selfhosted/controllers/SiteController.php
/**
     * Requests password reset.
     * @return array|Response
     * @throws BadRequestHttpException
     */
Requests password reset.
@return array|Response
@throws BadRequestHttpException
Requests password reset . @return array|Response @throws BadRequestHttpException
public function actionRequestPasswordReset()
    {
        $model = new PasswordResetRequestForm();
        $cnt = Yii::$app->cache->get(Yii::$app->params['ResetPasswordCacheKey']);
        if (!$cnt) { $cnt = 1; } else { $cnt++; }
        Yii::$app->cache->set(Yii::$app->params['ResetPasswordCacheKey'], $cnt);
        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($model);
        }
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            if ($model->sendEmail()) {
                Yii::$app->session->setFlash('success', [
                    'message'   => Yii::t('forms/reset-password-form', 'Instructions_recovery_sent'),
                    'ttl'       => FLASH_MESSAGES_TTL,
                    'showClose' => true,
                    'alert_action' => 'actionRequestPasswordReset',
                ]);
                return $this->redirect('/site?request-reset-sent');
            } else {
                return $this->redirect('/site?reset-password-error');
            }
        }
        return $this->redirect('/site?reset-password-error');
    }
public function actionRequestPasswordReset ( ) { $ model = new PasswordResetRequestForm ( ) ; $ cnt = Yii :: $ app -> cache -> get ( Yii :: $ app -> params [ 'ResetPasswordCacheKey' ] ) ; if ( ! $ cnt ) { $ cnt = 1 ; } else { $ cnt ++ ; } Yii :: $ app -> cache -> set ( Yii :: $ app -> params [ 'ResetPasswordCacheKey' ] , $ cnt ) ; if ( Yii :: $ app -> request -> isAjax && $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; return ActiveForm :: validate ( $ model ) ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> validate ( ) ) { if ( $ model -> sendEmail ( ) ) { Yii :: $ app -> session -> setFlash ( 'success' , [ 'message' => Yii :: t ( 'forms/reset-password-form' , 'Instructions_recovery_sent' ) , 'ttl' => FLASH_MESSAGES_TTL , 'showClose' => true , 'alert_action' => 'actionRequestPasswordReset' , ] ) ; return $ this -> redirect ( '/site?request-reset-sent' ) ; } else { return $ this -> redirect ( '/site?reset-password-error' ) ; } } return $ this -> redirect ( '/site?reset-password-error' ) ; }
Requests password reset.
Requests password reset .
/*
                Yii::$app->session->setFlash('error', [
                    'message'   => Yii::t('app/flash-messages', 'RequestPasswordReset_error'),
                    'ttl'       => FLASH_MESSAGES_TTL,
                    'showClose' => true,
                    'alert_action' => 'actionRequestPasswordReset',
                ]);
                */