Exemple #1
0
 public static function reset()
 {
     if (Request::input('rs_type') == "change") {
         $validate = validateuser::validatechangepass(Request::all());
         if ($validate->passes()) {
             $user = Member::where("id", "=", Request::input('id'))->first();
             $dbpass = $user->password;
             $passcheck = \Hash::check(Request::input('old_password'), $dbpass);
             if ($passcheck == TRUE) {
                 $user->password = \Hash::make(Request::input('password'));
                 if ($user->save()) {
                     return Redirect::to('user_profile')->with('status', 'Change password has been completed');
                 }
             } else {
                 return redirect()->back()->withErrors('Old Password is Wrong!');
             }
         } else {
             return redirect()->back()->withErrors($validate->messages());
         }
     } else {
         if (Request::input('rs_type') == "forgot") {
             $validate = validateuser::validateforgotpass(Request::all());
             if ($validate->passes()) {
                 //get email from server
                 $user = Member::where("id", "=", Request::input('id'))->first();
                 $email = $user->email;
                 //get key from server
                 $reset = Reset::where("email", "=", $email)->first();
                 $key = $reset->token;
                 //Check email match
                 if ($email == Request::input('email')) {
                     //Check key match
                     if ($key == Request::input('key')) {
                         $user->password = \Hash::make(Request::input('password'));
                         //Change completed
                         if ($user->save()) {
                             return Redirect::to('login')->with('status', 'Change password has been completed');
                         }
                     } else {
                         return redirect()->back()->withErrors('key is Wrong! Please resend forgot password.');
                     }
                 } else {
                     return redirect()->back()->withErrors('email is Wrong!');
                 }
             } else {
                 return redirect()->back()->withInput(Request::except('password'))->withErrors($validate->messages());
             }
         } else {
             //Not match all
         }
     }
 }
Exemple #2
0
 public function sendEmailForgot()
 {
     $validate = validateuser::validateforgot(Request::all());
     if ($validate->passes()) {
         $count = Member::where('email', '=', Request::input('email'))->count();
         if ($count == 1) {
             $forgot_code = sendmail::generateRandomString();
             $sforgot_code = MD5($forgot_code);
             $countforgot = Reset::where('email', '=', Request::input('email'))->count();
             if ($countforgot == 1) {
                 $reset = Reset::where("email", "=", Request::input('email'))->first();
                 $reset->token = $sforgot_code;
                 $reset->save();
             } else {
                 $reset = new Reset();
                 $reset->email = Request::input('email');
                 $reset->token = $sforgot_code;
                 $reset->save();
             }
             $profiles = Member::where('email', '=', Request::input('email'))->get();
             foreach ($profiles as $record) {
                 $name = $record->name;
                 $id = $record->id;
             }
             $email = Request::input('email');
             $link = 'http://www.ojconsultinggroup.com/4oj/reset/' . $id . '/token/' . $sforgot_code;
             $data = array('code' => $sforgot_code, 'name' => $name, 'link' => $link);
             Mail::queue('Member.mailforgot', $data, function ($message) use($email, $data) {
                 $message->to($email)->subject('Your Password Reset Link!');
             });
             return Redirect::to('forgot')->with('status', 'อีเมลสำหรับตั้งรหัสผ่านใหม่ได้ถูกส่งไปแล้ว');
         } else {
             $msg = "เกิดข้อผิดพลาด! ไม่พบชื่ออีเมลนี้ในระบบ";
             return Redirect::to('forgot')->withInput(Request::except('password'))->withErrors($msg);
         }
     } else {
         return Redirect::to('forgot')->withInput(Request::except('password'))->withErrors($validate->messages());
     }
 }