Send reset password email

@param  Request $request
@return array
979264
public function post(Request $request)
    {
        // Validate user
        $email = Arr::get($this->getContentAsArray($request), 'email');
        $user  = $this->userService->findByEmail($email);

        if (! $user) {
            return $this->createNotFoundResponse();
        }

        // If a token exists that won't expire in the next 5 minutes, send it
        $token = $this->userService->findTokenBy([
            'user_id'       => $user->getId(),
            'token_type_id' => TokenEntity::TYPE_RESET_PASSWORD,
            ['expires', '>', time() + 5*60],
        ]);

        // Otherwise create a new token
        if (! $token) {
            $token = $this->userService->createUserToken([
                'user_id'       => $user->getId(),
                'token_type_id' => TokenEntity::TYPE_RESET_PASSWORD,
                'expires'       => strtotime('+1 day', time()),
            ]);
        }

        $this->resetPasswordView->setUserToken($token);

        $email = $this->emailService->createFromArray([
            'recipient_email' => $user->getEmail(),
            'subject'         => 'Reset Your Password',
            'message'         => (string) $this->resetPasswordView,
        ]);

        $this->emailService->enqueueSendEmailJob($email);

        return $this->create204Response(204, '');
    }
440434
public function loginWithEmail(Request $request)
  {
    $request->rules = [
      'email' => 'required'
    ];

    $request->validate();

    $provider = $this->provider;

    $info = MagicLink::notify($request, $provider, $this->musk());

    $this->sendMagicLinkNotification($info['email'], $info['token']);
    $this->redirectUser($request->input('email'));
  }
1346915
public function send(PasswordResetSendRequest $request)
    {
        $result = app('auth.password')
            ->broker($this->getPasswordResetBroker())
            ->sendResetLink($request->only(['email']));

        switch ($result) {
            case PasswordResetBrokerContract::RESET_LINK_SENT:
                return intend([
                    'url' => route('tenantarea.home'),
                    'with' => ['success' => trans($result)],
                ]);

            case PasswordResetBrokerContract::INVALID_USER:
            default:
                return intend([
                    'back' => true,
                    'withInput' => $request->only(['email']),
                    'withErrors' => ['email' => trans($result)],
                ]);
        }
    }
427215
public function resetPasswordAction(Request $request)
    {
        $groups = $this->decodeIdsString($request, Group::class);
        $this->om->startFlushSuite();
        $i = 0;

        foreach ($groups as $group) {
            foreach ($group->getUsers() as $user) {
                $this->container->get('claroline.manager.user_manager')->sendResetPassword($user);
                ++$i;

                if (0 === $i % 200) {
                    $this->om->forceFlush();
                }
            }
        }

        $this->om->endFlushSuite();

        return new JsonResponse();
    }
513618
private function validatePassword(Request $request)
    {
        $password = self::$validator->isString('password');

        $result = $password
            ->isRequired()
            ->isBetween(5, 72, true)
            ->isAlphanumeric()
            ->validate($request->password);

        $this->isValid = $this->isValid && $result;
        $this->errors  = array_merge($this->errors, $password->getErrors());
    }
652831
public function resetPassword(Request $request)
    {
        $event = new AccessControlEvent($request);
        $this->password()->resetPasswordConfirm($request->get('token'), $request->getClientIp(), $event);

        return $this->redirectToRoute('login', ['action' => 'login']);
    }
84726
public function resetPassword(Request $request): Response
    {
        $this->denyAccessUnlessLoggedIn();

        // @todo verify hash and if not valid show error page with message

        if ($request->isMethod(Request::METHOD_POST)) {
            // @todo: update password, login customer and redirect to account and show success message
            return $this->redirectToRoute('frontend.account.home.page', []);
        }

        return $this->renderStorefront('@Storefront/page/account/password-reset/password-reset.html.twig', ['page' => []]);
    }
439934
protected function sendRequest(Request $request): Response
    {
        // Set password authentication for request.
        if ($this->password !== null) {
            $request->authenticate($this->password);
        }

        $this->send((string) $request);
        $response = new Response($this->get());
        return $response;

    }
335648
public function postLogin(Request $request)
    {
        $this->loginValidator($request->all())->validate();

        $credentials = $request->only([$this->username(), 'password']);
        $remember = $request->get('remember', false);

        if ($this->guard()->attempt($credentials, $remember)) {
            return $this->sendLoginResponse($request);
        }

        return back()->withInput()->withErrors([
            $this->username() => $this->getFailedLoginMessage(),
        ]);
    }
31962
public function update(Request $request)
    {
        $this->validate($request, [
            'password' => 'required|confirmed|min:6',
        ]);

        $request->user()->update([
            'password' => bcrypt($request->password),
        ]);
    }
