Sends password recovery email

@param  HTTPRequest   $request    HTTP request containing 'email' vars
@return array                        'email' => false if email fails (Member doesn't exist will not be reported)
514153
public function lostPassword(HTTPRequest $request)
    {
        $email = Convert::raw2sql($request->requestVar('email'));
        $member = DataObject::get_one(Member::class, "\"Email\" = '{$email}'");

        if ($member) {
            $token = $member->generateAutologinTokenAndStoreHash();

            $link = Security::lost_password_url();
            $lostPasswordHandler = new LostPasswordHandler($link);

            $lostPasswordHandler->sendEmail($member, $token);
        }

        return array('done' => true);
    }
40191
public function authenticate(HTTPRequest $request): HTTPRequest
    {
        $requestAdapter = new HttpRequestAdapter();
        $responseAdapter = new HttpResponseAdapter();

        // missing vars (cli)
        $this->addMissingServerVariables($requestAdapter);

        $server = $this->getServer();
        $psrRequest = $requestAdapter->toPsr7($request);
        $psrResponse = new Response();

        try {
            $psrRequest = $server->validateAuthenticatedRequest($psrRequest);
        } catch (OAuthServerException $exception) {
            // convert to authentication exception
            throw new AuthenticationException(
                $exception->getMessage(),
                $exception->getCode(),
                $responseAdapter->fromPsr7($exception->generateHttpResponse($psrResponse))
            );
        } catch (\Exception $exception) {
            // convert to authentication exception
            throw new AuthenticationException(
                $exception->getMessage(),
                $exception->getCode(),
                $responseAdapter->fromPsr7(
                    (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500))
                        ->generateHttpResponse($psrResponse)
                )
            );
        }
        // add the request attributes as custom auth headers
        foreach ($psrRequest->getAttributes() as $attribute => $value) {
            $request->addHeader($attribute, $value);
        }

        return $request;
    }
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');
    }
334858
public function sendverification(SS_HTTPRequest $request)
    {
        // If we don't allow verification emails, return an error
        if (!Users::config()->send_verification_email) {
            return $this->httpError(400);
        }

        $sent = false;

        if (Member::currentUserID()) {
            $member = Member::currentUser();
        } else {
            $member = Member::get()->byID($this->getRequest()->param("ID"));
        }

        if ($member && !$member->isVerified()) {
            $sent = $this->send_verification_email($member);
        }

        $this->customise(
            array(
            "Title" => _t('Users.AccountVerification', 'Account Verification'),
            "MetaTitle" => _t('Users.AccountVerification', 'Account Verification'),
            "Content" => $this->renderWith(
                "UsersSendVerificationContent",
                array("Sent" => $sent)
            ),
            "Sent" => $sent
            )
        );

        $this->extend("updateSendVerificationAction");

        return $this->renderWith(
            array(
            "Users_Register_sendverification",
            "Users",
            "Page"
            )
        );
    }
153165
public function reset(Request $request)
    {
        $this->validate($request, [
            'token' => 'required', 'email' => 'required|email',
            'password' => 'required|confirmed|min:6',
        ]);

        // Here we will attempt to reset the user's password. If it is successful we
        // will update the password on an actual user model and persist it to the
        // database. Otherwise we will parse the error and return the response.
        $response = $this->broker()->reset(
            $this->credentials($request), function ($user, $password) {
                $this->resetPassword($user, $password);
            }
        );

        // If the password was successfully reset, we will redirect the user back to
        // the application's home authenticated view. If there is an error we can
        // redirect them back to where they came from with their error message.
        return $response == Password::PASSWORD_RESET
                    ? $this->sendResetResponse($response)
                    : $this->sendResetFailedResponse($request, $response);
    }
707417
public function processPassword(Request $request)
    {
        $redirect_url = session('cortex.auth.reauthentication.intended');
        $session_name = session('cortex.auth.reauthentication.session_name');

        if (Hash::check($request->input('password'), request()->user($this->getGuard())->password)) {
            $this->setSession($session_name);

            return intend([
                'intended' => url($redirect_url),
            ]);
        }

        return intend([
            'intended' => url($redirect_url),
            'withErrors' => [
                'password' => trans('cortex/auth::messages.auth.failed'),
            ],
        ]);
    }
891211
public function resetPasswordAction(Request $request)
    {
        $widget = $request->isXmlHttpRequest();

        $passwordResetToken = $this->getPasswordResetToken($request->query->get('token'));

        $form = $this->getSecurityFormFactory()->createPasswordResetForm($passwordResetToken)->handleRequest($request);

        if (!$form->isSubmitted()) {
            return new Response($this->getSecurityFormRenderer()->renderPasswordResetForm($form, $widget));
        }

        $successMessage = 'security.action.reset_password.success';

        if (!$this->getSecurityFormHandler()->handlePasswordResetForm($form, !$widget, $successMessage)) {
            $html = $this->getSecurityFormRenderer()->renderPasswordResetForm($form, $widget);

            return $widget
                ? new AjaxResponse($html, false, FlashNotifierInterface::MESSAGE_FORM_ERROR)
                : new Response($html);
        }

        $url = $this->generateUrl($this->getParameter('darvin_user.already_logged_in_redirect_route'));

        return $widget
            ? new AjaxResponse('', true, $successMessage, [], $url)
            : $this->redirect($url);
    }
