예제 #1
0
파일: Users.php 프로젝트: madoka8/ice-base
 /**
  * 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());
         }
     }
 }
예제 #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);
 }