/** * Send a password reset link to a user. * * @param array $credentials * @param \Closure|null $callback * @return string */ public function sendResetLink(array $credentials, Closure $callback = null) { // First we will check to see if we found a user at the given credentials and // if we did not we will redirect back to this current URI with a piece of // "flash" data in the session to indicate to the developers the errors. $user = $this->getUser($credentials); if (is_null($user)) { return PasswordBrokerContract::INVALID_USER; } // Once we have the reset token, we are ready to send the message out to this // user with a link to reset their password. We will then redirect back to // the current URI having nothing set in the session to indicate errors. $token = $this->tokens->create($user); $this->emailResetLink($user, $token, $callback); return PasswordBrokerContract::RESET_LINK_SENT; }
public function getToken(array $credentials) { $user = $this->getUser($credentials); if (is_null($user)) { return; } return $this->tokens->create($user); }
/** * Request for password change * * @param Request $request * @param TokenRepositoryInterface $tokenRepository * @return Response */ public function store(Request $request, UserRepositoryInterface $userRepository, TokenRepositoryInterface $tokenRepository) { $input = $request->all(); $user = $userRepository->findByEmail($input['email']); if ($user == null || $input['email'] == '') { return $this->sendUnprocessableEntity('User not found.'); } $token = $tokenRepository->create($user); Event::fire(new UserForgotPassword($user, $token)); return $this->sendSuccess([], 'You will receive an email on how to reset your password.'); }
public function postEmail(Request $request, TokenRepositoryInterface $token) { $department = $this->getDepartment(); $this->validate($request, ['email' => 'required|email|exists:users,email,department_id,' . $department->id]); $template = new Template(); $user = User::where('email', $request->get('email'))->where('department_id', $department->id)->first(); if (!$user) { return redirect()->back()->with('error', 'error'); } $settings = $user->department->settings()->key('email_password_reset'); if (!isset($settings->value) || !$settings->value) { return redirect()->back()->with('error', 'no-template'); } $emailTemplate = EmailTemplate::findOrFail($settings->value); $emailTemplate->body = $template->parser($emailTemplate->body, ['name' => $user->name, 'expire' => Carbon::now()->addMinutes(config('auth.password.expire'))->format('d.m.Y H:i'), 'link' => route('department::auth::reset_token', $user->department->keyword) . '/' . $token->create($user)]); Mail::send('layouts.partials.email', ['body' => $emailTemplate->body], function ($message) use($emailTemplate, $user) { $message->subject($emailTemplate->subject); $message->to($user->email); }); return redirect()->back()->with('success', 'email-send'); }
/** * Attempt to confirm account with code * * @param string $code */ public function confirm($code, TokenRepositoryInterface $tokenRepo) { $user = User::where('confirmation_code', '=', $code)->get()->first(); if ($user) { $notice_msg = trans('texts.security.confirmation'); $user->confirmed = true; $user->confirmation_code = ''; $user->save(); if ($user->public_id) { //Auth::login($user); $token = $tokenRepo->create($user); return Redirect::to("/password/reset/{$token}"); } else { if (Session::has(REQUESTED_PRO_PLAN)) { Session::forget(REQUESTED_PRO_PLAN); $invitation = $this->accountRepo->enableProPlan(); return Redirect::to($invitation->getLink()); } else { return Redirect::to(Auth::check() ? '/dashboard' : '/login')->with('message', $notice_msg); } } } else { $error_msg = trans('texts.security.wrong_confirmation'); return Redirect::to('/login')->with('error', $error_msg); } }
/** * Create a new password reset token for the given user. * * @param CanResetPasswordContract $user * @return string */ public function createToken(CanResetPasswordContract $user) { return $this->tokens->create($user); }