@Template("@CleverAgeEAVManagerUser/Security/resetPassword.html.twig")

@Route("/login/reset-password", name="reset_password")

@param Request $request

@throws \Exception

@return Response|array
557522
public function resetPasswordAction(Request $request)
    {
        if ($this->getUser()) {
            return $this->redirectToRoute($this->get(Configuration::class)->getHomeRoute());
        }
        $token = $request->query->get('token');
        if (!$token) {
            return $this->redirectToRoute('lost_password');
        }

        $userManager = $this->get(UserManagerInterface::class);
        $user = $userManager->loadUserByToken($token);
        if (!$user) {
            $this->addFlash(
                'error',
                $this->get('translator')->trans('reset_password.token_not_found', [], 'security')
            );

            return $this->redirectToRoute('lost_password');
        }

        $form = $this->createForm(ResetUserPasswordType::class);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $password = $form->get('password')->getData();
            $userManager->setPlainTextPassword($user, $password);
            $userManager->save($user);

            $authenticationManager = $this->get('security.authentication.manager');
            $token = $authenticationManager->authenticate(
                new UsernamePasswordToken($user, $password, 'main', $user->getRoles())
            );
            $tokenStorage = $this->get('security.token_storage');
            $tokenStorage->setToken($token);

            return $this->redirectToRoute($this->get(Configuration::class)->getHomeRoute());
        }

        return [
            'user' => $user,
            'form' => $form->createView(),
        ];
    }
1098013
public function postLogin(Request $request)
    {

        $this->validate($request, ['username' => 'required|min:3|max:255', 'password' => 'required',]);

        $credentials = $request->only('username', 'password');
        $credentials[ 'enabled' ] = 1;

        if (Auth::attempt($credentials, $request->has('remember'))) {
            return redirect()->intended($this->getRedirectUrl());
        } else {
            return redirect(route('login'))->withInput($request->except(['password']))
                                           ->withErrors([$this->getFailedLoginMessage()]);
        }

    }
1208042
public function resetAction(Request $request)
	{
		// TODO: Add validation class to have ability check like " if (empty($validation['errors'])){} "
		if (!$request->request->has('user_id')) {
			throw new CmsException(null, 'User id is not set');
		}

		$userId = $request->request->get('user_id');

		$user = $this->container->getDoctrine()->getRepository('CmsAuthentication:User')->findOneById($userId);

		if (empty($user)) {
			throw new CmsException(null, 'Can\'t find user with such id');
		}

		$password = substr(md5(rand() . time()), 0, 8);

		$user->setPassword($this->encodePassword($user, $password));
		$this->container->getDoctrine()->getManager()->flush();

		$message = \Swift_Message::newInstance(
			'SiteSupra password reset',
			sprintf('Hi %s, your new password is: %s', $user->getLogin(), $password)
		);

		$message->setTo($user->getEmail());
		$message->setFrom($this->container->getParameter('framework.swiftmailer.default_from'));

		$this->container->getMailer()->send($message);

//		$this->checkActionPermission($user->getGroup(), Group::PERMISSION_MODIFY_USER_NAME);

		return new SupraJsonResponse(null);
	}
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)]);
        }
    }
319731
private function handlePostReset(Request $request, FormInterface $form)
    {
        $event = new AccessControlEvent($request);
        $username = $form->get('username')->getData();

        // Send a password request mail, if username exists.
        if ($username === null || $username === '') {
            $this->flashes()->error(Trans::__('general.phrase.please-provide-username'));
        } else {
            $this->password()->resetPasswordRequest($username, $request->getClientIp(), $event);
            $response = $this->redirectToRoute('login');
            $response->setVary('Cookies', false)->setMaxAge(0)->setPrivate();

            return $response;
        }

        return null;
    }
1156183
protected function sendFailedLoginResponse(Request $request)
    {
        return redirect()->back()
            ->withInput($request->only($this->username(), 'remember'))
            ->withErrors([
                $this->username() => Lang::get('auth.failed'),
            ]);
    }
