42 lines
963 B
PHP
42 lines
963 B
PHP
<?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 $this->error('用户名和密码不能为空');
|
|
}
|
|
|
|
try {
|
|
$result = $authService->login($params['username'], $params['password']);
|
|
return $this->success('登录成功', $result);
|
|
} catch (\Exception $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/*
|
|
退出登录(已完成)
|
|
*/
|
|
public function logout()
|
|
{
|
|
Session::clear();
|
|
return $this->success('退出成功');
|
|
}
|
|
}
|