Browse Source

修复异常

master
xyiege 1 year ago
parent
commit
af95833b21
  1. 7
      app/api/controller/ApiController.php
  2. 12
      app/api/controller/Passport.php

7
app/api/controller/ApiController.php

@ -1,6 +1,7 @@
<?php
namespace app\api\controller;
use think\App;
use think\response\Json;
use think\route\dispatch\Controller;
use think\Request;
@ -16,6 +17,11 @@ abstract class ApiController {
* @var Request
*/
protected $request;
/**
* 应用实例
* @var App
*/
protected $app;
/**
* 构造方法
* BaseController constructor.
@ -23,6 +29,7 @@ abstract class ApiController {
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();

12
app/api/controller/Passport.php

@ -13,10 +13,16 @@ class Passport extends ApiController{
/**
* 登录
*/
public function login():Json{
public function login():Json
{
if (!$this->request->isPost()) {
return $this->renderError('请求方式错误');
}
$data = $this->postData();
$model = new UserService;
if (($userInfo = $model->login($this->postData())) === false) {
//
$data = $this->postData();
if (($userInfo = $model->login($data['uname'],$data['upass'])) === false) {
return $this->renderError($model->getError() ?: '登录失败');
}
return $this->renderSuccess([

Loading…
Cancel
Save