Esempio n. 1
0
 private function getUser()
 {
     if ($this->_user == null) {
         $this->_user = User::findOne(['username' => $this->username]);
     }
     return $this->_user;
 }
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user User */
     $user = User::findOne(['user_status' => User::STATUS_ACTIVE, 'user_email' => $this->email]);
     if ($user) {
         $user->generatePasswordResetToken();
         if ($user->save()) {
             return \Yii::$app->mailer->compose('@auth/views/mail/passwordResetToken', ['user' => $user])->setFrom([\Yii::$app->getModule('auth')->supportEmail => \Yii::$app->name])->setTo($this->email)->setSubject(Yii::t('auth.reset-password', 'Password reset for {name}', ['name' => \Yii::$app->name]))->send();
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  * @return User the loaded model
  * @throws HttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 4
0
 /**
  * @param $token
  * @return string|\yii\web\Response
  * @throws BadRequestHttpException
  */
 public function actionActivate()
 {
     $user = User::findOne(['user_status' => '0', 'activation_key' => $_GET['key']]);
     if ($user) {
         $user->activation_key = null;
         $user->user_status = 1;
         $update = $user->save(false);
         Yii::$app->getSession()->setFlash('active', Yii::t('auth.user', 'User has activation. Please login.'));
         return $this->goHome();
     } else {
         Yii::$app->getSession()->setFlash('expire', Yii::t('auth.user', 'Your activation key had expired, please re-active.'));
         return $this->render('expire');
     }
 }