mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
Introduce filament
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace App\Auth;
|
||||
|
||||
use Illuminate\Auth\GuardHelpers;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Auth\UserProvider;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NexusWebGuard implements Guard
|
||||
{
|
||||
use GuardHelpers;
|
||||
|
||||
/**
|
||||
* The request instance.
|
||||
*
|
||||
* @var \Illuminate\Http\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new authentication guard.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Contracts\Auth\UserProvider|null $provider
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Request $request, UserProvider $provider = null)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->provider = $provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently authenticated user.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
if (! is_null($this->user)) {
|
||||
return $this->user;
|
||||
}
|
||||
return $this->user = $this->provider->retrieveByCredentials($this->request->cookie());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate a user's credentials.
|
||||
*
|
||||
* @param array $credentials
|
||||
* @return bool
|
||||
*/
|
||||
public function validate(array $credentials = [])
|
||||
{
|
||||
$required = ['c_secure_pass', 'c_secure_uid', 'c_secure_login'];
|
||||
foreach ($required as $value) {
|
||||
if (empty($credentials[$value])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$b_id = base64($credentials["c_secure_uid"],false);
|
||||
$id = intval($b_id ?? 0);
|
||||
if (!$id || !is_valid_id($id) || strlen($credentials["c_secure_pass"]) != 32) {
|
||||
return false;
|
||||
}
|
||||
if ($this->provider->retrieveById($id)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
logoutcookie();
|
||||
return nexus_redirect('login.php');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user