|
|
|
@ -18,6 +18,7 @@ class Passport extends ApiController{ |
|
|
|
if (!$this->request->isPost()) { |
|
|
|
return $this->renderError('不支持GET请求'); |
|
|
|
} |
|
|
|
$data = $this->postData(); |
|
|
|
$model = new UserService; |
|
|
|
// |
|
|
|
$data = $this->postData(); |
|
|
|
@ -47,3 +48,43 @@ class Passport extends ApiController{ |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// app/controller/Index.php |
|
|
|
// namespace app\controller; |
|
|
|
|
|
|
|
// use app\service\JWTService; |
|
|
|
// use think\Request; |
|
|
|
|
|
|
|
// class IndexController |
|
|
|
// { |
|
|
|
// protected $jwtService; |
|
|
|
|
|
|
|
// public function __construct(JWTService $jwtService) |
|
|
|
// { |
|
|
|
// $this->jwtService = $jwtService; |
|
|
|
// } |
|
|
|
|
|
|
|
// public function login(Request $request) |
|
|
|
// { |
|
|
|
// $username = $request->param('username'); |
|
|
|
// $password = $request->param('password'); |
|
|
|
|
|
|
|
// // 假设验证用户名和密码成功 |
|
|
|
// $claims = ['id' => 1, 'username' => $username]; |
|
|
|
|
|
|
|
// $token = $this->jwtService->createToken($claims); |
|
|
|
|
|
|
|
// return json(['token' => $token]); |
|
|
|
// } |
|
|
|
|
|
|
|
// public function protectedRoute(Request $request) |
|
|
|
// { |
|
|
|
// $claims = $request->attributes->get('claims'); |
|
|
|
|
|
|
|
// if (empty($claims)) { |
|
|
|
// return json(['error' => 'Unauthorized'], 401); |
|
|
|
// } |
|
|
|
|
|
|
|
// return json(['message' => 'Welcome, ' . $claims['username']]); |
|
|
|
// } |
|
|
|
// } |