From 5e2f3ed9c97a1be219719052198b9f8a726667bb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 5 Jul 2021 16:35:29 +0545 Subject: [PATCH] custom id support in create user --- app/controllers/api/users.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 463b1c14b0..e7e7efa39f 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -17,6 +17,7 @@ use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Validator\UID; use DeviceDetector\DeviceDetector; +use Utopia\Database\Validator\Key; App::post('/v1/users') ->desc('Create User') @@ -30,19 +31,20 @@ App::post('/v1/users') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_USER) + ->param('id', 'uid()', new Key(), 'Unique Id. Passing `uid()` will auto generate the id.') ->param('email', '', new Email(), 'User email.') ->param('password', '', new Password(), 'User password. Must be between 6 to 32 chars.') ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('response') ->inject('dbForInternal') - ->action(function ($email, $password, $name, $response, $dbForInternal) { + ->action(function ($id, $email, $password, $name, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForInternal */ $email = \strtolower($email); try { - $userId = $dbForInternal->getId(); + $userId = $id == 'uid()' ? $dbForInternal->getId() : $id; $user = $dbForInternal->createDocument('users', new Document([ '$id' => $userId, '$read' => ['role:all'],