Esempio n. 1
0
 /**
  * Signs user up.
  * @param boolean $runValidation whether to perform validation (calling [[validate()]])
  * before signup the user.
  * @return User|null the saved model or null if saving fails
  */
 public function signup($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return null;
     }
     $user = new User();
     $user->email = $this->email;
     $user->password = $this->password;
     $user->statusId = User::STATUS_ACTIVE;
     if ($user->save(false)) {
         $user->sendNewUserEmail();
         return $user;
     }
     return null;
 }
 /**
  * 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 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', 'Password reset token cannot be blank.'));
     }
     $this->_user = User::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException(Yii::t('auth', 'Wrong password reset token.'));
     }
     parent::__construct($config);
 }
 public function testSendEmailCorrectUser()
 {
     $model = new PasswordResetRequestForm();
     $model->email = $this->user[0]['email'];
     $user = User::findOne(['passwordResetToken' => $this->user[0]['passwordResetToken']]);
     expect('email sent', $model->send())->true();
     expect('user has valid token', $user->passwordResetToken)->notNull();
     expect('message file exists', file_exists($this->getMessageFile()))->true();
     $message = file_get_contents($this->getMessageFile());
     expect('message "from" is correct', $message)->contains(Yii::$app->params['appEmail']);
     expect('message "to" is correct', $message)->contains($model->email);
 }
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function send()
 {
     /* @var $user User */
     $user = User::findOne(['statusId' => User::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!User::isPasswordResetTokenValid($user->passwordResetToken)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             return Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])->setFrom([Yii::$app->params['appEmail'] => Yii::$app->name])->setTo($this->email)->setSubject('Password reset for ' . Yii::$app->name)->send();
         }
     }
     return false;
 }
Esempio n. 5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('0=1');
         return $dataProvider;
     }
     // status
     if (empty($this->statusId)) {
         $query->andFilterWhere(['not', ['statusId' => User::STATUS_DELETED]]);
     } elseif ($this->statusId > 0) {
         $query->andFilterWhere(['statusId' => $this->statusId]);
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'authKey', $this->authKey]);
     return $dataProvider;
 }
Esempio n. 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'userId']);
 }
Esempio n. 7
0
 /**
  * This method is called after each cest class test method, even if test failed.
  * @param \Codeception\Event\TestEvent $event
  */
 public function _after($event)
 {
     User::deleteAll(['email' => '*****@*****.**']);
 }