You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.5 KiB
PHTML
66 lines
1.5 KiB
PHTML
4 years ago
|
<?php
|
||
|
use function _\find;
|
||
|
use ReallySimpleJWT\Token;
|
||
|
|
||
|
class Session
|
||
|
{
|
||
|
private static $file = "../content/.session";
|
||
|
private static $data = [
|
||
|
"member" => "",
|
||
|
"token" => "",
|
||
|
];
|
||
|
public static function start()
|
||
|
{
|
||
|
if (!is_file(self::$file)) {
|
||
|
file_put_contents(self::$file, json_encode(self::$data));
|
||
|
} else {
|
||
|
($new = fopen(self::$file, "w")) or die("Unable to open file!");
|
||
|
fwrite($new, json_encode(self::$data));
|
||
|
fclose($new);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static function active()
|
||
|
{
|
||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||
|
if ($data["member"] != null) {
|
||
|
$secret = (new Settings())->getFolks("secret");
|
||
|
if (
|
||
|
Token::validate($data["token"], $secret) &&
|
||
|
Token::validateExpiration($data["token"], $secret)
|
||
|
) {
|
||
|
true;
|
||
|
} else {
|
||
|
false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static function set($key, $value)
|
||
|
{
|
||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||
|
$data[$key] = $value;
|
||
|
($fresh = fopen(self::$file, "w")) or die("Unable to open file!");
|
||
|
fwrite($fresh, json_encode($data));
|
||
|
fclose($fresh);
|
||
|
}
|
||
|
|
||
|
public static function get($key)
|
||
|
{
|
||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||
|
|
||
|
return $data[$key];
|
||
|
}
|
||
|
|
||
|
public static function kill()
|
||
|
{
|
||
|
($fresh = fopen(self::$file, "w")) or die("Unable to open file!");
|
||
|
fwrite($fresh, json_encode(self::$data));
|
||
|
fclose($fresh);
|
||
|
}
|
||
|
}
|