示例#1
0
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByEmail($this->email);
     }
     return $this->_user;
 }
示例#2
0
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
示例#3
0
 public function ngRestExtraAttributeTypes()
 {
     return ['users' => ['checkboxRelation', 'model' => User::className(), 'refJoinTable' => 'admin_user_group', 'refModelPkId' => 'group_id', 'refJoinPkId' => 'user_id', 'labelFields' => ['firstname', 'lastname', 'email'], 'labelTemplate' => '%s %s (%s)']];
 }
示例#4
0
 /**
  * Returns an active record object for the admin user who last time updated this page.
  *
  * @return \luya\admin\models\User|boolean Returns an ActiceRecord for the admin user who last time updated this page, if not
  * found the return value is false.
  */
 public function getUserUpdated()
 {
     return User::findOne($this->itemArray['update_user_id']);
 }
示例#5
0
 /**
  * Create a new user and append them to an existing group.
  *
  * @return boolean
  */
 public function actionUser()
 {
     while (true) {
         $email = $this->prompt('User E-Mail:');
         if (!empty(User::findByEmail($email))) {
             $this->outputError('The provided E-Mail already exsists in the System.');
         } else {
             break;
         }
     }
     $titleArray = ['Mr' => 1, 'Mrs' => 2];
     $title = $this->select('Title:', $titleArray);
     $firstname = $this->prompt('Firstname:');
     $lastname = $this->prompt('Lastname:');
     $password = $this->prompt('User Password:'******'{$email}'?") !== true) {
         return $this->outputError('Abort user creation process.');
     }
     $user = new User();
     $user->email = $email;
     $user->password_salt = Yii::$app->getSecurity()->generateRandomString();
     $user->password = Yii::$app->getSecurity()->generatePasswordHash($password . $user->password_salt);
     $user->firstname = $firstname;
     $user->lastname = $lastname;
     $user->title = $titleArray[$title];
     if (!$user->save()) {
         throw new Exception("Unable to create new user.");
     }
     $groupSelect = [];
     foreach (Group::find()->all() as $entry) {
         $groupSelect[$entry->id] = $entry->name . ' (' . $entry->text . ')';
         $this->output($entry->id . ' - ' . $groupSelect[$entry->id]);
     }
     $groupId = $this->select('Select Group the user should belong to:', $groupSelect);
     $this->insert('admin_user_group', ['user_id' => $user->id, 'group_id' => $groupId]);
     return $this->outputSuccess("The user ({$email}) has been created.");
 }