/** * 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')); } } }
/** * 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')); } } }
/** * @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')); }
/** * @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')); }
/** * @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')); } }