2019-05-09 06:54:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Services;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use Appwrite\Client;
|
|
|
|
|
use Appwrite\Service;
|
|
|
|
|
|
|
|
|
|
class Users extends Service
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* List Users
|
|
|
|
|
*
|
2019-10-09 08:40:02 +00:00
|
|
|
* Get a list of all the project users. You can use the query params to filter
|
|
|
|
|
* your results.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $search
|
|
|
|
|
* @param int $limit
|
|
|
|
|
* @param int $offset
|
|
|
|
|
* @param string $orderType
|
2019-05-09 06:54:39 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-01-30 16:18:59 +00:00
|
|
|
public function list(string $search = '', int $limit = 25, int $offset = 0, string $orderType = 'ASC'):array
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
$path = str_replace([], [], '/users');
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
$params['search'] = $search;
|
|
|
|
|
$params['limit'] = $limit;
|
|
|
|
|
$params['offset'] = $offset;
|
|
|
|
|
$params['orderType'] = $orderType;
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_GET, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-05-09 06:54:39 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create User
|
|
|
|
|
*
|
2019-10-09 08:40:02 +00:00
|
|
|
* Create a new user.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $email
|
|
|
|
|
* @param string $password
|
|
|
|
|
* @param string $name
|
2019-05-09 06:54:39 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-01-30 16:18:59 +00:00
|
|
|
public function create(string $email, string $password, string $name = ''):array
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
$path = str_replace([], [], '/users');
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
$params['email'] = $email;
|
|
|
|
|
$params['password'] = $password;
|
|
|
|
|
$params['name'] = $name;
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_POST, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-05-09 06:54:39 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get User
|
|
|
|
|
*
|
2019-10-09 08:40:02 +00:00
|
|
|
* Get user by its unique ID.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $userId
|
2019-05-09 06:54:39 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-01-30 16:18:59 +00:00
|
|
|
public function get(string $userId):array
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
$path = str_replace(['{userId}'], [$userId], '/users/{userId}');
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_GET, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-05-09 06:54:39 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get User Logs
|
|
|
|
|
*
|
2019-10-09 08:40:02 +00:00
|
|
|
* Get user activity logs list by its unique ID.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $userId
|
2019-05-09 06:54:39 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-01-30 16:18:59 +00:00
|
|
|
public function getLogs(string $userId):array
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
$path = str_replace(['{userId}'], [$userId], '/users/{userId}/logs');
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_GET, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-05-09 06:54:39 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-01-27 21:50:41 +00:00
|
|
|
* Get User Preferences
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-09 08:40:02 +00:00
|
|
|
* Get user preferences by its unique ID.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $userId
|
2019-05-09 06:54:39 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-01-30 16:18:59 +00:00
|
|
|
public function getPrefs(string $userId):array
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
$path = str_replace(['{userId}'], [$userId], '/users/{userId}/prefs');
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_GET, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-05-09 06:54:39 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 04:16:38 +00:00
|
|
|
/**
|
2020-01-27 21:50:41 +00:00
|
|
|
* Update User Preferences
|
2019-10-09 04:16:38 +00:00
|
|
|
*
|
2019-10-09 08:40:02 +00:00
|
|
|
* Update user preferences by its unique ID. You can pass only the specific
|
|
|
|
|
* settings you wish to update.
|
2019-10-09 04:16:38 +00:00
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $userId
|
2020-02-14 06:28:54 +00:00
|
|
|
* @param array $prefs
|
2019-10-09 04:16:38 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-02-14 06:28:54 +00:00
|
|
|
public function updatePrefs(string $userId, array $prefs):array
|
2019-10-09 04:16:38 +00:00
|
|
|
{
|
|
|
|
|
$path = str_replace(['{userId}'], [$userId], '/users/{userId}/prefs');
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
$params['prefs'] = $prefs;
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_PATCH, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-10-09 04:16:38 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-09 06:54:39 +00:00
|
|
|
/**
|
|
|
|
|
* Get User Sessions
|
|
|
|
|
*
|
2019-10-09 08:40:02 +00:00
|
|
|
* Get user sessions list by its unique ID.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $userId
|
2019-05-09 06:54:39 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-01-30 16:18:59 +00:00
|
|
|
public function getSessions(string $userId):array
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
$path = str_replace(['{userId}'], [$userId], '/users/{userId}/sessions');
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_GET, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-05-09 06:54:39 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete User Sessions
|
|
|
|
|
*
|
|
|
|
|
* Delete all user sessions by its unique ID.
|
|
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $userId
|
2019-05-09 06:54:39 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-01-30 16:18:59 +00:00
|
|
|
public function deleteSessions(string $userId):array
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
$path = str_replace(['{userId}'], [$userId], '/users/{userId}/sessions');
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_DELETE, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-05-09 06:54:39 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete User Session
|
|
|
|
|
*
|
2019-10-09 08:40:02 +00:00
|
|
|
* Delete user sessions by its unique ID.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $userId
|
|
|
|
|
* @param string $sessionId
|
2019-05-09 06:54:39 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-01-30 16:18:59 +00:00
|
|
|
public function deleteSession(string $userId, string $sessionId):array
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
2020-05-02 04:23:56 +00:00
|
|
|
$path = str_replace(['{userId}', '{sessionId}'], [$userId, $sessionId], '/users/{userId}/sessions/{sessionId}');
|
2019-05-09 06:54:39 +00:00
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_DELETE, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-05-09 06:54:39 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-13 20:19:06 +00:00
|
|
|
* Update User Status
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-09 08:40:02 +00:00
|
|
|
* Update user status by its unique ID.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-10-19 17:21:36 +00:00
|
|
|
* @param string $userId
|
|
|
|
|
* @param string $status
|
2019-05-09 06:54:39 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-01-30 16:18:59 +00:00
|
|
|
public function updateStatus(string $userId, string $status):array
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
|
|
|
|
$path = str_replace(['{userId}'], [$userId], '/users/{userId}/status');
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
$params['status'] = $status;
|
|
|
|
|
|
|
|
|
|
return $this->client->call(Client::METHOD_PATCH, $path, [
|
2019-10-18 18:42:02 +00:00
|
|
|
'content-type' => 'application/json',
|
2019-05-09 06:54:39 +00:00
|
|
|
], $params);
|
|
|
|
|
}
|
2019-10-01 18:10:33 +00:00
|
|
|
|
|
|
|
|
}
|