Rewrote the user information class.
This one took multiple days and it pretty invasive into the core of Misuzu so issue might (will) arise, there's also some features that have gone temporarily missing in the mean time and some inefficiencies introduced that will be fixed again at a later time. The old class isn't gone entirely because I still have to figure out what I'm gonna do about validation, but for the most part this knocks out one of the "layers of backwards compatibility", as I've been referring to it, and is moving us closer to a future where Flashii actually gets real updates. If you run into anything that's broken and you're inhibited from reporting it through the forum, do it through chat or mail me at flashii-issues@flash.moe.
This commit is contained in:
parent
99353c4e70
commit
e000c21987
119 changed files with 1992 additions and 1816 deletions
public
|
@ -2,7 +2,6 @@
|
|||
namespace Misuzu;
|
||||
|
||||
use RuntimeException;
|
||||
use Misuzu\Users\User;
|
||||
|
||||
require_once __DIR__ . '/../misuzu.php';
|
||||
|
||||
|
@ -50,7 +49,6 @@ $globals = $cfg->getValues([
|
|||
['site.name:s', 'Misuzu'],
|
||||
'site.desc:s',
|
||||
'site.url:s',
|
||||
'sockChat.chatPath.normal:s',
|
||||
'eeprom.path:s',
|
||||
'eeprom.app:s',
|
||||
['auth.secret:s', 'meow'],
|
||||
|
@ -63,7 +61,6 @@ Template::set('globals', [
|
|||
'site_name' => $globals['site.name'],
|
||||
'site_description' => $globals['site.desc'],
|
||||
'site_url' => $globals['site.url'],
|
||||
'site_chat' => $globals['sockChat.chatPath.normal'],
|
||||
'eeprom' => [
|
||||
'path' => $globals['eeprom.path'],
|
||||
'app' => $globals['eeprom.app'],
|
||||
|
@ -81,7 +78,7 @@ AuthToken::setSecretKey($globals['auth.secret']);
|
|||
|
||||
if(isset($_COOKIE['msz_uid']) && isset($_COOKIE['msz_sid'])) {
|
||||
$authToken = new AuthToken;
|
||||
$authToken->setUserId(filter_input(INPUT_COOKIE, 'msz_uid', FILTER_SANITIZE_NUMBER_INT) ?? 0);
|
||||
$authToken->setUserId(filter_input(INPUT_COOKIE, 'msz_uid', FILTER_SANITIZE_NUMBER_INT) ?? '0');
|
||||
$authToken->setSessionToken(filter_input(INPUT_COOKIE, 'msz_sid') ?? '');
|
||||
|
||||
if($authToken->isValid())
|
||||
|
@ -93,27 +90,26 @@ if(isset($_COOKIE['msz_uid']) && isset($_COOKIE['msz_sid'])) {
|
|||
if(!isset($authToken))
|
||||
$authToken = AuthToken::unpack(filter_input(INPUT_COOKIE, 'msz_auth') ?? '');
|
||||
|
||||
if($authToken->isValid()) {
|
||||
$sessions = $msz->getSessions();
|
||||
$authToken->setCurrent();
|
||||
$users = $msz->getUsers();
|
||||
$sessions = $msz->getSessions();
|
||||
|
||||
if($authToken->isValid()) {
|
||||
try {
|
||||
$sessionInfo = $sessions->getSession(sessionToken: $authToken->getSessionToken());
|
||||
|
||||
if($sessionInfo->hasExpired()) {
|
||||
$sessions->deleteSessions(sessionInfos: $sessionInfo);
|
||||
} elseif($sessionInfo->getUserId() === (string)$authToken->getUserId()) {
|
||||
$userInfo = User::byId((int)$sessionInfo->getUserId());
|
||||
} elseif($sessionInfo->getUserId() === $authToken->getUserId()) {
|
||||
$userInfo = $users->getUser($authToken->getUserId(), 'id');
|
||||
|
||||
if(!$userInfo->isDeleted()) {
|
||||
$userInfo->setCurrent();
|
||||
$userInfo->bumpActivity($_SERVER['REMOTE_ADDR']);
|
||||
$sessions->updateSession(sessionInfo: $sessionInfo, remoteAddr: $_SERVER['REMOTE_ADDR']);
|
||||
$users->recordUserActivity($userInfo, remoteAddr: $_SERVER['REMOTE_ADDR']);
|
||||
$sessions->recordSessionActivity(sessionInfo: $sessionInfo, remoteAddr: $_SERVER['REMOTE_ADDR']);
|
||||
if($sessionInfo->shouldBumpExpires())
|
||||
$authToken->applyCookie($sessionInfo->getExpiresTime());
|
||||
|
||||
if($authToken->hasImpersonatedUserId()) {
|
||||
$allowToImpersonate = $userInfo->isSuper();
|
||||
$allowToImpersonate = $userInfo->isSuperUser();
|
||||
$impersonatedUserId = $authToken->getImpersonatedUserId();
|
||||
|
||||
if(!$allowToImpersonate) {
|
||||
|
@ -126,13 +122,11 @@ if($authToken->isValid()) {
|
|||
$userInfoReal = $userInfo;
|
||||
|
||||
try {
|
||||
$userInfo = User::byId($impersonatedUserId);
|
||||
$userInfo = $users->getUser($impersonatedUserId, 'id');
|
||||
} catch(RuntimeException $ex) {
|
||||
$userInfo = $userInfoReal;
|
||||
$removeImpersonationData = true;
|
||||
}
|
||||
|
||||
$userInfo->setCurrent();
|
||||
}
|
||||
|
||||
if($removeImpersonationData) {
|
||||
|
@ -140,46 +134,51 @@ if($authToken->isValid()) {
|
|||
$authToken->applyCookie();
|
||||
}
|
||||
}
|
||||
|
||||
$msz->setAuthInfo($authToken, $userInfo, $userInfoReal ?? null);
|
||||
}
|
||||
}
|
||||
} catch(RuntimeException $ex) {
|
||||
User::unsetCurrent();
|
||||
}
|
||||
|
||||
if(!User::hasCurrent())
|
||||
AuthToken::nukeCookie();
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($userInfo))
|
||||
$userInfo = $users->getUser((string)$userInfo->getId(), 'id');
|
||||
if(!empty($userInfoReal))
|
||||
$userInfoReal = $users->getUser((string)$userInfoReal->getId(), 'id');
|
||||
|
||||
CSRF::init(
|
||||
$globals['csrf.secret'],
|
||||
(User::hasCurrent() ? $authToken->getSessionToken() : $_SERVER['REMOTE_ADDR'])
|
||||
($msz->isLoggedIn() ? $authToken->getSessionToken() : $_SERVER['REMOTE_ADDR'])
|
||||
);
|
||||
|
||||
if(!empty($userInfo)) {
|
||||
Template::set('current_user', $userInfo);
|
||||
Template::set('current_user_ban_info', $msz->tryGetActiveBan());
|
||||
}
|
||||
if(!empty($userInfoReal))
|
||||
|
||||
if(!empty($userInfoReal)) {
|
||||
Template::set('current_user_real', $userInfoReal);
|
||||
Template::set('current_user_real_colour', $users->getUserColour($userInfoReal));
|
||||
}
|
||||
|
||||
$inManageMode = str_starts_with($_SERVER['REQUEST_URI'], '/manage');
|
||||
$hasManageAccess = User::hasCurrent()
|
||||
&& !$msz->hasActiveBan()
|
||||
&& perms_check_user(MSZ_PERMS_GENERAL, User::getCurrent()->getId(), MSZ_PERM_GENERAL_CAN_MANAGE);
|
||||
Template::set('has_manage_access', $hasManageAccess);
|
||||
|
||||
$canViewForumLeaderboard = User::hasCurrent()
|
||||
&& !$msz->hasActiveBan()
|
||||
&& perms_check_user(MSZ_PERMS_GENERAL, User::getCurrent()->getId(), MSZ_PERM_FORUM_VIEW_LEADERBOARD);
|
||||
Template::set('can_view_forum_leaderboard', $canViewForumLeaderboard);
|
||||
Template::set('header_menu', $msz->getHeaderMenu($userInfo ?? null));
|
||||
Template::set('user_menu', $msz->getUserMenu($userInfo ?? null, $inManageMode));
|
||||
Template::set('display_debug_info', MSZ_DEBUG || (!empty($userInfo) && $userInfo->isSuperUser()));
|
||||
|
||||
if($inManageMode) {
|
||||
$hasManageAccess = $msz->isLoggedIn() && !$msz->hasActiveBan()
|
||||
&& perms_check_user(MSZ_PERMS_GENERAL, $msz->getActiveUser()->getId(), MSZ_PERM_GENERAL_CAN_MANAGE);
|
||||
|
||||
if(!$hasManageAccess) {
|
||||
echo render_error(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
Template::set('manage_menu', manage_get_menu(User::getCurrent()->getId()));
|
||||
Template::set('manage_menu', manage_get_menu($userInfo->getId()));
|
||||
}
|
||||
|
||||
$mszRequestPath = $request->getPath();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue