/**
  * @return bool
  */
 public function change()
 {
     if (!$this->validate()) {
         return false;
     }
     $this->user->password = $this->user->passwordToHash($this->password);
     return $this->user->save();
 }
Пример #2
0
 /**
  * @param \app\core\models\User $identity
  * @param bool $cookieBased
  * @param int $duration
  */
 public function afterLogin($identity, $cookieBased, $duration)
 {
     $user = User::findIdentity($identity->user_id);
     if ($user) {
         //更新已存在用户
     } else {
         //保存新用户
         $user = new User();
         $user->attributes = $identity->attributes;
         $user->save();
     }
 }
 public function register()
 {
     if (!$this->validate()) {
         return false;
     }
     $user = new User();
     $user->attributes = $this->attributes;
     $user->password = $user->passwordToHash($this->password);
     $user->role = UserRole::USER;
     if (!$user->save()) {
         $this->addErrors($user->getErrors());
         return false;
     }
     \Yii::$app->mailer->compose('@app/auth/mail/registration', ['user' => $user])->setTo($user->email)->send();
     return true;
 }