generate token

This commit is contained in:
iBNu Maksum 2024-11-04 13:54:45 +07:00
parent 27bd2590f2
commit 1903dc6b45
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5

View File

@ -157,12 +157,25 @@ class User
return [];
}
public static function generateToken($uid)
{
global $db_pass;
$time = time();
return [
'time' => $time,
'token' => $uid . '.' . $time . '.' . sha1($uid . '.' . $time . '.' . $db_pass)
];
}
public static function setCookie($uid)
{
global $db_pass;
if (isset($uid)) {
$time = time();
setcookie('uid', $uid . '.' . $time . '.' . sha1($uid . '.' . $time . '.' . $db_pass), time() + 86400 * 30);
list($time, $token) = self::generateToken($uid);
setcookie('uid', $token, time() + 86400 * 30);
return $token;
} else {
return false;
}
}
@ -210,7 +223,8 @@ class User
return $d;
}
public static function isUserVoucher($kode) {
public static function isUserVoucher($kode)
{
$regex = '/^GC\d+C.{10}$/';
return preg_match($regex, $kode);
}
@ -223,11 +237,21 @@ class User
$d = ORM::for_table('tbl_user_recharges')
->select('tbl_user_recharges.id', 'id')
->selects([
'customer_id', 'username', 'plan_id', 'namebp', 'recharged_on', 'recharged_time', 'expiration', 'time',
'status', 'method', 'plan_type',
'customer_id',
'username',
'plan_id',
'namebp',
'recharged_on',
'recharged_time',
'expiration',
'time',
'status',
'method',
'plan_type',
['tbl_user_recharges.routers', 'routers'],
['tbl_user_recharges.type', 'type'],
'admin_id', 'prepaid'
'admin_id',
'prepaid'
])
->left_outer_join('tbl_plans', ['tbl_plans.id', '=', 'tbl_user_recharges.plan_id'])
->left_outer_join('tbl_bandwidth', ['tbl_bandwidth.id', '=', 'tbl_plans.id_bw'])