From 3bcb1f846ed26b1d50b6b6d4f768eb200d02b2e4 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 26 Dec 2022 05:31:49 +0000 Subject: [PATCH] password disctionary endpont and project model --- app/controllers/api/projects.php | 31 +++++++++++++++++++ .../Utopia/Response/Model/Project.php | 1 + 2 files changed, 32 insertions(+) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 25045fc64d..cfe4a66acc 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -607,6 +607,37 @@ App::patch('/v1/projects/:projectId/auth/password-history') $response->dynamic($project, Response::MODEL_PROJECT); }); +App::patch('/v1/projects/:projectId/auth/password-dictionary') + ->desc('Update Project users limit') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN]) + ->label('sdk.namespace', 'projects') + ->label('sdk.method', 'updateAuthLimit') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_PROJECT) + ->param('projectId', '', new UID(), 'Project unique ID.') + ->param('enabled', false, new Boolean(true), 'Set whether or not to enable checking user\'s password against most commonly used passwords. Default is false.') + ->inject('response') + ->inject('dbForConsole') + ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForConsole) { + + $project = $dbForConsole->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $auths = $project->getAttribute('auths', []); + $auths['passwordDisctionary'] = (bool) filter_var($enabled, FILTER_VALIDATE_BOOLEAN); + + $dbForConsole->updateDocument('projects', $project->getId(), $project + ->setAttribute('auths', $auths)); + + $response->dynamic($project, Response::MODEL_PROJECT); + }); + App::patch('/v1/projects/:projectId/auth/max-sessions') ->desc('Update Project users limit') ->groups(['api', 'projects']) diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index 59bd8ea78c..599bb041cd 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -247,6 +247,7 @@ class Project extends Model $document->setAttribute('authDuration', $authValues['duration'] ?? Auth::TOKEN_EXPIRATION_LOGIN_LONG); $document->setAttribute('authSessionLimit', $authValues['maxSessions'] ?? APP_LIMIT_USER_SESSIONS_DEFAULT); $document->setAttribute('authPasswordHistory', $authValues['passwordHistory'] ?? 0); + $document->setAttribute('authPasswordDictionary', $authValues['passwordDictionary'] ?? false); foreach ($auth as $index => $method) { $key = $method['key'];