示例#1
0
文件: Register.php 项目: artang/test
 public function register()
 {
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->status = $this->status;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     return $user->save() ? $user : null;
 }
示例#2
0
 /**
  * Validates the password.
  * This method serves as the inline validation for password.
  */
 public function validatePassword()
 {
     $this->user = User::findByUsername($this->username);
     if (!$this->user || !$this->user->validatePassword($this->password)) {
         $this->addError('password', 'Incorrect username or password.');
     }
 }
示例#3
0
文件: Login.php 项目: artang/test
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
示例#4
0
 /**
  * check access
  */
 protected function checkUserAccess($action_id)
 {
     $uid = \Yii::$app->user->identity->id;
     //当前用户ID
     if (in_array($uid, $this->supperUsers)) {
         return true;
     }
     if (is_array($this->allowAccess) && in_array($action_id, $this->allowAccess)) {
         return;
     }
     $access = \app\modules\auth\models\User::access($uid);
     if (!$access || !in_array($action_id, $access)) {
         throw new \yii\base\HttpException(403, __('access deny'));
     }
 }
示例#5
0
 public function actionDelete($id)
 {
     if ($_POST['action'] == 1) {
         if ($id == 1) {
             echo json_encode(array('id' => array(0), 'class' => 'alert-error', 'message' => __('supper user can not delete')));
             exit;
         }
         if ($id === uid()) {
             echo json_encode(array('id' => array(0), 'class' => 'alert-error', 'message' => __('you can not remove yourself')));
             exit;
         }
         $model = \app\modules\auth\models\User::find($id);
         $model->delete();
         echo json_encode(array('id' => array($id), 'class' => 'alert-success', 'message' => __('delete user success')));
         exit;
     }
 }
示例#6
0
 /**
  * 用户绑定到组
  */
 public function actionBind($id)
 {
     $id = (int) $id;
     $model = \app\modules\auth\models\User::find($id);
     foreach ($model->groups as $g) {
         $groups[] = $g->group_id;
     }
     $rows = Group::find()->all();
     if ($rows) {
         $rows = Arr::model_tree($rows);
     }
     if ($_POST) {
         $group = $_POST['group'];
         //绑定用户到组
         UserGroup::UserGroupSave($id, $group);
         flash('success', __('bin user group success') . " # " . $id);
         redirect(url('auth/group/bind', array('id' => $id)));
     }
     echo $this->render('bind', array('rows' => $rows, 'groups' => $groups, 'model' => $model, 'id' => $id, 'self' => $model->yourself));
 }