登录、模板操作
This commit is contained in:
@@ -2,34 +2,16 @@
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseNotAuthService;
|
||||
use App\Models\AdminModel;
|
||||
use App\Service\common\JWTService;
|
||||
use App\Service\common\UtilsService;
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LoginService
|
||||
class LoginService extends BaseNotAuthService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var mixed 单例实例,确保该类只有一个全局实例
|
||||
*/
|
||||
private static mixed $_instance;
|
||||
|
||||
/**
|
||||
* 获取实例
|
||||
* @return null|static
|
||||
*/
|
||||
public static function getInstance(): null|static
|
||||
{
|
||||
$name = get_called_class();
|
||||
if (!isset(self::$_instance[$name])) {
|
||||
self::$_instance[$name] = new static();
|
||||
}
|
||||
|
||||
return self::$_instance[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param $phone
|
||||
@@ -39,19 +21,19 @@ class LoginService
|
||||
*/
|
||||
public function login($phone, $password): array
|
||||
{
|
||||
$userModel = AdminModel::with(['roles:id,name,value'])->where('phone', $phone)->first();
|
||||
$userModel = AdminModel::with(['role:id,name,value'])->where('phone', $phone)->first();
|
||||
if (empty($userModel)) {
|
||||
UtilsService::getInstance()->errorThrow('用户或密码错误!');
|
||||
// return $this->register($phone, $password);
|
||||
}
|
||||
|
||||
if (!password_verify($password, $userModel->password)) {
|
||||
UtilsService::getInstance()->errorThrow('用户或密码错误!');
|
||||
UtilsService::getInstance()->errorThrow('用户或密码错误2!');
|
||||
}
|
||||
|
||||
if ($userModel->ip !== get_ip()) {
|
||||
$ipTable = json_decode($userModel->ip_table, true);
|
||||
if (!in_array(get_ip(), $ipTable)) {
|
||||
if (!in_array(get_ip(), $ipTable?? [])) {
|
||||
$ipTable[] = get_ip();
|
||||
}
|
||||
$update = AdminModel::where('id', $userModel->id)->update([
|
||||
@@ -72,8 +54,8 @@ class LoginService
|
||||
'nick_name' => $userModel->nick_name,
|
||||
'avatar' => $userModel->avatar,
|
||||
'email' => $userModel->email,
|
||||
'role_name' => $userModel->roles->name,
|
||||
'role_value' => $userModel->roles->value,
|
||||
'role_name' => $userModel->role->name,
|
||||
'role_value' => $userModel->role->value,
|
||||
'ip' => $userModel->ip,
|
||||
'ip_table' => $userModel->ip_table,
|
||||
];
|
||||
@@ -114,7 +96,7 @@ class LoginService
|
||||
UtilsService::getInstance()->errorThrow('注册失败!');
|
||||
}
|
||||
|
||||
$userInfo = AdminModel::with(['roles:id,name,value'])->where('id', $createModel->id)->first();
|
||||
$userInfo = AdminModel::with(['role:id,name,value'])->where('id', $createModel->id)->first();
|
||||
|
||||
$result = [
|
||||
'id' => $userInfo->id,
|
||||
@@ -122,8 +104,8 @@ class LoginService
|
||||
'nick_name' => $userInfo->nick_name,
|
||||
'avatar' => $userInfo->avatar,
|
||||
'email' => $userInfo->email?? '',
|
||||
'role_name' => $userInfo->roles->name,
|
||||
'role_value' => $userInfo->roles->value,
|
||||
'role_name' => $userInfo->role->name,
|
||||
'role_value' => $userInfo->role->value,
|
||||
'ip' => $userInfo->ip,
|
||||
'ip_table' => $userInfo->ip_table,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user