Password reset
@param string $id User ID
@param string $token Token
@return \Cake\Network\Response|null|void
@throws RecordNotFoundException
187816
public function passwordReset($id, $token)
    {
        $tokenExists = $this->Token->check($token, ['type' => 'password_forgot', 'user_id' => $id]);
        is_true_or_fail($tokenExists, __d('me_cms', 'Invalid token'), RecordNotFoundException::class);

        $user = $this->Users->findActiveById($id)->select(['id'])->firstOrFail();

        if ($this->request->is(['patch', 'post', 'put'])) {
            $user = $this->Users->patchEntity($user, $this->request->getData());

            if ($user->isDirty() && $this->Users->save($user)) {
                $this->Token->delete($token);
                $this->Flash->success(__d('me_cms', 'The password has been edited'));

                return $this->redirect(['_name' => 'login']);
            }

            $this->Flash->error(__d('me_cms', 'The password has not been edited'));
        }

        $this->set(compact('user'));
        $this->viewBuilder()->setLayout('login');
    }
891913
public function forgotStep2($token, array $password)
    {
        $ip = $this->request->ip();

        return $this->getPasswordReset()
                    ->step2($token, $password, $ip);
    }
851346
public function actionReset($id, $code) {
    if (!$this->module->enablePasswordRecovery) {
      throw new NotFoundHttpException();
    }

    /** @var Token $token */
    $token = Token::find()->where(['userId' => $id, 'code' => $code, 'type' => Token::TYPE_RECOVERY])->one();
    $event = $this->getResetPasswordEvent($token);

    $this->trigger(self::EVENT_BEFORE_TOKEN_VALIDATE, $event);

    if ($token === null || $token->isExpired || $token->user === null) {
      $this->trigger(self::EVENT_AFTER_TOKEN_VALIDATE, $event);
      Yii::$app->session->setFlash('danger', Yii::t('users', 'Recovery link is invalid or expired. Please try requesting a new one.'));
      return $this->render('/message', [
        'title' => Yii::t('users', 'Invalid or expired link'),
        'module' => $this->module,
      ]);
    }

    /** @var RecoveryForm $model */
    $model = Yii::createObject([
      'class' => RecoveryForm::className(),
      'scenario' => 'reset',
    ]);
    $event->setForm($model);

    $this->performAjaxValidation($model);
    $this->trigger(self::EVENT_BEFORE_RESET, $event);

    if ($model->load(Yii::$app->getRequest()->post()) && $model->resetPassword($token)) {
      $this->trigger(self::EVENT_AFTER_RESET, $event);
      return $this->render('/message', [
        'title' => Yii::t('users', 'Password has been changed'),
        'module' => $this->module,
      ]);
    }

    return $this->render('reset', [
      'model' => $model,
    ]);
  }
641447
public function sendPasswordResetNotification($token)
    {
        // Send SMS
        $url = url('password/reset', $token);
        $sms = "Reset password using this link: $url";
        $oxygen = new OxygenSms();
        $signup = Signup::where('user_id', $this->id )->first();
        $oxygen->send( $sms, $signup->mobile_number );

        $this->notify(new ResetPasswordNotification($token));
    }
1088768
public function resetAction(Request $request, PasswordResetToken $token): Response
    {
        $user = $this->userRepositoryCollection->findUserByToken($token);

        if ($user === null) {
            return new RedirectResponse(
                $this->router->generate('multi_user_login')
            );
        }

        $changePasswordTransferObject = ChangePasswordDataTransferObject::forUser($user);
        $form = $this->formFactory->create(ChangePasswordType::class, $changePasswordTransferObject);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $this->resetPasswordHandler->handle($form->getData());

            $this->flashBag->add(
                'success',
                $this->translator->trans(
                    'sumocoders.multiuserbundle.flash.password_reset_success'
                )
            );

            return new RedirectResponse(
                $this->router->generate('multi_user_login')
            );
        }

        return $this->templating->renderResponse(
            'SumoCodersFrameworkMultiUserBundle:PasswordReset:reset.html.twig',
            [
                'form' => $form->createView(),
            ]
        );
    }
1260202
public function resetAction(Request $request, $token)
    {
        /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
        $formFactory = $this->get('fos_user.resetting.form.factory');
        /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
        $userManager = $this->get('fos_user.user_manager');
        /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
        $dispatcher = $this->get('event_dispatcher');

        $user = $userManager->findUserByConfirmationToken($token);

        if (null === $user) {
            throw new NotFoundHttpException(sprintf('The user with "confirmation token" does not exist for value "%s"', $token));
        }

        $event = new GetResponseUserEvent($user, $request);
        $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_INITIALIZE, $event);

        if (null !== $event->getResponse()) {
            return $event->getResponse();
        }

        $form = $formFactory->createForm();
        $form->setData($user);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $event = new FormEvent($form, $request);
            $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_SUCCESS, $event);

            $userManager->updateUser($user);

            if (null === $response = $event->getResponse()) {
                $url = $this->generateUrl('fos_user_profile_show');
                $response = new RedirectResponse($url);
            }

            $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_COMPLETED, new FilterUserResponseEvent($user, $request, $response));

            return $response;
        }

        return $this->render('FOSUserBundle:Resetting:reset.html.twig', array(
            'token' => $token,
            'form' => $form->createView(),
        ));
    }
