From 1903dc6b45016303de8ec8795e63915f4f2c804a Mon Sep 17 00:00:00 2001 From: iBNu Maksum Date: Mon, 4 Nov 2024 13:54:45 +0700 Subject: [PATCH] generate token --- system/autoload/User.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/system/autoload/User.php b/system/autoload/User.php index 732ff5ce..1acb8fc6 100644 --- a/system/autoload/User.php +++ b/system/autoload/User.php @@ -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'])