Ejemplo n.º 1
0
 public function store(Requests\RegisterCheck $request)
 {
     $settings_value = Settings::all();
     if ($settings_value[0]->value > Carbon::now() && $settings_value[1]->value < Carbon::now()) {
         return view('errors.RegisterInValid');
     }
     $input = new RegisterUsers();
     $input->email = $request->get('email');
     $input->password = Hash::make($request->get('password'));
     $input->pid = $request->get('pid');
     $input->type = $request->get('type');
     $input->verify_code = $rand = substr(md5(sha1($request->get('email') . $request->get('password'))), 0, 6);
     $input->reg_verify = 0;
     $input->reg_time = Carbon::now();
     $input->save();
     $account_details = RegisterUsers::select('id')->where('email', $request->get('email'))->get();
     $input = new RegisterDetails();
     $input->account_id = $account_details[0]->id;
     // 'Cause the variable account_id is a array.
     $input->name = $request->get('name');
     $input->gender = $request->get('gender');
     $input->school = $request->get('school');
     $input->phone = $request->get('phone');
     $input->tc_class = $request->get('tc_class');
     $input->save();
     /* Send the SMS to Users */
     $date = date("YmdHis");
     $pwd_file = fopen(public_path('msg_tmp/') . $date . $rand . ".txt", "a");
     $content = "ccucc," . $request->get('phone') . ",夥伴您好:驗證碼:" . $rand . "請填入系統送出註冊並填報名資訊,始完成報名。驗證網站:https://goo.gl/kfvpCT,";
     $content = iconv('UTF-8', 'Big5', $content);
     fwrite($pwd_file, $content);
     fclose($pwd_file);
     $chk_file = fopen(public_path('msg_tmp/') . $date . $rand . ".chk", "a");
     fclose($chk_file);
     $conn_id = ftp_connect("210.71.253.195");
     $login_result = ftp_login($conn_id, "sms", "sms");
     if ($login_result) {
         ftp_put($conn_id, $date . $rand . ".txt", public_path('msg_tmp/') . $date . $rand . ".txt", FTP_ASCII);
         ftp_put($conn_id, $date . $rand . ".chk", public_path('msg_tmp/') . $date . $rand . ".chk", FTP_ASCII);
     }
     $email = $request->get('email');
     $name = $request->get('name');
     /* Send the Mail to Users */
     Mail::send('emails.welcome', ['code' => $rand], function ($message) use($email, $name) {
         $message->from('*****@*****.**', '105偏鄉教師寒假教學專業成長研習');
         $message->to($email, $name)->subject('【驗證通知信】105偏鄉教師寒假教學專業成長研習');
     });
     return redirect('verify');
 }