first commit
This commit is contained in:
42
app/common/service/AuthService.php
Normal file
42
app/common/service/AuthService.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\User;
|
||||
use think\facade\Session;
|
||||
|
||||
class AuthService
|
||||
{
|
||||
/**
|
||||
* 验证用户登录状态
|
||||
* @return array|false 返回用户信息数组或false
|
||||
*/
|
||||
public function login(string $username, string $password)
|
||||
{
|
||||
$user = User::with(['company'])
|
||||
->where('username', $username)
|
||||
->find();
|
||||
|
||||
|
||||
|
||||
if (!$user || !password_verify($password, $user['password'])) {
|
||||
throw new \Exception('用户名或密码错误');
|
||||
}
|
||||
|
||||
if ($user['status'] != 1) {
|
||||
throw new \Exception('账户已禁用');
|
||||
}
|
||||
|
||||
|
||||
$userInfo = [
|
||||
'company_name' => $user['company']['company_name'], // 所属公司名称
|
||||
'username' => $user['username'],
|
||||
'role' => $user['role'],
|
||||
];
|
||||
|
||||
Session::set('user_info', $user);
|
||||
|
||||
return $userInfo;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user