/** @inheritdoc */
 public function run()
 {
     if ($this->user === null) {
         $this->user = Yii::$app->user->identity;
         if ($this->user === null) {
             throw new ServerErrorHttpException("No user identity found");
         }
         $this->user->setScenario(User::SCENARIO_PROFILE_UPDATE);
     }
     $this->formOptions['action'] = ['@profile-update'];
     return $this->render($this->viewFile, ['user' => $this->user, 'formOptions' => $this->formOptions]);
 }
 public function registrationScenario(RegistrationForm &$registrationForm)
 {
     $rules = ['trimUsername' => [['username'], 'filter', 'filter' => 'trim'], 'requiredFields' => [['username', 'password', 'confirmPassword'], 'required'], 'confirmPassword' => ['confirmPassword', 'compare', 'compareAttribute' => 'password'], 'uniqueUsername' => ['username', 'unique', 'targetClass' => User::className(), 'targetAttribute' => 'username', 'message' => Yii::t('users', 'This username has already been taken')], 'usernameLength' => ['username', 'string', 'min' => 3, 'max' => 18]];
     if ($this->requireEmail === true) {
         $rules['emailRequired'] = ['email', 'required'];
         $rules['emailUnique'] = ['email', 'unique', 'targetClass' => User::className(), 'targetAttribute' => 'email', 'message' => Yii::t('users', 'This email address has already been taken')];
     }
     $this->addEmailRules($rules);
     $this->addPasswordRules($rules);
     return $rules;
 }
 public function resetPassword()
 {
     /** @var User $user */
     $this->user = User::findOne(['email' => $this->email]);
     if ($this->user === null) {
         throw new ServerErrorHttpException("No user identity found");
     }
     $this->trigger(self::EVENT_BEFORE_RESET_PASSWORD);
     $this->user->generatePasswordResetToken();
     if ($this->user->save()) {
         $this->trigger(self::EVENT_AFTER_RESET_PASSWORD);
         return true;
     }
     return false;
 }
Exemplo n.º 4
0
 public function run($token)
 {
     /** @var User $model */
     $model = User::findByPasswordResetToken($token);
     if ($model === null) {
         throw new ServerErrorHttpException("No user identity found");
     }
     $model->setScenario(User::SCENARIO_PASSWORD_RESET);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->removePasswordResetToken();
         if ($model->changePassword()) {
             Yii::$app->session->setFlash('info', Yii::t('users', 'Your password has been changed'));
             return $this->controller->redirect(['@login']);
         }
     }
     return $this->controller->render($this->viewFile, ['model' => $model]);
 }