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.
75 lines
1.7 KiB
PHP
75 lines
1.7 KiB
PHP
<?php
|
|
|
|
use function _\find;
|
|
use ReallySimpleJWT\Token;
|
|
|
|
class Auth
|
|
{
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public static function sessionStatus()
|
|
{
|
|
if (isset($_SESSION["member"])) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
//return $this->secret;
|
|
}
|
|
|
|
public static function status()
|
|
{
|
|
$result = "";
|
|
if (Session::active()) {
|
|
$result = true;
|
|
} else {
|
|
$result = false;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public static function login($who)
|
|
{
|
|
//grab member list
|
|
$folks = (new Settings())->getFolks();
|
|
$found = find($folks, ["handle" => $who["handle"]]);
|
|
|
|
if ($found) {
|
|
//name is found, verify password
|
|
if (password_verify($who["password"], $found["password"])) {
|
|
$member = [
|
|
"handle" => $found["handle"],
|
|
"email" => $found["email"],
|
|
"role" => $found["role"],
|
|
"avatar" => $found["avi"],
|
|
];
|
|
|
|
$token = Token::create(
|
|
$found["id"],
|
|
$found["secret"],
|
|
time() + 3600,
|
|
"localhost"
|
|
); //expires in an hour
|
|
Session::start();
|
|
Session::set("member", $member);
|
|
Session::set("token", $token);
|
|
|
|
$result = "good_login";
|
|
} else {
|
|
$result = "bad_pass";
|
|
}
|
|
} else {
|
|
//if name is not found
|
|
$result = "no_name";
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public static function logout()
|
|
{
|
|
Session::kill();
|
|
}
|
|
}
|