969023
public function toResponse($request)
    {
        if (!empty($this->resource)) {
            return $this->resource->response($request)->setStatusCode($this->status())->withHeaders($this->headers);
        }

        ///
        $data = [
            'status_code' => $this->getStatusCode(),
            'message' => $this->getContent(),
        ];

        if (!empty($this->meta)) {
            $data['meta'] = $this->meta;
        }

        if ($this->debug && !empty($this->debugData)) {
            $data['debug'] = $this->debugData;
        }

        return response()->json($data, $this->status())->withHeaders($this->headers);
    }
691228
public function update(PasswordUpdateRequest $request)
    {
        $password = $request->new_password;

        if (Hash::check($request->old_password, Auth::user()->password)) {
            $this->resetPassword(Auth::user(), $password);
            return redirect('user/settings')
                ->with('message', 'Password updated successfully');
        }

        return back()->withErrors(['Password could not be updated']);
    }
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);

    }
658998
public function postReset(Request $request)
    {
        $this->validate($request, [
            'token'         => 'required',
            'email'         => 'required|email',
            'password'      => 'required|confirmed|min:6',
        ]);

        // Here we will attempt to reset the user's password. If it is successful we
        // will update the password on an actual user model and persist it to the
        // database. Otherwise we will parse the error and return the response.
        $response = $this->broker()->reset(
            $this->credentials($request), function ($user, $password) {
                $this->resetPassword($user, $password);
            }
        );

        switch ($response) {
            case Password::PASSWORD_RESET:
                return $this->getResetSuccessResponse('pulsar::passwords.reset');

            default:
                return $this->getResetFailureResponse($request, $response);
        }
    }
907356
public function requestAction(Request $request)
    {
        $widget = $request->isXmlHttpRequest();

        $form = $this->getPasswordResetTokenFormFactory()->createRequestForm()->handleRequest($request);

        if (!$form->isSubmitted()) {
            return new Response($this->getPasswordResetTokenFormRenderer()->renderRequestForm($widget, $form));
        }

        $successMessage = 'password_reset_token.action.request.success';

        $passwordResetToken = $this->getPasswordResetTokenFormHandler()->handleRequestForm($form, !$widget, $successMessage);

        if (empty($passwordResetToken)) {
            $html = $this->getPasswordResetTokenFormRenderer()->renderRequestForm($widget, $form);

            return $widget
                ? new AjaxResponse($html, false, FlashNotifierInterface::MESSAGE_FORM_ERROR)
                : new Response($html);
        }
        if ($widget) {
            $webmailLink   = null;
            $webmailLinker = $this->getWebmailLinker();

            if (!empty($webmailLinker)) {
                $webmailLink = $webmailLinker->getProviderByEmailAddress($passwordResetToken->getUser()->getEmail());
            }

            return new AjaxResponse(
                $this->renderView('DarvinUserBundle:PasswordResetToken/widget/request:submitted.html.twig', [
                    'password_reset_token' => $passwordResetToken,
                    'webmail_link'         => $webmailLink,
                ]),
                true,
                $successMessage
            );
        }

        return $this->redirectToRoute('darvin_user_security_login');
    }
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']);
    }
1086742
public function login(Request $request)
    {
        $form = $this->form(new LoginForm());
        $form->handleRequest($request);

        if ($form->isValid()) {
            if ($this->attemptLogin($request, $form)) {
                return $this->sendLoginResponse($request);
            }
        }

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        $this->sendFailedLoginResponse($request);
    }
1341518
public function getResponse(HttpRequest $request)
    {
        $uri = $request->getUrl();

        $headers = $request->getHeaders();
        $flatHeaders = [];

        foreach ($headers as $key => $value) {
            $flatHeaders[] = $key . ": " . $value;
        }

        $flatHeaders[] = 'Connection: Keep-Alive';
        $flatHeaders[] = 'Expect:';
        $flatHeaders[] = 'Accept-Language: en-GB';
        $flatHeaders[] = 'Cache-Control: no-cache';
        $flatHeaders[] = 'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)';

        $curl = curl_init($uri);

        curl_setopt($curl, CURLOPT_HEADER, false);

        $payload = $request->getPayload();

        switch ($request->getMethod()) {
            case "head":
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "HEAD");
                break;
            case "delete":
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
                break;
            case "post":
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
                break;
            case "put":
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);

                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
                break;
        }

        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $flatHeaders);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($curl);

        $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        curl_close($curl);

        $httpResponse = new HttpResponse();
        $httpResponse->setResponseBody($response);
        $httpResponse->setResponseCode($responseCode);

        return $httpResponse;
    }
63939
@POST
  @Path("password/reset")
  @PermitAll
  public Response resetPassword(PasswordRequest request) {
    checkNotNull(request.getEmail());

    userService.resetPassword(request.getEmail());
    return Response.noContent().build();
  }
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();
    }