Beispiel #1
0
 /**
  * 修改密码
  * @return bool
  */
 public function changePassword()
 {
     $id = Yii::$app->user->identity->id;
     $user = User::findOne($id);
     if (is_null($user)) {
         return false;
     }
     $user->salt = Str::random(10);
     $user->password = $user->generatePassword($this->password);
     return $user->save(false);
 }
Beispiel #2
0
 /**
  * 忘了密码
  */
 public function forgot()
 {
     if ($this->validate()) {
         $passwordReminder = new PasswordReminder();
         $passwordReminder->email = $this->email;
         $passwordReminder->token = Str::random(40);
         $passwordReminder->created_at = new Carbon();
         $passwordReminder->save(false);
         Yii::$app->mail->compose('forgotpassword', ['token' => $passwordReminder->token])->setTo($this->email)->setSubject(Yii::$app->id . ' 重置密码邮件')->send();
         return true;
     }
     return false;
 }
Beispiel #3
0
 public function resetPassword()
 {
     if ($this->validate()) {
         $user = User::findByEmail($this->email, true);
         if (is_null($user)) {
             $this->addError('email', '无效的邮箱');
             return false;
         }
         $user->salt = Str::random(10);
         $user->password = $user->generatePassword($this->password);
         return $user->save();
     }
     $this->addError('password', '重置密码失败');
     return false;
 }
Beispiel #4
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $model->salt = Str::random(10);
             $model->password = $model->generatePassword($model->password);
             if ($model->save(false)) {
                 Yii::$app->session->setFlash('create_user', '用户添加成功:您可以继续添加新用户,或返回用户列表。');
                 return $this->redirect(['create']);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }