mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-02-08 10:20:16 +08:00
feat : login first
This commit is contained in:
46
app/Service/Api/Login/PasswordLoginService.php
Normal file
46
app/Service/Api/Login/PasswordLoginService.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Login;
|
||||
|
||||
use App\Common\Interface\LoginInterface;
|
||||
use App\Exception\ErrException;
|
||||
|
||||
class PasswordLoginService extends AbstractLoginService implements LoginInterface
|
||||
{
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return string[]
|
||||
*/
|
||||
public function authenticate(string $username, string $password): array
|
||||
{
|
||||
if (!$this->validateCredentials([
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
])) throw new ErrException('error');
|
||||
|
||||
$this->logAttempt($username);
|
||||
|
||||
//
|
||||
return [
|
||||
'code' => 'success'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
public function supports(string $type): bool
|
||||
{
|
||||
return $type === 'password';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user