Example #1
0
 /**
  * Add role to user
  */
 public function addRole($role = 'login')
 {
     if ($this->getRole($role)) {
         // This user has this role
         return null;
     } else {
         // Add login role
         $roleUser = new AuthRolesUsers();
         $roleUser->user_id = $this->getId();
         $roleUser->role_id = Roles::findOne(['name' => $role])->getId();
         if ($roleUser->create() === true) {
             return true;
         } else {
             throw new Error($roleUser->getError());
         }
     }
 }
Example #2
0
 public function rolesAction()
 {
     $roles = Roles::find();
     if (!$roles->count()) {
         $login = new Roles();
         $login->name = 'login';
         $login->description = 'Login privileges, granted after account confirmation.';
         $login->create();
         $admin = new Roles();
         $admin->name = 'admin';
         $admin->description = 'Administrative user, has access to everything.';
         $admin->create();
         echo "The roles have been added.\n";
     }
     $this->view->setContent(false);
 }