コード例 #1
0
 public function setCurrentUser()
 {
     if ($this->isLogged()) {
         $userId = (string) HttpContext::getInstance()->getSession()->userId;
         $this->currentUser = UserManager::getInstance()->getUserInfo($userId);
     }
 }
コード例 #2
0
 private function beforeActionExecute()
 {
     $userId = (string) HttpContext::getInstance()->getSession()->userId;
     if ($userId === "" || !UserManager::getInstance()->isInRoleById($userId, AppConfig::DEFAULT_ADMIN_ROLE)) {
         throw new ApplicationException("Not enough permissions to see this page!");
     }
 }
コード例 #3
0
 private function beforeActionExecute()
 {
     $userId = (string) HttpContext::getInstance()->getSession()->userId;
     if ($userId == "") {
         Helpers::redirect("users/login");
     }
     $userRole = UserManager::getInstance()->getUserRole(intval($userId));
     if (!in_array($userRole->getName(), $this->roles)) {
         throw new ApplicationException("Not enough permissions to see this page!");
     }
 }
コード例 #4
0
 /**
  * @@Admin
  * @Route(admin/users/{int}/role/editPst)
  * @POST
  * @param int $id
  * @param ChangeRoleBindingModel $model
  * @throws ApplicationException
  */
 public function changeRolePst(int $id, ChangeRoleBindingModel $model)
 {
     if (intval($this->context->getIdentity()->getCurrentUser()->getId()) === $id) {
         throw new ApplicationException("Cannot change your own role!");
     }
     try {
         if (!UserManager::getInstance()->removeUserRoles($id)) {
             throw new ApplicationException("Couldn't change user role.");
         }
         UserManager::getInstance()->addToRole($id, $model->getNewRole());
         $this->redirect("admin/users");
     } catch (ApplicationException $e) {
         $_SESSION["binding-errors"] = [$e->getMessage()];
         $this->redirect("admin/users/" . $id . "/role/edit");
     }
 }
コード例 #5
0
 /**
  * @param \Framework\Models\BindingModels\ChangePasswordBindingModel $model
  * @@Authorize
  * @POST
  */
 public function passwordPst(\Framework\Models\BindingModels\ChangePasswordBindingModel $model)
 {
     try {
         if (UserManager::getInstance()->changePassword($model)) {
             $this->redirect("users/profile");
         }
     } catch (ApplicationException $e) {
         $userProfileViewModel = $this->context->getIdentity()->getCurrentUser();
         $this->renderDefaultLayout($userProfileViewModel);
     }
 }