forked from projects/fipamo
moved member auth to API class
This commit is contained in:
parent
179f007fab
commit
20cc4abad9
3 changed files with 73 additions and 31 deletions
63
brain/api/v1/AuthAPI.inc.php
Normal file
63
brain/api/v1/AuthAPI.inc.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
include "../brain/api/v1/AuthAPI.inc.php";
|
||||||
include "../brain/api/v1/ImagesAPI.inc.php";
|
include "../brain/api/v1/ImagesAPI.inc.php";
|
||||||
include "../brain/api/v1/PagesAPI.inc.php";
|
include "../brain/api/v1/PagesAPI.inc.php";
|
||||||
include "../brain/api/v1/SettingsAPI.inc.php";
|
include "../brain/api/v1/SettingsAPI.inc.php";
|
||||||
|
@ -15,7 +16,7 @@ class APIControl
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
switch (isset($args["third"]) ? $args["third"] : "none") {
|
switch (isset($args["third"]) ? $args["third"] : "none") {
|
||||||
case "status":
|
case "status":
|
||||||
$result = Auth::status();
|
$result = AuthAPI::status();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -39,10 +40,10 @@ class APIControl
|
||||||
|
|
||||||
switch (isset($args["third"]) ? $args["third"] : "none") {
|
switch (isset($args["third"]) ? $args["third"] : "none") {
|
||||||
case "login":
|
case "login":
|
||||||
$result = Auth::login($body);
|
$result = AuthAPI::login($body);
|
||||||
break;
|
break;
|
||||||
case "logout":
|
case "logout":
|
||||||
$result = Auth::logout($body);
|
$result = AuthAPI::logout($body);
|
||||||
break;
|
break;
|
||||||
case "page":
|
case "page":
|
||||||
$token = $request->getHeader("fipamo-access-token");
|
$token = $request->getHeader("fipamo-access-token");
|
||||||
|
|
|
@ -21,20 +21,12 @@ class Auth
|
||||||
|
|
||||||
public static function status()
|
public static function status()
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = "";
|
||||||
if (Session::active()) {
|
if (Session::active()) {
|
||||||
$result = [
|
$result = true;
|
||||||
"message" => "Authorized",
|
|
||||||
"type" => "apiUseAuthorized",
|
|
||||||
"token" => Session::get("token"),
|
|
||||||
];
|
|
||||||
} else {
|
} else {
|
||||||
$result = [
|
$result = false;
|
||||||
"message" => "Not Authorized",
|
|
||||||
"type" => "apiUseNotAuthorized",
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,22 +56,13 @@ class Auth
|
||||||
Session::set("member", $member);
|
Session::set("member", $member);
|
||||||
Session::set("token", $token);
|
Session::set("token", $token);
|
||||||
|
|
||||||
$result = [
|
$result = "good_login";
|
||||||
"message" => "Welcome back",
|
|
||||||
"type" => "requestGood",
|
|
||||||
];
|
|
||||||
} else {
|
} else {
|
||||||
$result = [
|
$result = "bad_pass";
|
||||||
"message" => "Check your password, sport",
|
|
||||||
"type" => "requestLame",
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//if name is not found
|
//if name is not found
|
||||||
$result = [
|
$result = "no_name";
|
||||||
"message" => "Need to see some id, champ",
|
|
||||||
"type" => "requestLame",
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -87,10 +70,5 @@ class Auth
|
||||||
public static function logout()
|
public static function logout()
|
||||||
{
|
{
|
||||||
Session::kill();
|
Session::kill();
|
||||||
$result = [
|
|
||||||
"message" => "Till next time, g.",
|
|
||||||
"type" => "TASK_LOGOUT",
|
|
||||||
];
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue