diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 8b66604504..17d9f47f35 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -45,6 +45,7 @@ use Utopia\Validator\WhiteList; use Appwrite\Auth\Validator\PasswordHistory; use Appwrite\Auth\Validator\PasswordDictionary; use Appwrite\Auth\Validator\PersonalData; +use Appwrite\Hooks\Hooks; $oauthDefaultSuccess = '/auth/oauth2/success'; $oauthDefaultFailure = '/auth/oauth2/failure'; @@ -76,7 +77,8 @@ App::post('/v1/account') ->inject('project') ->inject('dbForProject') ->inject('queueForEvents') - ->action(function (string $userId, string $email, string $password, string $name, Request $request, Response $response, Document $user, Document $project, Database $dbForProject, Event $queueForEvents) { + ->inject('hooks') + ->action(function (string $userId, string $email, string $password, string $name, Request $request, Response $response, Document $user, Document $project, Database $dbForProject, Event $queueForEvents, Hooks $hooks) { $email = \strtolower($email); if ('console' === $project->getId()) { @@ -117,6 +119,8 @@ App::post('/v1/account') } } + $hooks->trigger('passwordValidator', [$project, $password, $user]); + $passwordHistory = $project->getAttribute('auths', [])['passwordHistory'] ?? 0; $password = Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS); try { diff --git a/app/init.php b/app/init.php index eaea44e32f..c02f886d4a 100644 --- a/app/init.php +++ b/app/init.php @@ -72,6 +72,7 @@ use Ahc\Jwt\JWTException; use Appwrite\Event\Build; use Appwrite\Event\Certificate; use Appwrite\Event\Func; +use Appwrite\Hooks\Hooks; use MaxMind\Db\Reader; use PHPMailer\PHPMailer\PHPMailer; use Swoole\Database\PDOProxy; @@ -828,6 +829,9 @@ $register->set('passwordsDictionary', function () { $register->set('promiseAdapter', function () { return new Swoole(); }); +$register->set('hooks', function () { + return new Hooks(); +}); /* * Localization */ @@ -867,6 +871,10 @@ App::setResource('logger', function ($register) { return $register->get('logger'); }, ['register']); +App::setResource('hooks', function ($register) { + return $register->get('hooks'); +}, ['register']); + App::setResource('loggerBreadcrumbs', function () { return []; }); diff --git a/src/Appwrite/Hooks/Hooks.php b/src/Appwrite/Hooks/Hooks.php new file mode 100644 index 0000000000..03f5237fa5 --- /dev/null +++ b/src/Appwrite/Hooks/Hooks.php @@ -0,0 +1,26 @@ +