mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
account endpoint custom id
This commit is contained in:
@@ -24,6 +24,7 @@ use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Appwrite\Database\Validator\CustomId;
|
||||
|
||||
$oauthDefaultSuccess = App::getEnv('_APP_HOME').'/auth/oauth2/success';
|
||||
$oauthDefaultFailure = App::getEnv('_APP_HOME').'/auth/oauth2/failure';
|
||||
@@ -42,6 +43,7 @@ App::post('/v1/account')
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_USER)
|
||||
->label('abuse-limit', 10)
|
||||
->param('userId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.')
|
||||
->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)
|
||||
@@ -50,7 +52,7 @@ App::post('/v1/account')
|
||||
->inject('project')
|
||||
->inject('dbForInternal')
|
||||
->inject('audits')
|
||||
->action(function ($email, $password, $name, $request, $response, $project, $dbForInternal, $audits) {
|
||||
->action(function ($userId, $email, $password, $name, $request, $response, $project, $dbForInternal, $audits) {
|
||||
/** @var Utopia\Swoole\Request $request */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Utopia\Database\Document $project */
|
||||
@@ -84,7 +86,7 @@ App::post('/v1/account')
|
||||
Authorization::disable();
|
||||
|
||||
try {
|
||||
$userId = $dbForInternal->getId();
|
||||
$userId = $userId == 'unique()' ? $dbForInternal->getId() : $userId;
|
||||
$user = $dbForInternal->createDocument('users', new Document([
|
||||
'$id' => $userId,
|
||||
'$read' => ['role:all'],
|
||||
@@ -137,6 +139,7 @@ App::post('/v1/account/sessions')
|
||||
->label('sdk.response.model', Response::MODEL_SESSION)
|
||||
->label('abuse-limit', 10)
|
||||
->label('abuse-key', 'url:{url},email:{param-email}')
|
||||
->param('sessionId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.')
|
||||
->param('email', '', new Email(), 'User email.')
|
||||
->param('password', '', new Password(), 'User password. Must be between 6 to 32 chars.')
|
||||
->inject('request')
|
||||
@@ -145,7 +148,7 @@ App::post('/v1/account/sessions')
|
||||
->inject('locale')
|
||||
->inject('geodb')
|
||||
->inject('audits')
|
||||
->action(function ($email, $password, $request, $response, $dbForInternal, $locale, $geodb, $audits) {
|
||||
->action(function ($sessionId, $email, $password, $request, $response, $dbForInternal, $locale, $geodb, $audits) {
|
||||
/** @var Utopia\Swoole\Request $request */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Utopia\Database\Database $dbForInternal */
|
||||
@@ -178,7 +181,7 @@ App::post('/v1/account/sessions')
|
||||
$secret = Auth::tokenGenerator();
|
||||
$session = new Document(array_merge(
|
||||
[
|
||||
'$id' => $dbForInternal->getId(),
|
||||
'$id' => $sessionId == 'unique()' ? $dbForInternal->getId() : $sessionId,
|
||||
'userId' => $profile->getId(),
|
||||
'provider' => Auth::SESSION_PROVIDER_EMAIL,
|
||||
'providerUid' => $email,
|
||||
@@ -679,7 +682,19 @@ App::post('/v1/account/sessions/anonymous')
|
||||
->setAttribute('$read', ['user:'.$user->getId()])
|
||||
->setAttribute('$write', ['user:'.$user->getId()])
|
||||
);
|
||||
|
||||
it', 50)
|
||||
->label('abuse-key', 'ip:{ip}')
|
||||
->inject('request')
|
||||
->inject('response')
|
||||
->inject('locale')
|
||||
->inject('user')
|
||||
->inject('project')
|
||||
->inject('dbForInternal')
|
||||
->inject('geodb')
|
||||
->inject('audits')
|
||||
->action(function ($request, $response, $locale, $user, $project, $dbForInternal, $geodb, $audits) {
|
||||
/** @var Utopia\Swoole\Request $request */
|
||||
/** @var Appwrite\Utopia\Response $respons
|
||||
$user = $dbForInternal->updateDocument('users', $user->getId(),
|
||||
$user->setAttribute('sessions', $session, Document::SET_TYPE_APPEND));
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ abstract class Scope extends TestCase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console',
|
||||
], [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -99,6 +100,7 @@ abstract class Scope extends TestCase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console',
|
||||
], [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -138,6 +140,7 @@ abstract class Scope extends TestCase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -150,6 +153,7 @@ abstract class Scope extends TestCase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
@@ -20,6 +20,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -42,6 +43,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -54,6 +56,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => '',
|
||||
'password' => '',
|
||||
]);
|
||||
@@ -65,6 +68,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => '',
|
||||
]);
|
||||
@@ -76,6 +80,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => '',
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -106,6 +111,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -123,6 +129,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email.'x',
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -134,6 +141,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password.'x',
|
||||
]);
|
||||
@@ -145,6 +153,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => '',
|
||||
'password' => '',
|
||||
]);
|
||||
@@ -482,6 +491,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => 'new-password',
|
||||
]);
|
||||
@@ -601,6 +611,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $data['email'],
|
||||
'password' => $data['password'],
|
||||
'name' => $data['name'],
|
||||
@@ -844,6 +855,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -911,6 +923,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -993,6 +1006,7 @@ trait AccountBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
@@ -68,6 +68,7 @@ class AccountCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -82,6 +83,7 @@ class AccountCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -124,6 +126,7 @@ class AccountCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -147,6 +150,7 @@ class AccountCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -161,6 +165,7 @@ class AccountCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -325,6 +330,7 @@ class AccountCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password
|
||||
]);
|
||||
@@ -368,6 +374,7 @@ class AccountCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
@@ -26,6 +26,7 @@ class AccountCustomServerTest extends Scope
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
|
||||
@@ -320,6 +320,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), [
|
||||
'userIdId' => 'unique()',
|
||||
'email' => $originalEmail,
|
||||
'password' => $originalPassword,
|
||||
'name' => $originalName,
|
||||
@@ -330,6 +331,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $originalEmail,
|
||||
'password' => $originalPassword,
|
||||
]);
|
||||
@@ -372,6 +374,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -419,6 +422,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $originalEmail,
|
||||
'password' => $originalPassword,
|
||||
]);
|
||||
@@ -479,6 +483,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -504,6 +509,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -665,6 +671,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), [
|
||||
'teamId' => 'unique()',
|
||||
'name' => 'Arsenal'
|
||||
]);
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -77,6 +78,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
@@ -87,6 +89,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -143,6 +146,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -209,6 +213,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -281,6 +286,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
@@ -339,6 +345,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'sessionId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
@@ -133,6 +133,7 @@ class WebhooksTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
]), [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
|
||||
Reference in New Issue
Block a user