Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[user] be user_accounts #1369

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/private_image/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/user/config.php → ext/user_accounts/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions ext/user/info.php → ext/user_accounts/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 19 additions & 18 deletions ext/user/main.php → ext/user_accounts/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
Expand All @@ -119,30 +119,31 @@ 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()
);
}
}
}

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
Expand Down Expand Up @@ -174,15 +175,15 @@ 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;
}
$this->theme->display_signup_page($page);
}
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;
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]
);
}

Expand Down
2 changes: 1 addition & 1 deletion ext/user/test.php → ext/user_accounts/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Shimmie2;

class UserPageTest extends ShimmiePHPUnitTestCase
class UserAccountsTest extends ShimmiePHPUnitTestCase
{
public function testUserPage(): void
{
Expand Down
10 changes: 5 additions & 5 deletions ext/user/theme.php → ext/user_accounts/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
);

Expand Down Expand Up @@ -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")));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", false));
$userPage->onUserCreation(new UserCreationEvent("test", "test", "test", "[email protected]", false));
// in mysql, CREATE TABLE commits transactions, so after the database
Expand Down
2 changes: 1 addition & 1 deletion themes/danbooru/user.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use function MicroHTML\rawHTML;

class DanbooruUserPageTheme extends UserPageTheme
class DanbooruUserAccountsTheme extends UserAccountsTheme
{
public function display_login_page(Page $page): void
{
Expand Down
2 changes: 1 addition & 1 deletion themes/danbooru2/user.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use function MicroHTML\rawHTML;

class Danbooru2UserPageTheme extends UserPageTheme
class Danbooru2UserAccountsTheme extends UserAccountsTheme
{
public function display_login_page(Page $page): void
{
Expand Down
2 changes: 1 addition & 1 deletion themes/lite/user.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use function MicroHTML\rawHTML;

class LiteUserPageTheme extends UserPageTheme
class LiteUserAccountsTheme extends UserAccountsTheme
{
public function display_login_page(Page $page): void
{
Expand Down
2 changes: 1 addition & 1 deletion themes/warm/user.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use function MicroHTML\rawHTML;

class WarmUserPageTheme extends UserPageTheme
class WarmUserAccountsTheme extends UserAccountsTheme
{
/**
* @param array<array{link: string, name: string}> $parts
Expand Down
Loading