appwrite/src/Appwrite/Utopia/Response/Model/User.php

170 lines
5.8 KiB
PHP
Raw Normal View History

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;
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',
])
->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,
])
->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,
])
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.',
'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.',
'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.',
'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', [
'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
])
->addRule('labels', [
'type' => self::TYPE_STRING,
'description' => 'Labels for the user.',
'default' => [],
'example' => ['vip'],
'array' => true,
])
->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,
])
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(),
'example' => ['theme' => 'pink', 'timezone' => 'UTC'],
2020-06-22 16:25:01 +00:00
])
->addRule('accessedAt', [
'type' => self::TYPE_DATETIME,
'description' => 'Most recent access date in ISO 8601 format. This attribute is only updated again after ' . APP_USER_ACCCESS / 60 / 60 . ' hours.',
'default' => '',
'example' => self::TYPE_DATETIME_EXAMPLE,
])
2020-06-05 09:53:06 +00:00
;
}
/**
* Get Collection
2022-05-23 14:54:50 +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) {
$prefs = $prefs->getArrayCopy();
}
2022-05-23 14:54:50 +00:00
if (is_array($prefs) && empty($prefs)) {
$document->setAttribute('prefs', new \stdClass());
}
return $document;
}
2020-06-05 09:53:06 +00:00
/**
* Get Name
*
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
*
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
}
}