first commit
This commit is contained in:
43
app/index/controller/Login.php
Normal file
43
app/index/controller/Login.php
Normal 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' => '退出成功']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user