private function currentUserIsNotAnonymous() { $user = $this->user_manager->getCurrentUser(); if ($user && !$user->isAnonymous()) { return true; } }
/** * 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; }
/** * 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"); }