mirror of
https://github.com/kleeja-official/kleeja.git
synced 2025-12-15 20:49:41 +01:00
Refactor user class to store user information internally
This commit is contained in:
@@ -29,7 +29,9 @@ if (! $username)
|
|||||||
{
|
{
|
||||||
is_array($plugin_run_result = Plugins::getInstance()->run('user_not_admin_admin_page', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
is_array($plugin_run_result = Plugins::getInstance()->run('user_not_admin_admin_page', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
||||||
redirect(PATH . 'ucp.php?go=login&return=' . urlencode(ADMIN_PATH . '?cp=' . $go_to));
|
redirect(PATH . 'ucp.php?go=login&return=' . urlencode(ADMIN_PATH . '?cp=' . $go_to));
|
||||||
}else if(!user_can('enter_acp')){
|
}
|
||||||
|
elseif(! user_can('enter_acp'))
|
||||||
|
{
|
||||||
$usrcp->logout_cp();
|
$usrcp->logout_cp();
|
||||||
redirect($config['siteurl']);
|
redirect($config['siteurl']);
|
||||||
}
|
}
|
||||||
@@ -42,7 +44,7 @@ get_lang('acp');
|
|||||||
//
|
//
|
||||||
if (
|
if (
|
||||||
(empty($_SESSION['ADMINLOGIN']) || $_SESSION['ADMINLOGIN'] != md5(sha1($config['h_key']) . $usrcp->name() . $config['siteurl'])) ||
|
(empty($_SESSION['ADMINLOGIN']) || $_SESSION['ADMINLOGIN'] != md5(sha1($config['h_key']) . $usrcp->name() . $config['siteurl'])) ||
|
||||||
(empty($_SESSION['USER_SESS']) || $_SESSION['USER_SESS'] != KJ_SESSION) ||
|
(empty($_SESSION['USER_SESS']) || $_SESSION['USER_SESS'] != KJ_SESSION) ||
|
||||||
(empty($_SESSION['ADMINLOGIN_T']) || $_SESSION['ADMINLOGIN_T'] < time())
|
(empty($_SESSION['ADMINLOGIN_T']) || $_SESSION['ADMINLOGIN_T'] < time())
|
||||||
) {
|
) {
|
||||||
if (ig('go') && g('go') == 'login')
|
if (ig('go') && g('go') == 'login')
|
||||||
@@ -192,9 +194,9 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
(! defined('LAST_VISIT')) ? define('LAST_VISIT', time() - 3600 * 12) : null;
|
|
||||||
//last visit
|
//last visit
|
||||||
$last_visit = defined('LAST_VISIT') && preg_match('/[0-9]{10}/', LAST_VISIT) ? kleeja_date(LAST_VISIT) : false;
|
$last_visit = $usrcp->last_visit();
|
||||||
|
$last_visit = $last_visit && preg_match('/[0-9]{10}/', $last_visit) ? kleeja_date($last_visit) : false;
|
||||||
|
|
||||||
//
|
//
|
||||||
//exceptional
|
//exceptional
|
||||||
@@ -295,41 +297,41 @@ $adm_extensions_menu = $adm_topmenu = [];
|
|||||||
//sort the items as alphabetic !
|
//sort the items as alphabetic !
|
||||||
sort($adm_extensions);
|
sort($adm_extensions);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$cr_time = LAST_VISIT > 0 ? LAST_VISIT : time() - 3600*12;
|
$cr_time = $usrcp->last_visit() > 0 ? $usrcp->last_visit() : time() - 3600*12;
|
||||||
|
|
||||||
|
|
||||||
// check calls and reports numbers
|
// check calls and reports numbers
|
||||||
if (ig('check_msgs') || ! ig('_ajax_')):
|
if (ig('check_msgs') || ! ig('_ajax_')):
|
||||||
|
|
||||||
//small bubble system
|
//small bubble system
|
||||||
//any item can show what is inside it as unread messages
|
//any item can show what is inside it as unread messages
|
||||||
$kbubbles = [];
|
$kbubbles = [];
|
||||||
|
|
||||||
//for calls and reports
|
//for calls and reports
|
||||||
foreach (['call'=>'calls', 'reports'=>'reports'] as $table=>$n)
|
foreach (['call'=>'calls', 'reports'=>'reports'] as $table=>$n)
|
||||||
{
|
{
|
||||||
$query = [
|
$query = [
|
||||||
'SELECT' => 'COUNT(' . $table[0] . '.id) AS total_rows',
|
'SELECT' => 'COUNT(' . $table[0] . '.id) AS total_rows',
|
||||||
'FROM' => "`{$dbprefix}" . $table . '` ' . $table[0]
|
'FROM' => "`{$dbprefix}" . $table . '` ' . $table[0]
|
||||||
];
|
];
|
||||||
|
|
||||||
$fetched = $SQL->fetch_array($SQL->build($query));
|
$fetched = $SQL->fetch_array($SQL->build($query));
|
||||||
|
|
||||||
$kbubbles[$n] = $fetched['total_rows'];
|
$kbubbles[$n] = $fetched['total_rows'];
|
||||||
|
|
||||||
$SQL->freeresult();
|
$SQL->freeresult();
|
||||||
}
|
}
|
||||||
|
|
||||||
//if ajax, echo differntly
|
//if ajax, echo differntly
|
||||||
if (ig('check_msgs'))
|
if (ig('check_msgs'))
|
||||||
{
|
{
|
||||||
$SQL->close();
|
$SQL->close();
|
||||||
|
|
||||||
exit($kbubbles['calls'] . '::' . $kbubbles['reports']);
|
exit($kbubbles['calls'] . '::' . $kbubbles['reports']);
|
||||||
}
|
}
|
||||||
|
|
||||||
//add your own bubbles here
|
//add your own bubbles here
|
||||||
is_array($plugin_run_result = Plugins::getInstance()->run('kbubbles_admin_page', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
is_array($plugin_run_result = Plugins::getInstance()->run('kbubbles_admin_page', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
@@ -458,9 +460,10 @@ else
|
|||||||
{
|
{
|
||||||
$is_ajax = 'yes';
|
$is_ajax = 'yes';
|
||||||
|
|
||||||
echo_ajax(1,
|
echo_ajax(
|
||||||
empty($adminAjaxContent) ? $tpl->display($stylee, $styleePath) : $adminAjaxContent,
|
1,
|
||||||
$go_menu_html
|
empty($adminAjaxContent) ? $tpl->display($stylee, $styleePath) : $adminAjaxContent,
|
||||||
|
$go_menu_html
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ if (! defined('IN_COMMON')) {
|
|||||||
|
|
||||||
class usrcp
|
class usrcp
|
||||||
{
|
{
|
||||||
|
private $user_id = -1;
|
||||||
|
private $group_id = 2;
|
||||||
|
private $user_name = null;
|
||||||
|
private $user_mail = null;
|
||||||
|
private $last_visit = null;
|
||||||
|
|
||||||
public function data($name, $pass, $hashed = false, $expire = 86400, $loginadm = false)
|
public function data($name, $pass, $hashed = false, $expire = 86400, $loginadm = false)
|
||||||
{
|
{
|
||||||
//expire
|
//expire
|
||||||
@@ -57,8 +63,8 @@ class usrcp
|
|||||||
global $SQL, $dbprefix, $config, $userinfo;
|
global $SQL, $dbprefix, $config, $userinfo;
|
||||||
|
|
||||||
$userinfo = [
|
$userinfo = [
|
||||||
'id' => -1,
|
'id' => $this->user_id,
|
||||||
'group_id' => 2,
|
'group_id' => $this->group_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
$query = [
|
$query = [
|
||||||
@@ -117,6 +123,12 @@ class usrcp
|
|||||||
//all user fileds info
|
//all user fileds info
|
||||||
$userinfo = $row;
|
$userinfo = $row;
|
||||||
|
|
||||||
|
$this->user_id = $row['id'];
|
||||||
|
$this->group_id = $row['group_id'];
|
||||||
|
$this->user_name = $row['name'];
|
||||||
|
$this->user_mail = $row['mail'];
|
||||||
|
$this->last_visit = $row['last_visit'];
|
||||||
|
|
||||||
$user_y = base64_encode(serialize(['id'=>$row['id'], 'name'=>$row['name'], 'mail'=>$row['mail'], 'last_visit'=>$row['last_visit']]));
|
$user_y = base64_encode(serialize(['id'=>$row['id'], 'name'=>$row['name'], 'mail'=>$row['mail'], 'last_visit'=>$row['last_visit']]));
|
||||||
|
|
||||||
if (! $hashed && ! $loginadm) {
|
if (! $hashed && ! $loginadm) {
|
||||||
@@ -126,9 +138,10 @@ class usrcp
|
|||||||
|
|
||||||
//if last visit > 1 minute then update it
|
//if last visit > 1 minute then update it
|
||||||
if (empty($row['last_visit']) || time() - $row['last_visit'] > 60) {
|
if (empty($row['last_visit']) || time() - $row['last_visit'] > 60) {
|
||||||
|
$this->last_visit = time();
|
||||||
$update_last_visit = [
|
$update_last_visit = [
|
||||||
'UPDATE' => "{$dbprefix}users",
|
'UPDATE' => "{$dbprefix}users",
|
||||||
'SET' => 'last_visit=' . time(),
|
'SET' => 'last_visit=' . $this->last_visit,
|
||||||
'WHERE' => 'id=' . intval($row['id'])
|
'WHERE' => 'id=' . intval($row['id'])
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -142,9 +155,6 @@ class usrcp
|
|||||||
unset($pass);
|
unset($pass);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
//guest
|
|
||||||
define('USER_ID', $userinfo['id']);
|
|
||||||
define('GROUP_ID', $userinfo['group_id']);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,7 +192,7 @@ class usrcp
|
|||||||
{
|
{
|
||||||
is_array($plugin_run_result = Plugins::getInstance()->run('id_func_usr_class', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
is_array($plugin_run_result = Plugins::getInstance()->run('id_func_usr_class', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
||||||
|
|
||||||
return defined('USER_ID') ? USER_ID : false;
|
return $this->user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// group ids
|
// group ids
|
||||||
@@ -190,7 +200,7 @@ class usrcp
|
|||||||
{
|
{
|
||||||
is_array($plugin_run_result = Plugins::getInstance()->run('group_id_func_usr_class', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
is_array($plugin_run_result = Plugins::getInstance()->run('group_id_func_usr_class', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
||||||
|
|
||||||
return defined('GROUP_ID') ? GROUP_ID : false;
|
return $this->group_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// user name
|
// user name
|
||||||
@@ -198,7 +208,7 @@ class usrcp
|
|||||||
{
|
{
|
||||||
is_array($plugin_run_result = Plugins::getInstance()->run('name_func_usr_class', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
is_array($plugin_run_result = Plugins::getInstance()->run('name_func_usr_class', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
||||||
|
|
||||||
return defined('USER_NAME') ? USER_NAME : false;
|
return $this->user_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// user mail
|
// user mail
|
||||||
@@ -206,7 +216,15 @@ class usrcp
|
|||||||
{
|
{
|
||||||
is_array($plugin_run_result = Plugins::getInstance()->run('mail_func_usr_class', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
is_array($plugin_run_result = Plugins::getInstance()->run('mail_func_usr_class', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
||||||
|
|
||||||
return defined('USER_MAIL') ? USER_MAIL : false;
|
return $this->user_mail;
|
||||||
|
}
|
||||||
|
|
||||||
|
// last visit
|
||||||
|
public function last_visit()
|
||||||
|
{
|
||||||
|
is_array($plugin_run_result = Plugins::getInstance()->run('last_visit_func_usr_class', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
||||||
|
|
||||||
|
return $this->last_visit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// logout func
|
// logout func
|
||||||
@@ -219,6 +237,12 @@ class usrcp
|
|||||||
$this->logout_cp();
|
$this->logout_cp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->user_id = -1;
|
||||||
|
$this->group_id = 2;
|
||||||
|
$this->user_name = null;
|
||||||
|
$this->user_mail = null;
|
||||||
|
$this->last_visit = null;
|
||||||
|
|
||||||
//is ther any cookies
|
//is ther any cookies
|
||||||
$this->kleeja_set_cookie('ulogu', '', time() - 31536000);//31536000 = year
|
$this->kleeja_set_cookie('ulogu', '', time() - 31536000);//31536000 = year
|
||||||
|
|
||||||
@@ -376,8 +400,8 @@ class usrcp
|
|||||||
|
|
||||||
//to make sure
|
//to make sure
|
||||||
$userinfo = [
|
$userinfo = [
|
||||||
'id' => -1,
|
'id' => $this->user_id,
|
||||||
'group_id' => 2,
|
'group_id' => $this->group_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
//if login up
|
//if login up
|
||||||
@@ -399,19 +423,15 @@ class usrcp
|
|||||||
if ($user_data == false) {
|
if ($user_data == false) {
|
||||||
$this->logout();
|
$this->logout();
|
||||||
} else {
|
} else {
|
||||||
define('USER_ID', $userinfo['id']);
|
$this->user_id = $userinfo['id'];
|
||||||
define('GROUP_ID', $userinfo['group_id']);
|
$this->group_id = $userinfo['group_id'];
|
||||||
define('USER_NAME', $userinfo['name']);
|
$this->user_name = $userinfo['name'];
|
||||||
define('USER_MAIL', $userinfo['mail']);
|
$this->user_mail = $userinfo['mail'];
|
||||||
define('LAST_VISIT', $userinfo['last_visit']);
|
$this->last_visit = $userinfo['last_visit'];
|
||||||
return $user_data;
|
return $user_data;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//guest
|
|
||||||
define('USER_ID', $userinfo['id']);
|
|
||||||
define('GROUP_ID', $userinfo['group_id']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; //nothing
|
return false; //nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user