diff --git a/public_html/dispatch.php b/public_html/dispatch.php index 2458fc16..a523c004 100644 --- a/public_html/dispatch.php +++ b/public_html/dispatch.php @@ -146,6 +146,7 @@ $userValidations = \Chibi\Router::register(['UserController', 'flagAction'], 'POST', '/user/{name}/flag', $userValidations); \Chibi\Router::register(['UserController', 'banAction'], 'POST', '/user/{name}/ban', $userValidations); \Chibi\Router::register(['UserController', 'unbanAction'], 'POST', '/user/{name}/unban', $userValidations); +\Chibi\Router::register(['UserController', 'acceptRegistrationAction'], 'POST', '/user/{name}/accept-registration', $userValidations); foreach (['GET', 'POST'] as $method) { @@ -154,7 +155,6 @@ foreach (['GET', 'POST'] as $method) \Chibi\Router::register(['UserController', 'registrationAction'], $method, '/register', $userValidations); \Chibi\Router::register(['UserController', 'viewAction'], $method, '/user/{name}/{tab}', $userValidations); \Chibi\Router::register(['UserController', 'viewAction'], $method, '/user/{name}/{tab}/{page}', $userValidations); - \Chibi\Router::register(['UserController', 'acceptRegistrationAction'], $method, '/user/{name}/accept-registration', $userValidations); \Chibi\Router::register(['UserController', 'deleteAction'], $method, '/user/{name}/delete', $userValidations); \Chibi\Router::register(['UserController', 'settingsAction'], $method, '/user/{name}/settings', $userValidations); \Chibi\Router::register(['UserController', 'editAction'], $method, '/user/{name}/edit', $userValidations); diff --git a/src/Api/Jobs/AcceptUserRegistrationJob.php b/src/Api/Jobs/AcceptUserRegistrationJob.php new file mode 100644 index 00000000..5d75b1c2 --- /dev/null +++ b/src/Api/Jobs/AcceptUserRegistrationJob.php @@ -0,0 +1,20 @@ +user; + + $user->staffConfirmed = true; + UserModel::save($user); + + LogHelper::log('{user} confirmed {subject}\'s account', [ + 'user' => TextHelper::reprUser(Auth::getCurrentUser()), + 'subject' => TextHelper::reprUser($user)]); + } + + public function requiresPrivilege() + { + return Privilege::AcceptUserRegistration; + } +} diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index bf43c9eb..e6b47a1c 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -38,16 +38,8 @@ class UserController public function acceptRegistrationAction($name) { - $user = UserModel::findByNameOrEmail($name); - Access::assert( - Privilege::AcceptUserRegistration); - - if (!InputHelper::get('submit')) - return; - - $user->staffConfirmed = true; - UserModel::save($user); - LogHelper::log('{user} confirmed {subject}\'s account', ['subject' => TextHelper::reprUser($user)]); + Api::run(new AcceptUserRegistrationJob(), [ + AcceptUserRegistrationJob::USER_NAME => $name]); } public function deleteAction($name)