/**
  * @@Admin
  * @Route(admin/users/{int}/role/edit)
  * @param int $id
  * @throws ApplicationException
  */
 public function changeRole(int $id)
 {
     if (intval($this->context->getIdentity()->getCurrentUser()->getId()) === $id) {
         throw new ApplicationException("Cannot change your own role!");
     }
     $user = UserManager::getInstance()->getUserInfo($id);
     $role = UserManager::getInstance()->getUserRole($id);
     $roles = RoleManager::getInstance()->getAllRoles();
     $viewModel = new AdminChangeRoleViewModel($user, $role, $roles);
     $this->renderDefaultLayout($viewModel);
 }
Esempio n. 2
0
 private function seedRoles()
 {
     if (!$this->tableExists("roles")) {
         $this->updateDatabase();
     }
     if (!RoleManager::getInstance()->exists(AppConfig::DEFAULT_ADMIN_ROLE)) {
         RoleManager::getInstance()->createRole(AppConfig::DEFAULT_ADMIN_ROLE);
     }
     if (!RoleManager::getInstance()->exists(AppConfig::DEFAULT_REGISTRATION_ROLE)) {
         RoleManager::getInstance()->createRole(AppConfig::DEFAULT_REGISTRATION_ROLE);
     }
 }
 /**
  * @param RegisterBindingModel $model
  * @POST
  * @@NotLogged
  */
 public function registerPst(RegisterBindingModel $model)
 {
     try {
         $userId = UserManager::getInstance()->register($model);
         $roleId = RoleManager::getInstance()->getRoleId(AppConfig::DEFAULT_REGISTRATION_ROLE);
         UserManager::getInstance()->addToRole($userId, $roleId);
         $loginModel = new LoginBindingModel();
         $loginModel->setUsername($model->getUserName());
         $loginModel->setPassword($model->getPassword());
         $this->initLogin($loginModel);
     } catch (ApplicationException $e) {
         $this->redirect("users/register");
     }
 }