Example #1
0
 public function actionSignup()
 {
     $model = new User();
     $model->setScenario('signup');
     if ($model->load($_POST) && $model->save()) {
         if (Yii::$app->getUser()->login($model)) {
             return $this->goHome();
         }
     }
     return $this->render('signup', ['model' => $model]);
 }
Example #2
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
Example #3
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 private function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
Example #4
0
 private function getUser()
 {
     if ($this->_user == null) {
         $this->_user = User::findOne(['username' => $this->username]);
     }
     return $this->_user;
 }
 /**
  * Creates a form model given a token.
  *
  * @param  string $token
  * @param  array $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException(Yii::t('auth.reset-password', 'Password reset token cannot be blank.'));
     }
     $this->_user = User::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException(Yii::t('auth.reset-password', 'Wrong password reset token.'));
     }
     parent::__construct($config);
 }
Example #6
0
 /**
  * Creates a form model given a token.
  *
  * @param  string $token
  * @param  array $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         Yii::$app->getSession()->setFlash('invalid', Yii::t('auth.reset-password', 'Wrong password reset token.'));
     }
     $this->_user = User::findByPasswordResetToken($token);
     if (!$this->_user) {
         Yii::$app->getSession()->setFlash('invalid', Yii::t('auth.reset-password', 'Wrong password reset token.'));
     }
     parent::__construct($config);
 }
Example #7
0
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'last_visit_time', $this->last_visit_time])->andFilterWhere(['like', 'create_time', $this->create_time])->andFilterWhere(['like', 'update_time', $this->update_time])->andFilterWhere(['like', 'delete_time', $this->delete_time]);
     return $dataProvider;
 }
 /**
  * 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;
 }
Example #9
0
 /**
  * 验证子系统请求头,确保是子系统的请求
  */
 public function authenticate($user, $request, $response)
 {
     $headers = $request->headers;
     $ticket = $request->get('ticket');
     if (isset($headers['app-id']) && isset($headers['signkey']) && isset($headers['once'])) {
         if (!$this->checkHeader($headers)) {
             return null;
         }
         $user = User::findIdentityByTicket($ticket);
         if ($user != null) {
             \Yii::$app->user->login($user);
             return $user;
         }
     }
     if ($ticket !== null) {
         $this->handleFailure($response);
     }
     return null;
 }
Example #10
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert)
 {
     parent::afterSave($insert);
 }
Example #11
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.');
     }
 }
Example #12
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');
     }
 }
Example #13
0
 /**
  * 获取用户数量,包含所有用户数量。
  */
 public static function getUsersCount()
 {
     $count = User::find()->count();
     return $count;
 }