blog/app/service/UserService.php

61 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2024-06-08 15:54:41 +08:00
<?php
namespace app\service;
use app\model\User;
class UserService
{
/**
* @Inject
* @var User
*/
private $user;
/**
* User: 高军
* Date: 2024/5/8
* QQ: 2926804347
* @param string $userName
* @param string $pwd
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* Notes:
*/
public function login(string $userName, string $pwd): array
{
$userInfo = $this->user->getInfoByUserName($userName);
if (!$userInfo['result']) return $userInfo;
if (!password_verify($pwd, $userInfo['data']['pass_word'])) return show(false, '用户名或密码错误');
$tokenData = [
'id' => $userInfo['data']['id'],
'name' => $userInfo['data']['nickname'],
'email' => $userInfo['data']['email']
];
$token = \Tinywan\Jwt\JwtToken::generateToken($tokenData);
unset($userInfo['data']['pass_word']);
$data = [
'token' => $token,
'userInfo' => $userInfo['data']
];
return show(true, '登录成功', $data);
}
/**
* User: 高军
* Date: 2024/5/8
* QQ: 2926804347
* @param array $param
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* Notes:
*/
public function getList(array $param):array
{
return $this->user->getList($param);
}
}