706262
public function getByApiToken(int $id, string $token) : ?Authenticatable
    {
        $model = $this->getModel();

        $user = $model->newQuery()
                      ->where($model->getAuthIdentifierName(), $id)
                      ->first();

        if ($user === null) {
            return null;
        }

        $apiToken = $user->getApiToken();

        return !empty($apiToken) && hash_equals($apiToken, $token) ? $user : null;
    }
69167
public function getByRememberToken(int $id, string $token) : ?Authenticatable
    {
        $model = $this->getModel();

        $user = $model->newQuery()
                      ->where($model->getAuthIdentifierName(), $id)
                      ->first();

        if ($user === null) {
            return null;
        }

        $rememberToken = $user->getRememberToken();

        return !empty($rememberToken) && hash_equals($rememberToken, $token) ? $user : null;
    }
266835
public function saveNewPassword(string $password, bool $reset_token = false): bool
    {
        $this->setPassword($password);
        if ($reset_token === true) {
            $this->removePasswordResetToken();
        }
        return $this->save();
    }
527953
public function edit($id) : Response
    {
        if ($user = $this->model->findFirst($this->userData->getId())) {
            $request = $this->request->getPut();

            if (empty($request)) {
                $request = $this->request->getJsonRawBody(true);
            }

            //clean pass
            if (array_key_exists('password', $request) && !empty($request['password'])) {
                $user->password = Users::passwordHash($request['password']);
                unset($request['password']);
            }

            //clean default company
            if (array_key_exists('default_company', $request)) {
                //@todo check if I belong to this company
                if ($company = Companies::findFirst($request['default_company'])) {
                    $user->default_company = $company->getId();
                    unset($request['default_company']);
                }
            }

            //update
            if ($user->update($request, $this->updateFields)) {
                $user->password = null;
                return $this->response($user);
            } else {
                //didnt work
                throw new Exception($user->getMessages()[0]);
            }
        } else {
            throw new Exception('Record not found');
        }
    }
1168591
public function reset($token=null, $data=null)
    {
        if ($this->options['shared']) {
            $data = static::formatData($data);
            $key2 = md5(serialize($data));
            
            static::getStorage()->remove($key2);
        }
        
        if ($token) {
            $key = trim($token);
            
            static::getStorage()->remove($key);
        }
    }
508516
public static function findByPasswordResetToken($token, $status = self::STATUS_ACTIVE)
    {
        if (!static::isPasswordResetTokenValid($token)) {
            return null;
        }
        if ($status == null) {
            return static::find()->where(['password_reset_token' => $token])->limit(1)->one();
        }
        return static::find()->where(['password_reset_token' => $token, 'status' => $status])->limit(1)->one();
    }
194792
public function revokeRefreshToken($tokenId)
    {
        $this->getEntityManager()->transactional(function(EntityManagerInterface $em) use ($tokenId) {
            $token = $this->find($tokenId);

            if ($token) {
                $em->remove($token);
            }
        });
    }
189158
public function tokenLoginAction($token)
    {
        $newSessionId = $this->loginTokenCache->get($token);
        $this->loginTokenCache->remove($token);

        if ($newSessionId === false) {
            $this->systemLogger->log(sprintf('Token-based login failed, non-existing or expired token %s', $token), LOG_WARNING);
            $this->redirect('index');
        }

        $this->systemLogger->log(sprintf('Token-based login succeeded, token %s', $token), LOG_DEBUG);

        $newSession = $this->sessionManager->getSession($newSessionId);
        if ($newSession->canBeResumed()) {
            $newSession->resume();
        }
        if ($newSession->isStarted()) {
            $newSession->putData('lastVisitedNode', null);
        } else {
            $this->systemLogger->log(sprintf('Failed resuming or starting session %s which was referred to in the login token %s.', $newSessionId, $token), LOG_ERR);
        }

        $this->replaceSessionCookie($newSessionId);
        $this->redirect('index', 'Backend\Backend');
    }
1154352
public function showResetForm(Request $request, $token = null)
    {
        $data = new PasswordResetData();
        $data->setToken($token);

        $form = $this->form(new PasswordResetForm($data));

        return view('auth.passwords.reset')->with([
            'form' => $form
        ]);
    }
723513
public boolean resetPassword(String password, String token) {
		UserRecoverRequest req = this.retrieveRecoverRequest(token);
		if (req == null)
			return false;
		User user = req.getUser();
		user.setPassword(CryptManager.passwordHash(password));
		this.dao.persist(user);
		req.setRecover(new Date());
		req.setRecoverIp(this.request.getRemoteAddr());
		req.setUsed(true);
		this.dao.persist(req);
		return true;
	}
799046
public function setTokenAttribute(Token $token)
    {
        $value = null;

        if (! $token->isValid()) {
            $value = $token->toJson();
        }

        $this->attributes['token'] = $value;
    }