440748
public function forgotPassword(Request $request): Response
    {
        $form = $this->createForgotPasswordForm();
        $form->handleRequest($request);

        if (!$form->isValid()) {
            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.forgot_password', 'ngsite'),
                [
                    'form' => $form->createView(),
                ]
            );
        }

        $users = $this->userService->loadUsersByEmail($form->get('email')->getData());

        $passwordResetRequestEvent = new UserEvents\PasswordResetRequestEvent(
            $form->get('email')->getData(),
            $users[0] ?? null
        );

        $this->eventDispatcher->dispatch(SiteEvents::USER_PASSWORD_RESET_REQUEST, $passwordResetRequestEvent);

        return $this->render(
            $this->getConfigResolver()->getParameter('template.user.forgot_password_sent', 'ngsite')
        );
    }
1130206
public function login(Request $request)
    {
        $this->validate($request, [
            'email'    => 'required',
            'password' => 'required',
        ]);

        if (
            $this->core->auth()
                ->login($request->input('email'), $request->input('password'), $request->has('remember'))
        ) {
            return redirect()->intended(
                $this->core->route(NamedRoute::HOME)
            );
        }

        return redirect()->back()
            ->withInput($request->only('email', 'remember'))
            ->withErrors([
                'email' => Lang::has('cms::auth.failed')
                    ?   Lang::get('cms::auth.failed')
                    :   'These credentials do not match our records.',
            ]);
    }
350853
public function checkEmailAction(Request $request)
    {
        $username = $request->query->get('username');

        if (empty($username)) {
            // the user does not come from the sendEmail action
            return new RedirectResponse($this->generateUrl('networking_init_cms_admin_resetting_request'));
        }

        return $this->render('NetworkingInitCmsBundle:Admin:Security/Resetting/checkEmail.html.twig', [
            'base_template' => $this->get('sonata.admin.pool')->getTemplate('layout'),
            'admin_pool' => $this->get('sonata.admin.pool'),
            'tokenLifetime' => ceil($this->container->getParameter('fos_user.resetting.retry_ttl') / 3600),
        ]);
    }
1297688
public function resetPassword(Request $request)
    {
        $this->validate($request, [
            'password' => 'required|confirmed',
            'token'    => 'required'
       ]);

        $record= $this->resetPasswordRepo->where('token', $request['token']);
        $email = $record->first()->email;
        $record->delete();

        $user = $this->userRepo->where('email', $email)->update(['password' => $request['password']]);
        return redirect()->route('core::home');
    }
442806
public function handleReset(string $reset_code = null, array $request = [])
    {
        if ($reset_code === null) {
            if (isset($_GET['template']) === false) {
                return redirect($this->router->generate('login-page') . "?m=3");
            } else {
                return 'Redirect: ' . $this->router->generate('login-page') . "?m=3";
            }
        }
        $user = Model\User::where("reset_code", $reset_code)->first();
        if ($user === null) {
            if (isset($_GET['template']) === false) {
                return redirect($this->router->generate('login-page') . "?m=3");
            } else {
                return 'Redirect: ' . $this->router->generate('login-page') . "?m=3";
            }
        }

        $validator = new \Valitron\Validator($request);
        $validator->rule('required', ['password', 'confirm_password']);
        $validator->rule(function ($field, $value, array $params, array $fields) {
            return is_string($value);
        }, ['password', 'confirm_password'])->message("{field} must be a string");
        $validator->rule('equals', 'confirm_password', 'password');
        $validator->rule('lengthBetween', 'password', 8, 80);
        if ($validator->validate() === false) {
            if (headers_sent() === false) {
                header('X-PHP-Response-Code: 422', true, 422);
            }
            return $this->templates->render("Auth::Reset", [
                "messages" => [
                    'error' => $validator->errors(),
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ]
            ]);
        }

        $response = $this->core->api('User/reset/' . $request['reset_code'], 'POST')->run($request);
        if (headers_sent() === false) {
            foreach ($response["headers"] as $header) {
                header($header[0], $header[1], $header[2]);
            }
        }
        if ($response["headers"][0][2] === 422) {
            return $this->templates->render("Auth::Reset", [
                "messages" => [
                    'error' => $response['response'],
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "reset_code" => $request['reset_code']
            ]);
        } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
            if (isset($_GET['template']) === false) {
                return redirect($this->router->generate('login-page') . "?m=4");
            } else {
                return 'Redirect: ' . $this->router->generate('login-page') . "?m=4";
            }
        } else {
            return $this->templates->render("500", [
                "error" => $response['response'],
                "result" => ''
            ]);
        }
    }
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']);
    }
