fipamo/brain/api/v1/AuthAPI.php
Are0h 63eaba08e2 Added config for PHP formatting (PSR2)
I needed some consistent php formatting, so I plugged in a php fixer
config and then reformatted all PHP files so it's all consistent.

Fixed an ID issue with the page-edit template that was causing page
editing to fail.
2022-05-16 17:41:15 -07:00

77 lines
1.8 KiB
PHP

<?php
namespace brain\api\v1;
use brain\data\Auth;
use brain\data\Session;
class AuthAPI
{
public function __construct()
{
}
public static function status()
{
$result = [];
//internal check for admin action
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;
}
public static function requestSecret($body)
{
$result = Auth::findSecret($body);
return $result;
}
public static function resetPassword($body)
{
$result = Auth::makeNewPassword($body);
return $result;
}
}