2020-06-05 09:53:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-06-23 15:01:20 +00:00
|
|
|
namespace Appwrite\Utopia\Response\Model;
|
2020-06-05 09:53:06 +00:00
|
|
|
|
2020-06-23 15:01:20 +00:00
|
|
|
use Appwrite\Utopia\Response;
|
|
|
|
|
use Appwrite\Utopia\Response\Model;
|
2021-12-30 06:10:17 +00:00
|
|
|
use Utopia\Database\Document;
|
2020-06-05 09:53:06 +00:00
|
|
|
|
2020-06-23 15:01:20 +00:00
|
|
|
class User extends Model
|
2020-06-05 09:53:06 +00:00
|
|
|
{
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this
|
2020-06-22 16:25:01 +00:00
|
|
|
->addRule('$id', [
|
2020-11-07 22:14:48 +00:00
|
|
|
'type' => self::TYPE_STRING,
|
2020-06-22 16:25:01 +00:00
|
|
|
'description' => 'User ID.',
|
2021-01-13 15:06:36 +00:00
|
|
|
'default' => '',
|
2020-06-22 16:25:01 +00:00
|
|
|
'example' => '5e5ea5c16897e',
|
|
|
|
|
])
|
2022-06-15 12:46:52 +00:00
|
|
|
->addRule('$createdAt', [
|
2022-07-04 09:55:11 +00:00
|
|
|
'type' => self::TYPE_DATETIME,
|
2022-09-04 21:26:16 +00:00
|
|
|
'description' => 'User creation date in ISO 8601 format.',
|
2022-07-04 09:55:11 +00:00
|
|
|
'default' => '',
|
2022-08-14 10:27:07 +00:00
|
|
|
'example' => self::TYPE_DATETIME_EXAMPLE,
|
2022-06-15 12:46:52 +00:00
|
|
|
])
|
|
|
|
|
->addRule('$updatedAt', [
|
2022-07-04 09:55:11 +00:00
|
|
|
'type' => self::TYPE_DATETIME,
|
2022-09-04 21:26:16 +00:00
|
|
|
'description' => 'User update date in ISO 8601 format.',
|
2022-07-04 09:55:11 +00:00
|
|
|
'default' => '',
|
2022-08-14 10:27:07 +00:00
|
|
|
'example' => self::TYPE_DATETIME_EXAMPLE,
|
2022-06-15 12:46:52 +00:00
|
|
|
])
|
2020-06-22 16:25:01 +00:00
|
|
|
->addRule('name', [
|
2020-11-07 22:14:48 +00:00
|
|
|
'type' => self::TYPE_STRING,
|
2020-06-22 16:25:01 +00:00
|
|
|
'description' => 'User name.',
|
2021-01-13 15:06:36 +00:00
|
|
|
'default' => '',
|
2020-06-22 16:25:01 +00:00
|
|
|
'example' => 'John Doe',
|
|
|
|
|
])
|
2022-05-06 07:44:29 +00:00
|
|
|
->addRule('password', [
|
|
|
|
|
'type' => self::TYPE_STRING,
|
|
|
|
|
'description' => 'Hashed user password.',
|
2023-04-11 07:36:14 +00:00
|
|
|
'required' => false,
|
2022-05-06 07:44:29 +00:00
|
|
|
'default' => '',
|
|
|
|
|
'example' => '$argon2id$v=19$m=2048,t=4,p=3$aUZjLnliVWRINmFNTWMudg$5S+x+7uA31xFnrHFT47yFwcJeaP0w92L/4LdgrVRXxE',
|
|
|
|
|
])
|
2022-02-04 15:02:05 +00:00
|
|
|
->addRule('hash', [
|
|
|
|
|
'type' => self::TYPE_STRING,
|
|
|
|
|
'description' => 'Password hashing algorithm.',
|
2023-04-11 07:36:14 +00:00
|
|
|
'required' => false,
|
2022-02-04 15:02:05 +00:00
|
|
|
'default' => '',
|
2022-05-15 06:53:26 +00:00
|
|
|
'example' => 'argon2',
|
2022-02-04 15:02:05 +00:00
|
|
|
])
|
2022-05-04 14:37:37 +00:00
|
|
|
->addRule('hashOptions', [
|
2022-06-15 08:11:48 +00:00
|
|
|
'type' => [
|
|
|
|
|
Response::MODEL_ALGO_ARGON2,
|
|
|
|
|
Response::MODEL_ALGO_SCRYPT,
|
|
|
|
|
Response::MODEL_ALGO_SCRYPT_MODIFIED,
|
|
|
|
|
Response::MODEL_ALGO_BCRYPT,
|
|
|
|
|
Response::MODEL_ALGO_PHPASS,
|
|
|
|
|
Response::MODEL_ALGO_SHA,
|
|
|
|
|
Response::MODEL_ALGO_MD5, // keep least secure at the bottom. this order will be used in docs
|
|
|
|
|
],
|
2022-05-04 14:37:37 +00:00
|
|
|
'description' => 'Password hashing algorithm configuration.',
|
2023-04-11 07:36:14 +00:00
|
|
|
'required' => false,
|
2022-06-15 08:11:48 +00:00
|
|
|
'default' => [],
|
|
|
|
|
'example' => new \stdClass(),
|
|
|
|
|
'array' => false,
|
2022-05-04 14:37:37 +00:00
|
|
|
])
|
2020-06-22 19:06:57 +00:00
|
|
|
->addRule('registration', [
|
2022-07-04 09:55:11 +00:00
|
|
|
'type' => self::TYPE_DATETIME,
|
2022-09-04 21:26:16 +00:00
|
|
|
'description' => 'User registration date in ISO 8601 format.',
|
2022-08-19 10:03:54 +00:00
|
|
|
'default' => '',
|
2022-08-14 10:27:07 +00:00
|
|
|
'example' => self::TYPE_DATETIME_EXAMPLE,
|
2020-06-22 19:06:57 +00:00
|
|
|
])
|
|
|
|
|
->addRule('status', [
|
2021-07-14 11:02:12 +00:00
|
|
|
'type' => self::TYPE_BOOLEAN,
|
|
|
|
|
'description' => 'User status. Pass `true` for enabled and `false` for disabled.',
|
|
|
|
|
'default' => true,
|
|
|
|
|
'example' => true,
|
2020-06-22 19:06:57 +00:00
|
|
|
])
|
2023-05-27 00:15:38 +00:00
|
|
|
->addRule('labels', [
|
|
|
|
|
'type' => self::TYPE_STRING,
|
|
|
|
|
'description' => 'Labels for the user.',
|
|
|
|
|
'default' => [],
|
|
|
|
|
'example' => ['vip'],
|
|
|
|
|
'array' => true,
|
|
|
|
|
])
|
2021-05-04 18:52:46 +00:00
|
|
|
->addRule('passwordUpdate', [
|
2022-07-04 09:55:11 +00:00
|
|
|
'type' => self::TYPE_DATETIME,
|
2022-09-04 21:26:16 +00:00
|
|
|
'description' => 'Password update time in ISO 8601 format.',
|
2022-07-04 09:55:11 +00:00
|
|
|
'default' => '',
|
2022-08-14 10:27:07 +00:00
|
|
|
'example' => self::TYPE_DATETIME_EXAMPLE,
|
2021-05-04 18:52:46 +00:00
|
|
|
])
|
2020-06-22 16:25:01 +00:00
|
|
|
->addRule('email', [
|
2020-11-07 22:14:48 +00:00
|
|
|
'type' => self::TYPE_STRING,
|
2020-06-22 16:25:01 +00:00
|
|
|
'description' => 'User email address.',
|
2021-01-13 15:06:36 +00:00
|
|
|
'default' => '',
|
2020-06-22 16:25:01 +00:00
|
|
|
'example' => 'john@appwrite.io',
|
|
|
|
|
])
|
2022-06-08 09:00:38 +00:00
|
|
|
->addRule('phone', [
|
|
|
|
|
'type' => self::TYPE_STRING,
|
2022-06-14 07:27:27 +00:00
|
|
|
'description' => 'User phone number in E.164 format.',
|
2022-06-08 09:00:38 +00:00
|
|
|
'default' => '',
|
2022-06-13 12:43:17 +00:00
|
|
|
'example' => '+4930901820',
|
2022-06-08 09:00:38 +00:00
|
|
|
])
|
2020-06-22 16:25:01 +00:00
|
|
|
->addRule('emailVerification', [
|
2020-11-07 22:14:48 +00:00
|
|
|
'type' => self::TYPE_BOOLEAN,
|
2020-06-22 16:25:01 +00:00
|
|
|
'description' => 'Email verification status.',
|
|
|
|
|
'default' => false,
|
|
|
|
|
'example' => true,
|
|
|
|
|
])
|
2022-06-08 09:00:38 +00:00
|
|
|
->addRule('phoneVerification', [
|
|
|
|
|
'type' => self::TYPE_BOOLEAN,
|
|
|
|
|
'description' => 'Phone verification status.',
|
|
|
|
|
'default' => false,
|
|
|
|
|
'example' => true,
|
|
|
|
|
])
|
2020-06-22 16:25:01 +00:00
|
|
|
->addRule('prefs', [
|
2021-04-21 13:37:51 +00:00
|
|
|
'type' => Response::MODEL_PREFERENCES,
|
2020-06-22 16:25:01 +00:00
|
|
|
'description' => 'User preferences as a key-value object',
|
2022-05-23 14:54:50 +00:00
|
|
|
'default' => new \stdClass(),
|
2020-10-29 13:07:56 +00:00
|
|
|
'example' => ['theme' => 'pink', 'timezone' => 'UTC'],
|
2020-06-22 16:25:01 +00:00
|
|
|
])
|
2023-07-07 00:12:39 +00:00
|
|
|
->addRule('accessedAt', [
|
|
|
|
|
'type' => self::TYPE_DATETIME,
|
2023-07-20 18:47:26 +00:00
|
|
|
'description' => 'Most recent access date in ISO 8601 format. This attribute is only updated again after ' . APP_USER_ACCCESS / 60 / 60 . ' hours.',
|
2023-07-07 00:12:39 +00:00
|
|
|
'default' => '',
|
|
|
|
|
'example' => self::TYPE_DATETIME_EXAMPLE,
|
|
|
|
|
])
|
2020-06-05 09:53:06 +00:00
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 06:10:17 +00:00
|
|
|
/**
|
|
|
|
|
* Get Collection
|
2022-05-23 14:54:50 +00:00
|
|
|
*
|
2021-12-30 06:10:17 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function filter(Document $document): Document
|
|
|
|
|
{
|
|
|
|
|
$prefs = $document->getAttribute('prefs');
|
2022-05-23 14:54:50 +00:00
|
|
|
if ($prefs instanceof Document) {
|
2021-12-30 06:10:17 +00:00
|
|
|
$prefs = $prefs->getArrayCopy();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
if (is_array($prefs) && empty($prefs)) {
|
|
|
|
|
$document->setAttribute('prefs', new \stdClass());
|
2021-12-30 06:10:17 +00:00
|
|
|
}
|
|
|
|
|
return $document;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 09:53:06 +00:00
|
|
|
/**
|
|
|
|
|
* Get Name
|
2021-10-06 14:22:38 +00:00
|
|
|
*
|
2020-06-05 09:53:06 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
public function getName(): string
|
2020-06-05 09:53:06 +00:00
|
|
|
{
|
|
|
|
|
return 'User';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-12-15 10:19:29 +00:00
|
|
|
* Get Type
|
2021-10-06 14:22:38 +00:00
|
|
|
*
|
2020-06-05 09:53:06 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
public function getType(): string
|
2020-06-05 09:53:06 +00:00
|
|
|
{
|
2020-06-23 15:01:20 +00:00
|
|
|
return Response::MODEL_USER;
|
2020-06-05 09:53:06 +00:00
|
|
|
}
|
2021-10-06 14:22:38 +00:00
|
|
|
}
|