moved member auth to API class

This commit is contained in:
Ro 2021-04-16 20:50:03 -07:00
parent 179f007fab
commit 20cc4abad9
3 changed files with 73 additions and 31 deletions

View file

@ -0,0 +1,63 @@
<?php
class AuthAPI
{
public function __construct()
{
}
public static function status()
{
$result = [];
if (Auth::status()) {
$result = [
"message" => "Authorized",
"type" => "apiUseAuthorized",
"token" => Session::get("token"),
];
} else {
$result = [
"message" => "Not Authorized",
"type" => "apiUseNotAuthorized",
];
}
return $result;
}
public static function login($body)
{
$result = [];
switch (Auth::login($body)) {
case "no_name":
$result = [
"message" => "Need to see some id, champ",
"type" => "requestLame",
];
break;
case "bad_pass":
$result = [
"message" => "Check your password, sport",
"type" => "requestLame",
];
break;
default:
$result = [
"message" => "Welcome back",
"type" => "requestGood",
];
break;
}
return $result;
}
public static function logout($body)
{
Auth::logout($body);
$result = [
"message" => "Till next time, g.",
"type" => "TASK_LOGOUT",
];
return $result;
}
}

View file

@ -2,6 +2,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
include "../brain/api/v1/AuthAPI.inc.php";
include "../brain/api/v1/ImagesAPI.inc.php";
include "../brain/api/v1/PagesAPI.inc.php";
include "../brain/api/v1/SettingsAPI.inc.php";
@ -15,7 +16,7 @@ class APIControl
): ResponseInterface {
switch (isset($args["third"]) ? $args["third"] : "none") {
case "status":
$result = Auth::status();
$result = AuthAPI::status();
break;
default:
break;
@ -39,10 +40,10 @@ class APIControl
switch (isset($args["third"]) ? $args["third"] : "none") {
case "login":
$result = Auth::login($body);
$result = AuthAPI::login($body);
break;
case "logout":
$result = Auth::logout($body);
$result = AuthAPI::logout($body);
break;
case "page":
$token = $request->getHeader("fipamo-access-token");

View file

@ -21,20 +21,12 @@ class Auth
public static function status()
{
$result = [];
$result = "";
if (Session::active()) {
$result = [
"message" => "Authorized",
"type" => "apiUseAuthorized",
"token" => Session::get("token"),
];
$result = true;
} else {
$result = [
"message" => "Not Authorized",
"type" => "apiUseNotAuthorized",
];
$result = false;
}
return $result;
}
@ -64,22 +56,13 @@ class Auth
Session::set("member", $member);
Session::set("token", $token);
$result = [
"message" => "Welcome back",
"type" => "requestGood",
];
$result = "good_login";
} else {
$result = [
"message" => "Check your password, sport",
"type" => "requestLame",
];
$result = "bad_pass";
}
} else {
//if name is not found
$result = [
"message" => "Need to see some id, champ",
"type" => "requestLame",
];
$result = "no_name";
}
return $result;
}
@ -87,10 +70,5 @@ class Auth
public static function logout()
{
Session::kill();
$result = [
"message" => "Till next time, g.",
"type" => "TASK_LOGOUT",
];
return $result;
}
}