diff --git a/system/autoload/Admin.php b/system/autoload/Admin.php new file mode 100644 index 0000000..c39ee81 --- /dev/null +++ b/system/autoload/Admin.php @@ -0,0 +1,61 @@ +find_one($id); + } else { + return null; + } + } +} diff --git a/system/autoload/App.php b/system/autoload/App.php new file mode 100644 index 0000000..71f1614 --- /dev/null +++ b/system/autoload/App.php @@ -0,0 +1,29 @@ +where('id', $id_customer)->find_one(); + $c->balance = $amount + $c['balance']; + $c->save(); + } + + public static function transfer($id_customer, $phoneTarget, $amount) + { + global $config; + if (Balance::min($id_customer, $amount)) { + return Balance::plusByPhone($phoneTarget, $amount); + } else { + return false; + } + } + + public static function min($id_customer, $amount) + { + $c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one(); + if ($c && $c['balance'] >= $amount) { + $c->balance = $c['balance'] - $amount; + $c->save(); + return true; + } else { + return false; + } + } + + public static function plusByPhone($phone_customer, $amount) + { + $c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one(); + if ($c) { + $c->balance = $amount + $c['balance']; + $c->save(); + return true; + } + return false; + } + + public static function minByPhone($phone_customer, $amount) + { + $c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one(); + if ($c && $c['balance'] >= $amount) { + $c->balance = $c['balance'] - $amount; + $c->save(); + return true; + } else { + return false; + } + } +} diff --git a/system/autoload/Csrf.php b/system/autoload/Csrf.php new file mode 100644 index 0000000..57752a0 --- /dev/null +++ b/system/autoload/Csrf.php @@ -0,0 +1,55 @@ + self::$tokenExpiration) { + self::clearToken(); + return false; + } + + return self::validateToken($token, $storedToken); + } + return false; + } + return true; + } + + public static function generateAndStoreToken() + { + $token = self::generateToken(); + $_SESSION['csrf_token'] = $token; + $_SESSION['csrf_token_time'] = time(); + return $token; + } + + public static function clearToken() + { + unset($_SESSION['csrf_token'], $_SESSION['csrf_token_time']); + } +} diff --git a/system/autoload/File.php b/system/autoload/File.php new file mode 100644 index 0000000..156d7be --- /dev/null +++ b/system/autoload/File.php @@ -0,0 +1,108 @@ +