コード例 #1
0
 /**
  * Check that there is no such E-mail in the system
  */
 public function validateEmailUnique()
 {
     if ($this->email) {
         $exists = User::findOne(['email' => $this->email]);
         if ($exists) {
             $this->addError('email', Yii::t('yee/auth', 'This E-mail already exists'));
         }
     }
 }
コード例 #2
0
 /**
  * Check that there is no such username in the system
  */
 public function validateUsernameUnique()
 {
     if ($this->username) {
         $exists = User::findOne(['username' => $this->username]);
         if ($exists) {
             $this->addError('username', Yii::t('yee/auth', 'Login has been taken'));
         }
     }
 }
コード例 #3
0
 /**
  * @param int $id User ID
  *
  * @throws \yii\web\NotFoundHttpException
  * @return string
  */
 public function actionChangePassword($id)
 {
     $model = User::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException(Yii::t('yee/user', 'User not found'));
     }
     $model->scenario = 'changePassword';
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('crudMessage', Yii::t('yee/auth', 'Password has been updated'));
         return $this->redirect(['change-password', 'id' => $model->id]);
     }
     return $this->renderIsAjax('changePassword', compact('model'));
 }
コード例 #4
0
 /**
  * @param int $id User ID
  *
  * @throws \yii\web\NotFoundHttpException
  * @return string
  */
 public function actionSet($id)
 {
     $user = User::findOne($id);
     if (!$user) {
         throw new NotFoundHttpException(Yii::t('yee/user', 'User not found'));
     }
     $permissionsByGroup = [];
     $permissions = Permission::find()->andWhere([Yii::$app->yee->auth_item_table . '.name' => array_keys(Permission::getUserPermissions($user->id))])->joinWith('group')->all();
     foreach ($permissions as $permission) {
         $permissionsByGroup[@$permission->group->name][] = $permission;
     }
     return $this->renderIsAjax('set', compact('user', 'permissionsByGroup'));
 }
コード例 #5
0
 /**
  * @return bool
  */
 public function validateEmailConfirmedAndUserActive()
 {
     if (!Yii::$app->yee->checkAttempts()) {
         $this->addError('email', Yii::t('yee/auth', 'Too many attempts'));
         return false;
     }
     $user = User::findOne(['email' => $this->email, 'email_confirmed' => 1, 'status' => User::STATUS_ACTIVE]);
     if ($user) {
         $this->user = $user;
     } else {
         $this->addError('email', Yii::t('yee/auth', 'E-mail is invalid'));
     }
 }