mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-05 17:51:40 +09:00
Move login status calculation to its own method and add API in member module
This commit is contained in:
parent
a0f895a02f
commit
0cc1246898
3 changed files with 33 additions and 12 deletions
|
|
@ -305,18 +305,8 @@ class Session
|
|||
*/
|
||||
public static function checkLoginStatusCookie()
|
||||
{
|
||||
// Members are identified by a hash of member_srl. Guests are identified as 'none'.
|
||||
if (isset($_SESSION['RHYMIX']) && $_SESSION['RHYMIX']['login'])
|
||||
{
|
||||
$data = sprintf('%s:%s:%d:%s', $_SERVER['HTTP_HOST'] ?? '', RX_BASEDIR, $_SESSION['RHYMIX']['login'], config('crypto.session_key'));
|
||||
$value = base64_encode_urlsafe(substr(hash('sha256', $data, true), 0, 18));
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = 'none';
|
||||
}
|
||||
|
||||
// If the cookie value is different from the current value, overwrite it.
|
||||
// If the cookie value is different from the current login status, overwrite it.
|
||||
$value = self::getLoginStatus();
|
||||
if (!isset($_COOKIE['rx_login_status']) || $_COOKIE['rx_login_status'] !== $value)
|
||||
{
|
||||
list($lifetime, $refresh_interval, $domain, $path, $secure, $samesite) = self::_getParams();
|
||||
|
|
@ -1003,6 +993,27 @@ class Session
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string that identifies login status.
|
||||
*
|
||||
* Members are identified by a hash that is unique to each member.
|
||||
* Guests are identified as 'none'.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getLoginStatus()
|
||||
{
|
||||
if (isset($_SESSION['RHYMIX']) && $_SESSION['RHYMIX']['login'])
|
||||
{
|
||||
$data = sprintf('%s:%s:%d:%s', $_SERVER['HTTP_HOST'] ?? '', RX_BASEDIR, $_SESSION['RHYMIX']['login'], config('crypto.session_key'));
|
||||
return base64_encode_urlsafe(substr(hash('sha256', $data, true), 0, 18));
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'none';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get validity information.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
<action name="dispMemberLogout" type="view" meta-noindex="true" />
|
||||
<action name="dispMemberSpammer" type="view" permission="manager" check_var="module_srl" meta-noindex="true" />
|
||||
|
||||
<action name="getLoginStatus" type="model" meta-noindex="true" />
|
||||
<action name="getMemberMenu" type="model" />
|
||||
<action name="getApiGroups" type="model" permission="root" />
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,15 @@ class memberModel extends member
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display login status as JSON API
|
||||
*/
|
||||
public function getLoginStatus()
|
||||
{
|
||||
Context::setResponseMethod('JSON');
|
||||
$this->add('status', Rhymix\Framework\Session::getLoginStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Display menus of the member
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue