Password reset step 4: Show password reset form

@Route("/user/reset")
@Method("GET")
@Template
764581
public function resetAction()
    {
        $token = $this->get('request_stack')->getCurrentRequest()->get('token');
        if (!$token) {
            return $this->render('FOMUserBundle:Login:error-notoken.html.twig');
        }

        $user = $this->getDoctrine()->getRepository("FOMUserBundle:User")->findOneByResetToken($token);
        if (!$user) {
            $mail = $this->container->getParameter('fom_user.mail_from_address');
            return $this->render('FOMUserBundle:Login:error-notoken.html.twig', array(
                'site_email' => $mail));
        }

        $max_token_age = $this->container->getParameter("fom_user.max_reset_time");
        if (!$this->checkTimeInterval($user->getResetTime(), $max_token_age)) {
            $form = $this->createForm('form');
            return $this->render('FOMUserBundle:Login:error-tokenexpired.html.twig', array(
                'user' => $user,
                'form' => $form->createView()
            ));
        }

        $form = $this->createForm(new UserResetPassType(), $user);
        return array(
            'user' => $user,
            'form' => $form->createView());
    }
873953
public function resetPassword()
    {
        $user = $this->_user;
        $user->new_password = $this->password;
        $user->removePasswordResetToken();

        return $user->save(false);
    }
828086
function (form) {
              var viewData = {
                form: form,
                organization: req.organization
              };

              if (form.data.password !== form.data.passwordAgain) {
                viewData.error = 'Passwords do not match.';
                return helpers.render(req, res, view, viewData);
              }

              result.password = form.data.password;

              return resetPasswordWithRecoveryToken(client, result, form.data.password, function (err) {
                if (err) {
                  logger.info('A user attempted to reset their password, but the password change itself failed.');
                  err = oktaErrorTransformer(err);
                  viewData.error = err.userMessage;
                  return helpers.render(req, res, view, viewData);
                }

                if (config.web.changePassword.autoLogin) {
                  var options = {
                    username: result.email,
                    password: result.password
                  };

                  if (req.organization) {
                    options.accountStore = req.organization.href;
                  }

                  return helpers.authenticate(options, req, res, function (err) {
                    if (err) {
                      viewData.error = err.userMessage;
                      return helpers.render(req, res, view, viewData);
                    }

                    res.redirect(config.web.login.nextUri);
                  });
                }

                res.redirect(config.web.changePassword.nextUri);
              });
            }
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');
    }
234600
protected function resetPasswordUser()
    {
        $result = $this->user_action->resetPassword($this->getSubmitted());
        $this->redirect($result['redirect'], $result['message'], $result['severity']);
    }
1010593
public function actionRequestPasswordReset()
    {
        $model = new PasswordResetRequest();
        if ($model->load(Yii::$app->getRequest()->post()) && $model->validate()) {
            if ($model->sendEmail()) {
                Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');

                return $this->goHome();
            } else {
                Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
            }
        }

        return $this->render('requestPasswordResetToken', [
                'model' => $model,
        ]);
    }
407085
function (form) {
            var data = {
              email: form.data.email
            };

            if (req.organization) {
              data.accountStore = {
                href: req.organization.href
              };
            }

            application.sendPasswordResetEmail(data, function (err) {
              if (err) {
                logger.info('A user tried to reset their password, but supplied an invalid email address: ' + form.data.email + '.');
              }

              res.redirect(config.web.forgotPassword.nextUri);
            });
          }
1321488
def request_password_reset(self, user_id):
		""""""
		content = self._fetch("/user/%s/password/request_reset" % (user_id), method="POST")
		return FastlyUser(self, content)
1061291
function resetPassword()
    {
        $infoMessage = null;
        $formErrors = null;

        $form = new FormResetPassword();
        if ($form->validate()) {
            $nonce = $form->getSubmitValue('form_nonce');
            if (Nonce::verifyNonce('Login.login', $nonce)) {
                $formErrors = $this->resetPasswordFirstStep($form);
                if (empty($formErrors)) {
                    $infoMessage = Piwik::translate('Login_ConfirmationLinkSent');
                }
            } else {
                $formErrors = array($this->getMessageExceptionNoAccess());
            }
        } else {
            // if invalid, display error
            $formData = $form->getFormData();
            $formErrors = $formData['errors'];
        }

        $view = new View('@Login/resetPassword');
        $view->infoMessage = $infoMessage;
        $view->formErrors = $formErrors;

        return $view->render();
    }
1095508
def send_reset_password_instructions(user):
    # type: (User) -> None
    
    token = generate_reset_password_token(user)
    url = url_for("login.reset_password", token=token)
    reset_link = request.url_root[:-1] + url

    subject = _("Password reset instruction for {site_name}").format(
        site_name=current_app.config.get("SITE_NAME")
    )
    mail_template = "password_reset_instructions"
    send_mail(subject, user.email, mail_template, user=user, reset_link=reset_link)
1150538
def reset_password(self, token=None, login_user=None):
        
        pwcol = self.options['password_column']
        if not token:
            if "token" in request.view_args:
                token = request.view_args["token"]
            elif "token" in request.values:
                token = request.values["token"]
            else:
                raise OptionMissingError(("Missing 'token' option or 'token' view arg "
                                          "or 'token' GET paramater in 'reset_password' action"))

        user = self.find_by_token(token, salt="password-reset", max_age=self.options["reset_password_ttl"])
        if user is None:
            if self.options["reset_password_error_message"]:
                flash(self.options["reset_password_error_message"], "error")
            current_context.exit(trigger_action_group="reset_password_failed")

        self.update_password_from_form(user)
        self.reset_password_signal.send(self, user=user)
        if (login_user is None and self.options["login_user_on_reset_password"]) or login_user:
            flask_login.login_user(user)
        return user
1194920
public function index()
    {
        $this->authorize(PasswordResetsPolicy::PERMISSION_LIST);

        $resets = PasswordReset::with(['user'])
            ->orderBy('created_at', 'desc')
            ->paginate($this->perPage);

        $this->setTitle($title = trans('auth::password-resets.titles.password-resets-list'));
        $this->addBreadcrumb($title);

        return $this->view('admin.password-resets.index', compact('resets'));
    }
393108
public function postReset()
    {
        $credentials = Input::only(
            'email', 'password', 'password_confirmation', 'token'
        );

        $response = Password::reset($credentials, function($user, $password)
        {
            $user->password = Hash::make($password);
            $user->save();
        });

        switch ($response)
        {
            case Password::INVALID_PASSWORD:
            case Password::INVALID_TOKEN:
            case Password::INVALID_USER:
                return Redirect::back()->with('error', 'Something was wrong with the input you provided.');

            case Password::PASSWORD_RESET:
                return Redirect::route('bumble.login');
        }
    }
899217
public function forgotPassword()
    {
        if ($this->request->getMethod() == 'POST') {
            $email = $this->getParam('email', null);
            $user = $this->userStore->getByEmail($email);

            if (empty($user)) {
                $this->view->error = Lang::get('reset_no_user_exists');
                return $this->view->render();
            }

            $key = md5(date('Y-m-d') . $user->getHash());
            $url = PHPCI_URL;

            $message = Lang::get('reset_email_body', $user->getName(), $url, $user->getId(), $key);

            $email = new Email();
            $email->setEmailTo($user->getEmail(), $user->getName());
            $email->setSubject(Lang::get('reset_email_title', $user->getName()));
            $email->setBody($message);
            $email->send();

            $this->view->emailed = true;
        }

        return $this->view->render();
    }
306568
def reset_password(token):
    """"""

    expired, invalid, user = reset_password_token_status(token)

    if not user or invalid:
        invalid = True
        do_flash(*get_message('INVALID_RESET_PASSWORD_TOKEN'))

    if expired:
        send_reset_password_instructions(user)
        do_flash(*get_message('PASSWORD_RESET_EXPIRED', email=user.email,
                              within=_security.reset_password_within))
    if invalid or expired:
        return redirect(url_for('forgot_password'))

    form = _security.reset_password_form()

    if form.validate_on_submit():
        after_this_request(_commit)
        update_password(user, form.password.data)
        do_flash(*get_message('PASSWORD_RESET'))
        return redirect(get_url(_security.post_reset_view) or
                        get_url(_security.login_url))

    return _security.render_template(
        config_value('RESET_PASSWORD_TEMPLATE'),
        reset_password_form=form,
        reset_password_token=token,
        **_ctx('reset_password')
    )
1077529
public function resetPasswordAction()
    {
        if($user = $this->identity()) {
            return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
        }
    
        $user = new User;
        $form = $this->getUserFormHelper()->createUserForm($user, 'ResetPassword');
        $message = null;
        if($this->getRequest()->isPost()) {
            $form->setValidationGroup('csrf', 'captcha');
            $form->setData($this->getRequest()->getPost());
            if($form->isValid()) {
                $data = $form->getData();
                $usernameOrEmail = $this->params()->fromPost('usernameOrEmail');
                $entityManager = $this->getEntityManager();
                $user = $entityManager->createQuery("SELECT u FROM CsnUser\Entity\User u WHERE u.email = '$usernameOrEmail' OR u.username = '$usernameOrEmail'")->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT);
                $user = $user[0];
    
                if(isset($user)) {
                    try {
                        $user->setRegistrationToken(md5(uniqid(mt_rand(), true)));
                        $fullLink = $this->getBaseUrl() . $this->url()->fromRoute('user-register', array( 'action' => 'confirm-email-change-password', 'id' => $user->getRegistrationToken()));
                        $this->sendEmail(
                                $user->getEmail(),
                                $this->getTranslatorHelper()->translate('Please, confirm your request to change password!'),
                                sprintf($this->getTranslatorHelper()->translate('Hi, %s. Please, follow this link %s to confirm your request to change password.'), $user->getUsername(), $fullLink)
                        );
                        $entityManager->persist($user);
                        $entityManager->flush();
    
                        $viewModel = new ViewModel(array(
                            'email' => $user->getEmail(),
                            'navMenu' => $this->getOptions()->getNavMenu()
                        ));
    
                        $viewModel->setTemplate('csn-user/registration/password-change-success');
                        return $viewModel;
                    } catch (\Exception $e) {
                        return $this->getServiceLocator()->get('csnuser_error_view')->createErrorView(
                                $this->getTranslatorHelper()->translate('Something went wrong when trying to send activation email! Please, try again later.'),
                                $e,
                                $this->getOptions()->getDisplayExceptions(),
                                $this->getOptions()->getNavMenu()
                        );
                    }
                } else {
                    $message = 'The username or email is not valid!';
                }
            }
        }
    
        return new ViewModel(array('form' => $form, 'navMenu' => $this->getOptions()->getNavMenu(), 'message' => $message));
    }
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)]);
        }
    }