phpnuxbill/system/autoload/User.php

60 lines
1.5 KiB
PHP
Raw Normal View History

2017-03-11 03:51:06 +08:00
<?php
2023-06-15 16:26:38 +08:00
2017-03-11 03:51:06 +08:00
/**
2023-10-12 16:55:42 +08:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
2023-06-15 16:26:38 +08:00
**/
2017-03-11 03:51:06 +08:00
2023-10-12 16:55:42 +08:00
2023-06-15 16:26:38 +08:00
class User
{
2024-02-12 10:45:44 +08:00
public static function getID(){
global $db_password;
2024-02-26 15:38:04 +08:00
if(isset($_SESSION['uid']) && !empty($_SESSION['uid'])){
2024-02-12 10:45:44 +08:00
return $_SESSION['uid'];
}else if(isset($_COOKIE['uid'])){
// id.time.sha1
$tmp = explode('.',$_COOKIE['uid']);
2024-02-26 15:38:04 +08:00
if(sha1($tmp[0].'.'.$tmp[1].'.'.$db_password)==$tmp[2]){
if(time()-$tmp[1] < 86400*30){
2024-02-12 10:45:44 +08:00
$_SESSION['uid'] = $tmp[0];
return $tmp[0];
}
}
}
return 0;
}
public static function setCookie($uid){
global $db_password;
if(isset($uid)){
$time = time();
setcookie('uid', $uid.'.'.$time.'.'.sha1($uid.'.'.$time.'.'.$db_password), time()+86400*30);
}
}
public static function removeCookie(){
if(isset($_COOKIE['uid'])){
setcookie('uid', '', time()-86400);
}
}
2023-06-15 16:26:38 +08:00
public static function _info()
{
2024-02-12 10:45:44 +08:00
$id = User::getID();
2017-03-11 03:51:06 +08:00
$d = ORM::for_table('tbl_customers')->find_one($id);
if(empty($d['username'])){
r2(U . 'logout', 'd', '');
}
2017-03-11 03:51:06 +08:00
return $d;
}
2023-06-15 16:26:38 +08:00
public static function _billing()
{
2024-02-12 10:45:44 +08:00
$id = User::getID();
2023-11-15 12:39:05 +08:00
$d = ORM::for_table('tbl_user_recharges')->where('customer_id', $id)->find_many();
2017-03-11 03:51:06 +08:00
return $d;
}
2023-06-15 16:26:38 +08:00
}