diff options
author | Aleksander Machniak <machniak@kolabsys.com> | 2019-06-26 09:42:44 +0000 |
---|---|---|
committer | Aleksander Machniak <machniak@kolabsys.com> | 2019-06-26 09:42:44 +0000 |
commit | 829a757c5d7e9298b9db2360e584e945a925970a (patch) | |
tree | 1ce32748c13c00db19bd4539fba3b2297f27f888 | |
parent | 35251088ee10e5fb2ee7bc02e0d92aa9421a8fa8 (diff) | |
download | webadmin-kolab-webadmin-3.2.14.tar.gz |
Add user.password action to the API (Bifrost#T221026)kolab-webadmin-3.2.14
-rw-r--r-- | lib/api/kolab_api_service_user.php | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php index 43ab530..d63636d 100644 --- a/lib/api/kolab_api_service_user.php +++ b/lib/api/kolab_api_service_user.php @@ -37,14 +37,10 @@ class kolab_api_service_user extends kolab_api_service */ public function capabilities($domain) { - //console("kolab_api_service_group::capabilities"); - $auth = Auth::get_instance($domain); $effective_rights = $auth->list_rights('user'); - //console("effective_rights", $effective_rights); - $rights = array(); if (in_array('add', $effective_rights['entryLevelRights'])) { @@ -56,7 +52,8 @@ class kolab_api_service_user extends kolab_api_service } if (in_array('modrdn', $effective_rights['entryLevelRights'])) { - $rights['edit'] = "w"; + $rights['edit'] = "w"; + $rights['password'] = "w"; } if (in_array('read', $effective_rights['entryLevelRights'])) { @@ -111,7 +108,6 @@ class kolab_api_service_user extends kolab_api_service */ public function user_delete($getdata, $postdata) { - //console("user_delete()", $getdata, $postdata); if (!isset($postdata['id'])) { return false; } @@ -120,13 +116,17 @@ class kolab_api_service_user extends kolab_api_service $auth = Auth::get_instance(); $result = $auth->user_delete($postdata['id']); - if ($result) { - return $result; - } - - return false; + return $result; } + /** + * Update user. + * + * @param array $get GET parameters + * @param array $post POST parameters + * + * @return array|bool User attributes or False on error. + */ public function user_edit($getdata, $postdata) { Log::trace("\$postdata to user_edit()", $postdata); @@ -148,9 +148,45 @@ class kolab_api_service_user extends kolab_api_service } return false; + } + /** + * Update user password. + * + * @param array $get GET parameters + * @param array $post POST parameters + * + * @return bool True on success, False on failure + */ + public function user_password($getdata, $postdata) + { + $password = $postdata['password']; + $user_id = $postdata['id']; + + if (empty($user_id) || !is_string($password) || !strlen($password)) { + return false; + } + + if ($user_id === 'me') { + $user_id = $_SESSION['user']->get_userid(); + } + + password_policy::validate_password($password); + + $auth = Auth::get_instance(); + $result = $auth->user_edit($user_id, array('userpassword' => $password)); + + return $result !== false; } + /** + * Effective rights on user record. + * + * @param array $get GET parameters + * @param array $post POST parameters + * + * @return array Effective rights + */ public function user_effective_rights($getdata, $postdata) { $auth = Auth::get_instance(); @@ -230,5 +266,4 @@ class kolab_api_service_user extends kolab_api_service return false; } - } |