From 16d2c88314364b5e79936f4262d453dff03abdad Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Mon, 3 Jan 2011 21:10:37 +0100 Subject: [PATCH] Implements the first API handler (/api/1/user//isRegistered). It is associated with a new permission, which can only be set as an additonal permission for existing users (accounts.user_perms). Signed-off-by: Vincent Zanotti --- classes/user.php | 5 ++-- classes/xorg.php | 2 +- modules/api.php | 54 ++++++++++++++++++++++++++++++++++++++++ upgrade/1.1.0/05_permissions.sql | 9 +++++++ 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 modules/api.php create mode 100644 upgrade/1.1.0/05_permissions.sql diff --git a/classes/user.php b/classes/user.php index b5669fa..98985b4 100644 --- a/classes/user.php +++ b/classes/user.php @@ -21,13 +21,14 @@ class User extends PlUser { - const PERM_GROUPS = 'groups'; - const PERM_MAIL = 'mail'; + const PERM_API_USER_READONLY = 'api_user_readonly'; const PERM_DIRECTORY_AX = 'directory_ax'; const PERM_DIRECTORY_PRIVATE = 'directory_private'; const PERM_EDIT_DIRECTORY = 'edit_directory'; const PERM_FORUMS = 'forums'; + const PERM_GROUPS = 'groups'; const PERM_LISTS = 'lists'; + const PERM_MAIL = 'mail'; const PERM_PAYMENT = 'payment'; private $_profile_fetched = false; diff --git a/classes/xorg.php b/classes/xorg.php index 83bc952..a0da2b6 100644 --- a/classes/xorg.php +++ b/classes/xorg.php @@ -28,7 +28,7 @@ class Xorg extends Platal 'profile', 'register', 'search', 'stats', 'admin', 'newsletter', 'axletter', 'bandeau', 'survey', 'fusionax', 'gadgets', 'googleapps', 'poison', - 'openid', 'reminder'); + 'openid', 'reminder', 'api'); } public function find_hook() diff --git a/modules/api.php b/modules/api.php new file mode 100644 index 0000000..5562302 --- /dev/null +++ b/modules/api.php @@ -0,0 +1,54 @@ + $this->make_api_hook('user', AUTH_COOKIE, 'api_user_readonly'), + ); + } + + // This handler supports the following URL patterns: + // /api/1/user/{forlife}/isRegistered + function handler_user(PlPage& $page, PlUser& $authUser, $payload, $user = null, $selector = null) + { + // Retrieve the PlUser referenced in the request. Note that this is the + // target user, not the authenticated user. + $user = PlUser::getSilent($user); + if (empty($user)) { + return PL_NOT_FOUND; + } + + if ($selector == 'isRegistered') { + $page->jsonAssign('isRegistered', $user->isActive()); + return PL_JSON; + } else { + return PL_NOT_FOUND; + } + } +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/upgrade/1.1.0/05_permissions.sql b/upgrade/1.1.0/05_permissions.sql new file mode 100644 index 0000000..6a6615d --- /dev/null +++ b/upgrade/1.1.0/05_permissions.sql @@ -0,0 +1,9 @@ +ALTER TABLE accounts CHANGE COLUMN user_perms user_perms + SET('groups', 'mail', 'directory_ax', 'directory_private', 'edit_directory', + 'forums', 'lists', 'payment', 'api_user_readonly') DEFAULT NULL; + +ALTER TABLE account_types CHANGE COLUMN perms perms + SET('groups', 'mail', 'directory_ax', 'directory_private', 'edit_directory', + 'forums', 'lists', 'payment', 'api_user_readonly') NOT NULL; + +-- vim:set syntax=mysql: -- 2.1.4