fipamo/app/Services/Data/AuthService.php
ro 36d04c8f68
reorganized services
service classes are beginning to swell as there functionality is being
fleshed out, so a new organizational structure was needed to make sure
class sizes don't become too large and to increase site managability and
legibilty as more features get added and the code base grows.

data is for retrieving, managing site information, assets interact with external files
and upkeep is for maintenance.

some additional tweaks were also made to the options menu template to
prep it for it's transition to a toolbar component
2024-05-12 22:14:53 -06:00

71 lines
2.1 KiB
PHP

<?php
namespace App\Services\Data;
use ReallySimpleJWT\Token;
use function _\find;
class AuthService
{
protected $config;
protected $request;
public function __construct(SettingsService $config)
{
$this->config = $config;
}
public function check($request)
{
$folks = $this->config->getFolks();
$found = find($folks, ['handle' => $request->handle]);
if ($found) {
if (password_verify($request->password, $found['password'])) {
$member = [
'handle' => $found['handle'],
'email' => $found['email'],
'role' => $found['role'],
'avatar' => $found['avi'],
'key' => $found['key'],
'secret' => $found['secret'],
];
$token = Token::create(
$found['key'],
$found['secret'],
time() + 3600,
'localhost'
); //expires in an hour
$form_token = md5(uniqid(microtime(), true));
$request->session()->put('member', $member);
$request->session()->put('token', $token);
$request->session()->put('form_token', $form_token);
return ['status' => true, 'message' => 'HEY WELCOME BACK'];
//DO SESSION STUFF
} else {
return ['status' => false, 'message' => 'CHECK THAT PASSWORD'];
//RETURN ERROR
}
} else {
return ['status' => false, 'message' => 'CHECK THAT HANDLE'];
}
}
public static function status()
{
if (session('member') !== null) {
if (
Token::validate(session('token'), session('member')['secret']) &&
Token::validateExpiration(session('token'), session('member')['secret'])
) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}