diff --git a/include/ws_functions/pwg.users.php b/include/ws_functions/pwg.users.php index 31d2159ef..2af1a8afa 100644 --- a/include/ws_functions/pwg.users.php +++ b/include/ws_functions/pwg.users.php @@ -296,6 +296,30 @@ function ws_users_add($params, &$service) return $service->invoke('pwg.users.getList', array('user_id'=>$user_id)); } +/** + * API method + * Get a new authentication key for a user. + * @param mixed[] $params + * @option int[] user_id + * @option string pwg_token + */ +function ws_users_getAuthKey($params, &$service) +{ + if (get_pwg_token() != $params['pwg_token']) + { + return new PwgError(403, 'Invalid security token'); + } + + $authkey = create_user_auth_key($params['user_id']); + + if ($authkey === false) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'invalid user_id'); + } + + return $authkey; +} + /** * API method * Deletes users diff --git a/ws.php b/ws.php index d0c348e3b..b2c5e1779 100644 --- a/ws.php +++ b/ws.php @@ -943,6 +943,18 @@ enabled_high, registration_date, registration_date_string, registration_date_sin array('admin_only'=>true, 'post_only'=>true) ); + $service->addMethod( + 'pwg.users.getAuthKey', + 'ws_users_getAuthKey', + array( + 'user_id' => array('type'=>WS_TYPE_ID), + 'pwg_token' => array(), + ), + 'Get a new authentication key for a user. Only works for normal/generic users (not admins)', + $ws_functions_root . 'pwg.users.php', + array('admin_only'=>true, 'post_only'=>true) + ); + $service->addMethod( 'pwg.users.setInfo', 'ws_users_setInfo',