示例#1
0
文件: Acl.php 项目: psesd/cascade-lib
 /**
  * @inheritdoc
  */
 public function run()
 {
     if (!User::systemUser()) {
         return false;
     }
     return parent::run();
 }
示例#2
0
 /**
  * Logs in a user using the provided username and password.
  *
  * @return boolean whether the user is logged in successfully
  */
 public function login()
 {
     if ($this->validate()) {
         $user = User::findByEmail($this->email);
         Yii::$app->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0);
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $user = new User();
     $user->scenario = 'creation';
     $user->attributes = $this->input['admin'];
     $user->status = User::STATUS_ACTIVE;
     $superGroup = Group::find()->disableAccessCheck()->where(['system' => 'super_administrators'])->one();
     if (!$superGroup) {
         throw new Exception("Unable to find super_administrators group!");
     }
     $user->relationModels = [['parent_object_id' => $superGroup->primaryKey]];
     if ($user->save()) {
         return true;
     }
     foreach ($user->errors as $field => $errors) {
         $this->fieldErrors[$field] = implode('; ', $errors);
     }
     var_dump($this->fieldErrors);
     exit;
     return false;
 }
示例#4
0
 /**
  * Get user.
  *
  * @return \yii\db\ActiveRelation
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
示例#5
0
 /**
  * Create a user.
  */
 public function actionCreate()
 {
     $groups = Group::find()->disableAccessCheck()->orderBy('name')->all();
     $this->out("Groups");
     $options = [];
     $i = 1;
     $defaultGroup = null;
     foreach ($groups as $group) {
         $extra = '';
         if ($group->system === 'users') {
             $defaultGroup = $group->primaryKey;
             $extra = '*';
         }
         $options[$i] = $group->primaryKey;
         $this->out("{$i}) {$group->descriptor}{$extra}");
         $i++;
     }
     $options[''] = $defaultGroup;
     $group = Console::select("Choose", $options);
     if (empty($group)) {
         $group = $defaultGroup;
     } else {
         $group = $options[$group];
     }
     $user = new User();
     $user->scenario = 'creation';
     $user->first_name = $this->prompt("First name");
     $user->last_name = $this->prompt("Last name");
     $user->email = $this->prompt("Email");
     $user->status = 1;
     $user->username = $this->prompt("Username");
     $user->password = $this->prompt("Password");
     $user->registerRelationModel(['parent_object_id' => $group]);
     if (!$user->validate()) {
         \d($user->errors);
         $this->stderr("User didn't validate!");
         exit;
     }
     $individual = $user->guessIndividual();
     if (empty($individual)) {
         if (!Console::confirm("No matching individual was found. Continue?")) {
             $this->stderr("Bye!");
             exit;
         }
     } elseif (is_object($individual)) {
         $user->object_individual_id = $individual->primaryKey;
         if (!Console::confirm("Matching individual was found ({$individual->descriptor})! Continue?")) {
             $this->stderr("Bye!");
             exit;
         }
     } else {
         $options = [];
         $i = 1;
         $this->out("Possible Individual Matches...");
         foreach ($individual as $ind) {
             $options[$i] = $ind->primaryKey;
             $this->out("{$i}) {$ind->descriptor}");
             $i++;
         }
         $user->object_individual_id = Console::select("Choose", $options);
     }
     if ($user->save()) {
         $this->out("User created!");
     } else {
         \d($user->errors);
         $this->out("Error creating user!");
     }
 }
示例#6
0
 /**
  * @inheritdoc
  */
 public function getPrimaryModel()
 {
     return User::className();
 }
 /**
  * Get users.
  *
  * @return \yii\db\ActiveRelation
  */
 public function getUsers()
 {
     return $this->hasMany(User::className(), ['object_individual_id' => 'id']);
 }