Exemplo n.º 1
0
 private function currentUserIsNotAnonymous()
 {
     $user = $this->user_manager->getCurrentUser();
     if ($user && !$user->isAnonymous()) {
         return true;
     }
 }
Exemplo n.º 2
0
 /**
  * We need it to browse the API as we are logged in through the Web UI
  * @throws \User_PasswordExpiredException
  */
 private function getUserFromCookie()
 {
     $current_user = $this->user_manager->getCurrentUser();
     if (!$current_user->isAnonymous()) {
         $password_expiration_checker = new User_PasswordExpirationChecker();
         $password_expiration_checker->checkPasswordLifetime($current_user);
     }
     return $current_user;
 }
Exemplo n.º 3
0
 /**
  * Partial update of user details
  *
  * Things to take into account:
  * <ol>
  *  <li>You don't need to set all 'values' of the user, you can restrict to the modified ones</li>
  *  <li>Possible fields are:"email", "real_name", "username" and "status"
  *  <li>Examples: To update a user status and username, the values must be an array:
  * <pre>
  * {
  * "status" : "S"
  * ,
  *
  * "username": "******"
  * }
  * </pre>
  * </li>
  * </ol>
  *
  * @url PATCH {id}
  * @param string  $id        Id of the user
  * @param Array   $values    User fields values
  *
  */
 protected function patchUserDetails($id, array $values)
 {
     $watchee = $this->getUserById($id);
     $watcher = $this->rest_user_manager->getCurrentUser();
     if ($this->checkUserCanUpdateOtherUser($watcher, $watchee)) {
         foreach ($values as $key => $value) {
             switch ($key) {
                 case "status":
                     $watchee->setStatus($value);
                     break;
                 case "email":
                     $watchee->setEmail($value);
                     break;
                 case "real_name":
                     $watchee->setRealName($value);
                     break;
                 case "username":
                     $watchee->setUserName($value);
                     break;
                 default:
                     break;
             }
         }
         return $this->user_manager->updateDb($watchee);
     }
     throw new RestException(403, "Cannot update other's details");
 }
Exemplo n.º 4
0
 public function __construct()
 {
     $this->user_manager = UserManager::instance();
     $this->json_decoder = new JsonDecoder();
     $this->ugroup_literalizer = new UGroupLiteralizer();
     $this->rest_user_manager = RestUserManager::build();
     $this->forge_ugroup_permissions_manager = new User_ForgeUserGroupPermissionsManager(new User_ForgeUserGroupPermissionsDao());
 }
 public function __isAllowed()
 {
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $current_user = \UserManager::instance()->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
         if ($current_user->isLoggedIn()) {
             return true;
         }
         throw new RestException(401, 'Basic Authentication Required');
     }
 }