mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
wip
This commit is contained in:
37
app/Server/Http/Controllers/Admin/AdminController.php
Normal file
37
app/Server/Http/Controllers/Admin/AdminController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Ratchet\ConnectionInterface;
|
||||
use function GuzzleHttp\Psr7\str;
|
||||
|
||||
abstract class AdminController extends Controller
|
||||
{
|
||||
protected function shouldHandleRequest(Request $request, ConnectionInterface $httpConnection): bool
|
||||
{
|
||||
try {
|
||||
$authorization = Str::after($request->header('Authorization'), 'Basic ');
|
||||
$authParts = explode(':', base64_decode($authorization), 2);
|
||||
list($user, $password) = $authParts;
|
||||
|
||||
if (! $this->credentialsAreAllowed($user, $password)) {
|
||||
throw new \InvalidArgumentException('Invalid Login');
|
||||
}
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
$httpConnection->send(str(new Response(401, [
|
||||
'WWW-Authenticate' => 'Basic realm="Expose"'
|
||||
], 'foo')));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function credentialsAreAllowed(string $user, string $password)
|
||||
{
|
||||
return config('expose.admin.users.'.$user) === $password;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user