509939
public function resettingPassword(Request $request, UserPasswordEncoderInterface $encoder, EventDispatcherInterface $dispatcher, \Swift_Mailer $mailer, TranslatorInterface $translator, $token)
    {
        // Get Doctrine
        $em = $this->getDoctrine()->getManager();

        // Find User
        $user = $em->getRepository($this->getParameter('pd_user.user_class'))->findOneBy(['confirmationToken' => $token]);
        if (null === $user) {
            throw $this->createNotFoundException(sprintf($translator->trans('security.token_notfound'), $token));
        }

        // Build Form
        $form = $this->createForm(ResettingPasswordType::class, $user);

        // Handle Form Submit
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            // Encode Password & Set Token
            $password = $encoder->encodePassword($user, $form->get('plainPassword')->getData());
            $user->setPassword($password)
                ->setConfirmationToken(null)
                ->setPasswordRequestedAt(null);

            // Save User
            $em->persist($user);
            $em->flush();

            // Dispatch Register Event
            if ($response = $dispatcher->dispatch(UserEvent::RESETTING_COMPLETE, new UserEvent($user))->getResponse()) {
                return $response;
            }

            // Send Resetting Complete
            $this->sendEmail($user, $mailer, 'Account Password Resetting', 'Password resetting completed.', 'Resetting_Completed');

            // Render Success
            return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resettingSuccess.html.twig', [
                'sendEmail' => false,
            ]);
        }

        // Render
        return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resettingPassword.html.twig', [
            'token' => $token,
            'form' => $form->createView(),
        ]);
    }
628289
public function postLogin(Request $request)
    {
        $credentials = $request->only(['mobile', 'password']);

        $validator = Validator::make($credentials, [
            'mobile' => 'required', 'password' => 'required',
        ]);

        if ($validator->fails()) {
            return Redirect::back()->withInput()->withErrors($validator);
        }

        if (Auth::guard('merchant')->attempt($credentials)) {
            merchant_toastr(trans('merchant.login_successful'));

            return redirect()->intended(config('merchant.route.prefix'));
        }

        return Redirect::back()->withInput()->withErrors(['mobile' => $this->getFailedLoginMessage()]);
    }
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');
    }
961813
public function postReset(Request $request, $code)
    {
        // Validate the form data
        $result = $this->validate($request, [
            'password' => 'required|confirmed|min:6',
        ]);

        // Attempt the password reset
        $result = $this->authManager->resetPassword($code, $request->get('password'));

        if ($result->isFailure()) {
            return $result->dispatch();
        }

        // Return the appropriate response
        return $result->dispatch(route('auth.login.form'));
    }
1170499
public function update(ResetPasswordRequest $request)
    {
        try {
            $this->dispatch(new ResetPassword($request->get('token'), $request->get('email'), $request->get('password')));

            return redirect()->route('authentication::session.create')->withErrors([
                'authentication::password-reset.updated' => trans('authentication::password-reset.updated'),
            ]);
        } catch (TokenIsExpired $e) {
            return redirect()->route('authentication::password-reset.create')->withErrors([
                'authentication::password-reset.expired' => trans('authentication::password-reset.expired'),
            ]);
        }
    }