public function renew($email, $token, ResetPasswordRequest $resetPasswordRequest, UserRepositoryInterface $userRepository, TokenRepositoryInterface $tokenRepository)
 {
     $input = $resetPasswordRequest->all();
     $user = $userRepository->findByEmail($email);
     if (!$user) {
         return $this->sendUnauthorized('Email not found.');
     }
     if (!$tokenRepository->exists($user, $token)) {
         return $this->sendUnauthorized('Invalid token.');
     }
     $user = $userRepository->changePassword($user, $input['password']);
     $tokenRepository->delete($token);
     return $this->sendSuccess([], 'Successfully reset your password. Now try logging in.');
 }
 public function getToken(array $credentials)
 {
     $user = $this->getUser($credentials);
     if (is_null($user)) {
         return;
     }
     return $this->tokens->create($user);
 }
Esempio n. 3
0
 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');
 }
Esempio n. 4
0
 /**
  * Validate a password reset for the given credentials.
  *
  * @param  array  $credentials
  * @return \Illuminate\Contracts\Auth\CanResetPassword
  */
 protected function validateReset(array $credentials)
 {
     if (is_null($user = $this->getUser($credentials))) {
         return PasswordBrokerContract::INVALID_USER;
     }
     if (!$this->validateNewPassword($credentials)) {
         return PasswordBrokerContract::INVALID_PASSWORD;
     }
     if (!$this->tokens->exists($user, $credentials['token'])) {
         return PasswordBrokerContract::INVALID_TOKEN;
     }
     return $user;
 }
 /**
  * Send a password reset link to a user.
  *
  * @param  array $credentials
  * @param  \Closure|null $callback
  *
  * @return string
  */
 public function sendResetEmail(array $credentials, \stdClass $viewData, 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->createEmailResetLink($user, $token, $viewData, $callback);
     return PasswordBrokerContract::RESET_LINK_SENT;
 }
Esempio n. 6
0
 /**
  * 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);
     }
 }
Esempio n. 7
0
 /**
  * Validate the given password reset token.
  *
  * @param  CanResetPasswordContract $user
  * @param  string $token
  * @return bool
  */
 public function tokenExists(CanResetPasswordContract $user, $token)
 {
     return $this->tokens->exists($user, $token);
 }