745349
public function postReset(Request $request) {

        $this->validate($request, [
            'token'    => 'required',
            'email'    => 'required|email',
            'password' => 'required|confirmed|min:6',
        ]);

        $credentials = $request->only(
            'email', 'password', 'password_confirmation', 'token'
        );

        $response = Password::reset($credentials, function ($user, $password) {
            $this->resetPassword($user, $password);
        });

        switch ($response)
        {
            case Password::PASSWORD_RESET:
                //return redirect($this->redirectPath())->with('status', trans($response));
                return view('usermanagement::frontend.'.$this->frontend_template_name.'.password.password_reset_confirmation', [
                    'title'     => 'Password Reset Confirmed',
                    'email'     => $request->input('email'),
                    'username'  => Auth::user()->name,
                ]);

            default:
                return redirect()->back()
                    ->withInput($request->only('email'))
                    ->withErrors(['email' => trans($response)]);
        }
    }
836223
public function sendResetPasswordNotification($token, $request)
    {
        $this->notify(new ResetPasswordNotification($token, $request->tenant, $request->site));
    }
332669
public function sendResetLinkEmail(Request $request)
    {
        $this->validate($request, ['email' => 'required|email']);

        $response = Password::broker()->sendResetLink(
            $request->only('email')
        );

        if (Password::RESET_LINK_SENT) {
            return new JsonResponse(['status' => trans($response) ], 200);
        }

        return new JsonResponse(['email' => trans($response) ], 422);

    }
1249041
public function sendReset(Request $request)
    {
        $user = User::where('email', '=', $request->email)->first();
        if($user !== null)
        {
            $existingReset = Password_reset::where('email', $request->email)->first();
            if($existingReset !== null)
            {

                $existingReset->created_at = Carbon::now()->toDateTimeString();
                $existingReset->save();

                \Mail::send(config('entrance.mail.password_reset'), ['reset' => $existingReset->token], function ($m) use ($user) {
                    $m->to($user->email, $user->name)->subject('Your Password Reset!');
                });

                $request->session()->flash('message', 'Er is een e-mail met een link verzonden.');
                return redirect()->route('reset.password');

            }
            else
            {
                $passwordReset = new Password_reset();
                $passwordReset->email = $request->email;
                $passwordReset->token = $request->_token;
                $passwordReset->created_at = Carbon::now()->toDateTimeString();
                $passwordReset->save();

                \Mail::send(config('entrance.mail.password_reset'), ['reset' => $request->_token], function ($m) use ($user) {
                    $m->to($user->email, $user->name)->subject('Your Password Reset!');
                });

                $request->session()->flash('message', 'Er is een e-mail met een link verzonden.');
                return redirect()->route('reset.password');
            }
        }
        else
        {

            $request->session()->flash('message', 'Er bestaat geen gebruiker met het ingevoerde e-mail adres.');
            return redirect()->route('reset.password');
        }
    }
787404
public function doReset(Request $request)
    {
        $existingReset = Password_reset::where('email', $request->email)
                                        ->where('token', $request->token)
                                        ->first();

        if ($existingReset !== null)
        {
            if ($request->password === $request->input('repeat-password'))
            {
                $user = User::where('email',$request->email)->first();
                $user->password = bcrypt($request->password);
                $user->save();

                $existingReset->delete();

                return redirect()->route('success');
            }
            else
            {
                $request->session()->flash('message', 'De ingevoerde wachtwoorden komen niet overeen.');
                return back()->withInput();
            }
        }
        else
        {
            $request->session()->flash('message', 'Het ingevoerde e-mail adres is onjuist.');
            return back()->withInput($request->except('email'));
        }
    }
464123
public function recoverAction($request)
    {
        $data = $request->get('data');
        $modelUser = new ModelUser;

        if ($this->isAuthenticated()) {
            $this->setMessage('error', 'Your are already authenticated.');
            return $this->redirect('/');
        }

        if (!filter_var($data['model']['email'], FILTER_VALIDATE_EMAIL)) {
            $this->setMessage('error', 'Thats is not an email');
            return $this->redirect('/user/recover');
        }

        if (!$modelUser->findByEmail($data['model']['email'])) {
            $this->setMessage('error', 'Your are not registered');
            return $this->redirect('/user/register');
        }

        //Send the email
        $password = $modelUser->regeneratePassword();
        $to = $modelUser->email;
        $subject = 'Password from Reader';
        $message = 'Your new password is ' . $password;
        $this->sendMail($to, $subject, $message);

        return $this->twig()->render('user\recoverAction.twig');
    }
255158
public function postReauthenticate(Request $request)
    {
        $this->validate($request, [
            'password' => 'required',
        ]);

        $reauth = new ReauthLimiter($request);

        if (!$reauth->attempt($request->password)) {
            return Redirect::back()
                ->withErrors([
                    'password' => $this->getFailedLoginMessage(),
                ]);
        }

        return Redirect::intended();
    }