/** * @param Request $request * @return \Illuminate\Contracts\View\View * @throws InvalidConfirmationTokenException */ public function render(Request $request) { $token = array_get($request->getQueryParams(), 'token'); $token = PasswordToken::findOrFail($token); if ($token->created_at < new DateTime('-1 day')) { throw new InvalidConfirmationTokenException(); } return $this->view->make('flarum::reset')->with('translator', $this->translator)->with('passwordToken', $token->id)->with('csrfToken', $request->getAttribute('session')->get('csrf_token')); }
private function collectGarbage() { if ($this->hitsLottery()) { AccessToken::whereRaw('last_activity <= ? - lifetime', [time()])->delete(); $earliestToKeep = date('Y-m-d H:i:s', time() - 24 * 60 * 60); EmailToken::where('created_at', '<=', $earliestToKeep)->delete(); PasswordToken::where('created_at', '<=', $earliestToKeep)->delete(); AuthToken::where('created_at', '<=', $earliestToKeep)->delete(); } }
/** * @param Request $request * @return RedirectResponse */ public function handle(Request $request) { $input = $request->getParsedBody(); $token = PasswordToken::findOrFail(array_get($input, 'token')); $password = array_get($input, 'password'); $confirmation = array_get($input, 'password_confirmation'); if (!$password || $password !== $confirmation) { return new RedirectResponse($this->url->toRoute('resetPassword', ['token' => $token->id])); } $token->user->changePassword($password); $token->user->save(); $token->delete(); return new RedirectResponse($this->url->toBase()); }
/** * @param RequestPasswordReset $command * @return \Flarum\Core\User * @throws ModelNotFoundException */ public function handle(RequestPasswordReset $command) { $user = $this->users->findByEmail($command->email); if (!$user) { throw new ModelNotFoundException(); } $token = PasswordToken::generate($user->id); $token->save(); $data = ['username' => $user->username, 'url' => $this->url->toRoute('resetPassword', ['token' => $token->id]), 'forumTitle' => $this->settings->get('forum_title')]; $this->mailer->send(['text' => 'flarum::emails.resetPassword'], $data, function (Message $message) use($user) { $message->to($user->email); $message->subject('Reset Your Password'); }); return $user; }
/** * @param RequestPasswordReset $command * @return \Flarum\Core\User * @throws ModelNotFoundException */ public function handle(RequestPasswordReset $command) { $user = $this->users->findByEmail($command->email); if (!$user) { throw new ModelNotFoundException(); } $token = PasswordToken::generate($user->id); $token->save(); $data = ['{username}' => $user->username, '{url}' => $this->url->toRoute('resetPassword', ['token' => $token->id]), '{forum}' => $this->settings->get('forum_title')]; $body = $this->translator->trans('core.email.reset_password.body', $data); $this->mailer->raw($body, function (Message $message) use($user, $data) { $message->to($user->email); $message->subject('[' . $data['{forum}'] . '] ' . $this->translator->trans('core.email.reset_password.subject')); }); return $user; }
/** * @param Request $request * @return RedirectResponse */ public function handle(Request $request) { $input = $request->getParsedBody(); $token = PasswordToken::findOrFail(array_get($input, 'passwordToken')); $password = array_get($input, 'password'); $confirmation = array_get($input, 'password_confirmation'); $this->validator->assertValid(compact('password')); if (!$password || $password !== $confirmation) { return new RedirectResponse($this->url->toRoute('resetPassword', ['token' => $token->id])); } $token->user->changePassword($password); $token->user->save(); $token->delete(); $session = $request->getAttribute('session'); $this->authenticator->logIn($session, $token->user->id); return new RedirectResponse($this->url->toBase()); }
/** * @param Request $request * @return RedirectResponse */ public function handle(Request $request) { $input = $request->getParsedBody(); $token = PasswordToken::findOrFail(array_get($input, 'passwordToken')); $password = array_get($input, 'password'); try { // todo: probably shouldn't use the user validator for this, // passwords should be validated separately $this->validator->assertValid(compact('password')); $validator = $this->validatorFactory->make($input, ['password' => 'required|confirmed']); if ($validator->fails()) { throw new ValidationException($validator); } } catch (ValidationException $e) { $request->getAttribute('session')->set('error', $e->errors()->first()); return new RedirectResponse($this->url->toRoute('resetPassword', ['token' => $token->id])); } $token->user->changePassword($password); $token->user->save(); $token->delete(); $session = $request->getAttribute('session'); $this->authenticator->logIn($session, $token->user->id); return new RedirectResponse($this->url->toBase()); }