/** * Handle posting of the form for the password reminder confirmation. * * @param int $id * @param string $code * @return \Illuminate\Http\RedirectResponse */ public function processReset($id, $code) { $rules = ['password' => 'required|confirmed']; $validator = Validator::make(Input::get(), $rules); if ($validator->fails()) { return Redirect::back()->withInput()->withErrors($validator); } if (!($user = Sentinel::findById($id))) { return Redirect::back()->withInput()->withErrors('The user no longer exists.'); } try { if (!Reminder::complete($user, $code, Input::get('password'))) { return Redirect::route('user.login')->withErrors('Invalid or expired reset code.'); } return Redirect::route('user.login')->withSuccess('Password was successfully resetted.'); } catch (NotUniquePasswordException $e) { return Redirect::back()->withErrors($e->getMessage()); } }
/** * @param $id * @param $code * @return mixed */ public function postResetPasswordCode($id, $code) { $rules = ['password' => 'required|confirmed']; $validator = Validator::make(Input::get($id), $rules); if ($validator->fails()) { return Redirect::back()->withInput()->withErrors($validator); } $user = Sentinel::findById($id); if (!$user) { return Redirect::back()->withInput()->withErrors($validator); } if (!Reminder::complete($user, $code, Input::get('password'))) { return Redirect::to('login')->withErrors($validator); } return Redirect::once('login')->withSuccess("Password Reset."); }
/** * Set the new password * @return $this */ public function SetForgotPassword() { try { $user = \Sentinel::getUserRepository()->findById(\Input::get('UserId')); if (\Reminder::complete($user, \Input::get('ResetCode'), \Input::get('password'))) { return redirect('auth/login')->withErrors(array('login' => 'Password reset successful. Please Login')); } else { return redirect('auth/forgotpassword')->withErrors(array('forgot_password' => 'Password reset failed')); } } catch (\Exception $e) { return redirect('auth/forgotpassword')->withErrors(array('forgot_password' => 'User not found in our database.')); } }
public function postReset(Request $request) { $input = $request->all(); $credentials = ['email' => $request->email]; $rules = ['email' => 'required|email|exists:users,email', 'password' => 'required|alpha_num|min:6|max:20', 'password_confirm' => 'required|same:password', 'code' => 'required']; $messsages = ['code.required' => 'خطای امنیتی. لطفا عملیات تغییر رمز عبور را مجددا انجام دهید.']; $validator = Validator::make($input, $rules, $messsages); if ($validator->fails()) { return back()->withInput()->withErrors($validator); } if ($user = Sentinel::findByCredentials($credentials)) { if (!Reminder::complete($user, $request->code, $request->password)) { return redirect()->route('login')->with('fail', 'Invalid or expired reset code.'); } return redirect()->route('login')->with('success', 'Password Reset.'); } else { return back()->withInput()->with('fail', 'The user no longer exists.'); } }
}); Route::get('reset/{id}/{code}', function ($id, $code) { $user = Sentinel::findById($id); return View::make('sentinel.reset.complete'); })->where('id', '\\d+'); Route::post('reset/{id}/{code}', function ($id, $code) { $rules = ['password' => 'required|confirmed']; $validator = Validator::make(Input::get(), $rules); if ($validator->fails()) { return Redirect::back()->withInput()->withErrors($validator); } $user = Sentinel::findById($id); if (!$user) { return Redirect::back()->withInput()->withErrors('The user no longer exists.'); } if (!Reminder::complete($user, $code, Input::get('password'))) { return Redirect::to('login')->withErrors('Invalid or expired reset code.'); } return Redirect::to('login')->withSuccess("Password Reset."); })->where('id', '\\d+'); Route::group(['prefix' => 'account', 'before' => 'auth'], function () { Route::get('/', function () { $user = Sentinel::getUser(); $persistence = Sentinel::getPersistenceRepository(); return View::make('sentinel.account.home', compact('user', 'persistence')); }); Route::get('kill', function () { $user = Sentinel::getUser(); Sentinel::getPersistenceRepository()->flush($user); return Redirect::back(); });