From 20cc4abad99f55b06a249ede2b19cdb12792edeb Mon Sep 17 00:00:00 2001 From: Ro Date: Fri, 16 Apr 2021 20:50:03 -0700 Subject: [PATCH] moved member auth to API class --- brain/api/v1/AuthAPI.inc.php | 63 +++++++++++++++++++++++++++++ brain/controller/APIControl.inc.php | 7 ++-- brain/data/Auth.inc.php | 34 +++------------- 3 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 brain/api/v1/AuthAPI.inc.php diff --git a/brain/api/v1/AuthAPI.inc.php b/brain/api/v1/AuthAPI.inc.php new file mode 100644 index 0000000..7977b4e --- /dev/null +++ b/brain/api/v1/AuthAPI.inc.php @@ -0,0 +1,63 @@ + "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; + } +} diff --git a/brain/controller/APIControl.inc.php b/brain/controller/APIControl.inc.php index 954e89d..43d554d 100644 --- a/brain/controller/APIControl.inc.php +++ b/brain/controller/APIControl.inc.php @@ -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"); diff --git a/brain/data/Auth.inc.php b/brain/data/Auth.inc.php index 8dda0f0..b93579d 100644 --- a/brain/data/Auth.inc.php +++ b/brain/data/Auth.inc.php @@ -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; } }