first commit

This commit is contained in:
2026-05-07 16:37:25 +08:00
commit 822ed9a099
67 changed files with 1799 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace app\index\controller;
use app\BaseController;
use app\common\service\AuthService;
use think\facade\Session;
// 已完成
class Login extends BaseController
{
/*
处理登录请求(已完成)
*/
public function login(AuthService $authService)
{
$params = $this->request->only(['username', 'password'], 'post');
// 验证数据
if (empty($params['username']) || empty($params['password'])) {
return json(['code' => 400, 'message' => '用户名和密码不能为空']);
}
try {
$result = $authService->login($params['username'], $params['password']);
} catch (\Exception $e) {
return json(['code' => 400, 'message' => $e->getMessage(),'data' => []]);
}
return json(['code' => 200, 'message' => '登录成功', 'data' => $result]);
}
/*
退出登录(已完成)
*/
protected function logout()
{
Session::clear();
return json(['code' => 200, 'message' => '退出成功']);
}
}