diff --git a/ext/private_image/main.php b/ext/private_image/main.php index 8a73476b7..5b1efbcdb 100644 --- a/ext/private_image/main.php +++ b/ext/private_image/main.php @@ -130,7 +130,7 @@ public function onSearchTermParse(SearchTermParseEvent $event): void // Admins can view others private images, but they have to specify the user if (!$user->can(Permissions::SET_OTHERS_PRIVATE_IMAGES) || - !UserPage::has_user_query($event->context)) { + !UserAccounts::has_user_query($event->context)) { $query .= " AND owner_id = :private_owner_id"; $params["private_owner_id"] = $user->id; } diff --git a/ext/user/config.php b/ext/user_accounts/config.php similarity index 93% rename from ext/user/config.php rename to ext/user_accounts/config.php index 6c38d8519..1c929ab74 100644 --- a/ext/user/config.php +++ b/ext/user_accounts/config.php @@ -4,7 +4,7 @@ namespace Shimmie2; -class UserPageConfig extends ConfigGroup +class UserAccountsConfig extends ConfigGroup { public const ANON_ID = "anon_id"; public const SIGNUP_ENABLED = "login_signup_enabled"; diff --git a/ext/user/events.php b/ext/user_accounts/events.php similarity index 100% rename from ext/user/events.php rename to ext/user_accounts/events.php diff --git a/ext/user/info.php b/ext/user_accounts/info.php similarity index 80% rename from ext/user/info.php rename to ext/user_accounts/info.php index 81d33e9a3..e91b2fb3e 100644 --- a/ext/user/info.php +++ b/ext/user_accounts/info.php @@ -4,12 +4,12 @@ namespace Shimmie2; -class UserPageInfo extends ExtensionInfo +class UserAccountsInfo extends ExtensionInfo { public const KEY = "user"; public string $key = self::KEY; - public string $name = "User Management"; + public string $name = "User Accounts"; public array $authors = self::SHISH_AUTHOR; public string $description = "Allows people to sign up to the website"; public bool $core = true; diff --git a/ext/user/main.php b/ext/user_accounts/main.php similarity index 95% rename from ext/user/main.php rename to ext/user_accounts/main.php index 91b55ad2c..a110d96ab 100644 --- a/ext/user/main.php +++ b/ext/user_accounts/main.php @@ -99,7 +99,7 @@ public static function login(string $username, string $password): LoginResult ); } catch (UserNotFound $ex) { return new LoginResult( - User::by_id($config->get_int(UserPageConfig::ANON_ID, 0)), + User::by_id($config->get_int(UserAccountsConfig::ANON_ID, 0)), null, "No user found" ); @@ -119,7 +119,7 @@ public static function create_user(string $username, string $password1, string $ ); } catch (UserCreationException $ex) { return new LoginResult( - User::by_id($config->get_int(UserPageConfig::ANON_ID, 0)), + User::by_id($config->get_int(UserAccountsConfig::ANON_ID, 0)), null, $ex->getMessage() ); @@ -127,22 +127,23 @@ public static function create_user(string $username, string $password1, string $ } } -class UserPage extends Extension +class UserAccounts extends Extension { - /** @var UserPageTheme $theme */ + /** @var UserAccountsTheme $theme */ public Themelet $theme; public function onInitExt(InitExtEvent $event): void { global $config; - $config->set_default_bool(UserPageConfig::SIGNUP_ENABLED, true); - $config->set_default_int(UserPageConfig::LOGIN_MEMORY, 365); + $config->set_default_bool(UserAccountsConfig::SIGNUP_ENABLED, true); + $config->set_default_int(UserAccountsConfig::LOGIN_MEMORY, 365); + $config->set_default_bool(UserAccountsConfig::LOGIN_TAC_BBCODE, true); + $config->set_default_bool(UserAccountsConfig::USER_EMAIL_REQUIRED, false); + $config->set_default_string(AvatarConfig::HOST, "none"); $config->set_default_int(AvatarConfig::GRAVATAR_SIZE, 80); $config->set_default_string(AvatarConfig::GRAVATAR_DEFAULT, ""); $config->set_default_string(AvatarConfig::GRAVATAR_RATING, "g"); - $config->set_default_bool(UserPageConfig::LOGIN_TAC_BBCODE, true); - $config->set_default_bool(UserPageConfig::USER_EMAIL_REQUIRED, false); } public function onUserLogin(UserLoginEvent $event): void @@ -174,7 +175,7 @@ public function onPageRequest(PageRequestEvent $event): void } if ($event->page_matches("user_admin/create", method: "GET", permission: Permissions::CREATE_USER)) { global $config, $page, $user; - if (!$config->get_bool(UserPageConfig::SIGNUP_ENABLED)) { + if (!$config->get_bool(UserAccountsConfig::SIGNUP_ENABLED)) { $this->theme->display_signups_disabled($page); return; } @@ -182,7 +183,7 @@ public function onPageRequest(PageRequestEvent $event): void } if ($event->page_matches("user_admin/create", method: "POST", authed: false, permission: Permissions::CREATE_USER)) { global $config, $page, $user; - if (!$config->get_bool(UserPageConfig::SIGNUP_ENABLED)) { + if (!$config->get_bool(UserAccountsConfig::SIGNUP_ENABLED)) { $this->theme->display_signups_disabled($page); return; } @@ -312,7 +313,7 @@ public function onPageRequest(PageRequestEvent $event): void if ($event->page_matches("user/{name}")) { $display_user = User::by_name($event->get_arg('name')); - if ($display_user->id == $config->get_int(UserPageConfig::ANON_ID)) { + if ($display_user->id == $config->get_int(UserAccountsConfig::ANON_ID)) { throw new UserNotFound("No such user"); } $e = send_event(new UserPageBuildingEvent($display_user)); @@ -414,8 +415,8 @@ public function onSetupBuilding(SetupBuildingEvent $event): void $sb = $event->panel->create_new_block("User Options"); $sb->start_table(); $sb->add_bool_option(UserConfig::ENABLE_API_KEYS, "Enable user API keys", true); - $sb->add_bool_option(UserPageConfig::SIGNUP_ENABLED, "Allow new signups", true); - $sb->add_bool_option(UserPageConfig::USER_EMAIL_REQUIRED, "Require email address", true); + $sb->add_bool_option(UserAccountsConfig::SIGNUP_ENABLED, "Allow new signups", true); + $sb->add_bool_option(UserAccountsConfig::USER_EMAIL_REQUIRED, "Require email address", true); $sb->add_longtext_option("login_tac", "Terms & Conditions", true); $sb->add_choice_option( "user_loginshowprofile", @@ -502,7 +503,7 @@ public function onUserCreation(UserCreationEvent $event): void if (!$user->can(Permissions::CREATE_USER)) { throw new UserCreationException("Account creation is currently disabled"); } - if (!$config->get_bool(UserPageConfig::SIGNUP_ENABLED) && !$user->can(Permissions::CREATE_OTHER_USER)) { + if (!$config->get_bool(UserAccountsConfig::SIGNUP_ENABLED) && !$user->can(Permissions::CREATE_OTHER_USER)) { throw new UserCreationException("Account creation is currently disabled"); } if (strlen($name) < 1) { @@ -530,7 +531,7 @@ public function onUserCreation(UserCreationEvent $event): void // Users who can create other users (ie, admins) are exempt // from the email requirement !$user->can(Permissions::CREATE_OTHER_USER) && - ($config->get_bool(UserPageConfig::USER_EMAIL_REQUIRED) && empty($event->email)) + ($config->get_bool(UserAccountsConfig::USER_EMAIL_REQUIRED) && empty($event->email)) ) { throw new UserCreationException("Email address is required"); } @@ -630,11 +631,11 @@ private function page_login(string $name, string $pass): void private function page_logout(): void { global $page, $config; - $page->add_cookie("session", "", time() + 60 * 60 * 24 * $config->get_int(UserPageConfig::LOGIN_MEMORY), "/"); + $page->add_cookie("session", "", time() + 60 * 60 * 24 * $config->get_int(UserAccountsConfig::LOGIN_MEMORY), "/"); if (Extension::is_enabled(SpeedHaxInfo::KEY) && $config->get_bool(SpeedHaxConfig::PURGE_COOKIE)) { # to keep as few versions of content as possible, # make cookies all-or-nothing - $page->add_cookie("user", "", time() + 60 * 60 * 24 * $config->get_int(UserPageConfig::LOGIN_MEMORY), "/"); + $page->add_cookie("user", "", time() + 60 * 60 * 24 * $config->get_int(UserAccountsConfig::LOGIN_MEMORY), "/"); } log_info("user", "Logged out"); $page->set_mode(PageMode::REDIRECT); @@ -760,7 +761,7 @@ private function delete_user(Page $page, int $uid, bool $with_images = false, bo } else { $database->execute( "UPDATE images SET owner_id = :new_owner_id WHERE owner_id = :old_owner_id", - ["new_owner_id" => $config->get_int(UserPageConfig::ANON_ID), "old_owner_id" => $uid] + ["new_owner_id" => $config->get_int(UserAccountsConfig::ANON_ID), "old_owner_id" => $uid] ); } diff --git a/ext/user/test.php b/ext/user_accounts/test.php similarity index 97% rename from ext/user/test.php rename to ext/user_accounts/test.php index 7a56b73b1..1d378769c 100644 --- a/ext/user/test.php +++ b/ext/user_accounts/test.php @@ -4,7 +4,7 @@ namespace Shimmie2; -class UserPageTest extends ShimmiePHPUnitTestCase +class UserAccountsTest extends ShimmiePHPUnitTestCase { public function testUserPage(): void { diff --git a/ext/user/theme.php b/ext/user_accounts/theme.php similarity index 97% rename from ext/user/theme.php rename to ext/user_accounts/theme.php index d2dccc0d6..9befe8e77 100644 --- a/ext/user/theme.php +++ b/ext/user_accounts/theme.php @@ -23,7 +23,7 @@ use function MicroHTML\SELECT; use function MicroHTML\OPTION; -class UserPageTheme extends Themelet +class UserAccountsTheme extends Themelet { public function display_login_page(Page $page): void { @@ -61,14 +61,14 @@ public function display_user_block(Page $page, User $user, array $parts): void public function display_signup_page(Page $page): void { global $config, $user; - $tac = $config->get_string(UserPageConfig::LOGIN_TAC, ""); + $tac = $config->get_string(UserAccountsConfig::LOGIN_TAC, ""); - if ($config->get_bool(UserPageConfig::LOGIN_TAC_BBCODE)) { + if ($config->get_bool(UserAccountsConfig::LOGIN_TAC_BBCODE)) { $tac = format_text($tac); } $email_required = ( - $config->get_bool(UserPageConfig::USER_EMAIL_REQUIRED) && + $config->get_bool(UserAccountsConfig::USER_EMAIL_REQUIRED) && !$user->can(Permissions::CREATE_OTHER_USER) ); @@ -190,7 +190,7 @@ public function create_login_block(): HTMLElement $html = emptyHTML(); $html->appendChild($form); - if ($config->get_bool(UserPageConfig::SIGNUP_ENABLED) && $user->can(Permissions::CREATE_USER)) { + if ($config->get_bool(UserAccountsConfig::SIGNUP_ENABLED) && $user->can(Permissions::CREATE_USER)) { $html->appendChild(SMALL(A(["href" => make_link("user_admin/create")], "Create Account"))); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 946db05b4..f494e6db6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -48,7 +48,7 @@ send_event(new DatabaseUpgradeEvent()); send_event(new InitExtEvent()); $user = User::by_id($config->get_int("anon_id", 0)); -$userPage = new UserPage(); +$userPage = new UserAccounts(); $userPage->onUserCreation(new UserCreationEvent("demo", "demo", "demo", "demo@demo.com", false)); $userPage->onUserCreation(new UserCreationEvent("test", "test", "test", "test@test.com", false)); // in mysql, CREATE TABLE commits transactions, so after the database diff --git a/themes/danbooru/user.theme.php b/themes/danbooru/user.theme.php index 30ba30bfd..e06da3995 100644 --- a/themes/danbooru/user.theme.php +++ b/themes/danbooru/user.theme.php @@ -6,7 +6,7 @@ use function MicroHTML\rawHTML; -class DanbooruUserPageTheme extends UserPageTheme +class DanbooruUserAccountsTheme extends UserAccountsTheme { public function display_login_page(Page $page): void { diff --git a/themes/danbooru2/user.theme.php b/themes/danbooru2/user.theme.php index 346866803..d29477e92 100644 --- a/themes/danbooru2/user.theme.php +++ b/themes/danbooru2/user.theme.php @@ -6,7 +6,7 @@ use function MicroHTML\rawHTML; -class Danbooru2UserPageTheme extends UserPageTheme +class Danbooru2UserAccountsTheme extends UserAccountsTheme { public function display_login_page(Page $page): void { diff --git a/themes/lite/user.theme.php b/themes/lite/user.theme.php index 9e251286f..64d5f96dc 100644 --- a/themes/lite/user.theme.php +++ b/themes/lite/user.theme.php @@ -6,7 +6,7 @@ use function MicroHTML\rawHTML; -class LiteUserPageTheme extends UserPageTheme +class LiteUserAccountsTheme extends UserAccountsTheme { public function display_login_page(Page $page): void { diff --git a/themes/warm/user.theme.php b/themes/warm/user.theme.php index f4cb59970..d4860af92 100644 --- a/themes/warm/user.theme.php +++ b/themes/warm/user.theme.php @@ -6,7 +6,7 @@ use function MicroHTML\rawHTML; -class WarmUserPageTheme extends UserPageTheme +class WarmUserAccountsTheme extends UserAccountsTheme { /** * @param array $parts