diff --git a/app/Controllers/Settings/AdvancedController.php b/app/Controllers/Settings/AdvancedController.php index 1e74c9e..4e36b8d 100644 --- a/app/Controllers/Settings/AdvancedController.php +++ b/app/Controllers/Settings/AdvancedController.php @@ -63,29 +63,26 @@ class AdvancedController extends Controller public function deactivate(): string { if (!CurrentSession::$user->perms->deactivateAccount) { - throw new HttpMethodNotAllowedException(); + throw new HttpMethodNotAllowedException; } $password = $_POST['password'] ?? null; - if (session_check() && $password) { - $redirect = route('settings.advanced.deactivate'); - - // Check password - if (!CurrentSession::$user->verifyPassword($password)) { - $message = "Your password was invalid!"; - return view('global/information', compact('message', 'redirect')); + if (session_check()) { + if (!$password || strlen($password) < 1 || !CurrentSession::$user->verifyPassword($password)) { + return $this->json(['error' => 'Incorrect password!']); } // Deactivate account - CurrentSession::$user->removeRanks(array_keys(CurrentSession::$user->ranks)); - CurrentSession::$user->addRanks([1]); - CurrentSession::$user->setMainRank(1); + DB::table('users') + ->where('user_id', CurrentSession::$user->id) + ->update(['user_activated' => 0]); // Destroy all active sessions CurrentSession::$user->purgeSessions(); - return view('settings/advanced/deactivate_bye'); + // should probably not use the error var for the farewell msg but w/e + return $this->json(['error' => 'Farewell!', 'go' => route('main.index')]); } return view('settings/advanced/deactivate'); diff --git a/app/User.php b/app/User.php index fdfe096..e11a41e 100644 --- a/app/User.php +++ b/app/User.php @@ -286,6 +286,7 @@ class User * @param string $username * @param string $password * @param string $email + * @param bool $active * @param array $ranks * @return User */ diff --git a/resources/views/yuuno/settings/advanced/deactivate.twig b/resources/views/yuuno/settings/advanced/deactivate.twig index aa86cb3..03953a3 100644 --- a/resources/views/yuuno/settings/advanced/deactivate.twig +++ b/resources/views/yuuno/settings/advanced/deactivate.twig @@ -9,14 +9,63 @@

You can reactivate your account by logging in within 30 days, after that period your account will be removed.

{% endblock %} +{% block js %} + +{% endblock %} + {% block settingsContent %} -
+ +

Enter your password to continue

- +
{% endblock %}