fix:更新已知bug,优化代码
This commit is contained in:
@@ -8,6 +8,8 @@ use app\ApiController;
|
||||
use app\common\library\Email;
|
||||
use app\common\library\Sms;
|
||||
use app\common\model\system\User;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use support\Response;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
@@ -18,11 +20,11 @@ use think\db\exception\ModelNotFoundException;
|
||||
class Ajax extends ApiController
|
||||
{
|
||||
|
||||
public $needLogin = true;
|
||||
public bool $needLogin = true;
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
* @return mixed|void
|
||||
* @return Response|void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
@@ -44,10 +46,10 @@ class Ajax extends ApiController
|
||||
return $this->error(__('发送频繁'));
|
||||
}
|
||||
|
||||
$userinfo = User::getByMobile($mobile);
|
||||
if (in_array($event, ['register', 'changer']) && $userinfo) {
|
||||
$userData = User::getByMobile($mobile);
|
||||
if (in_array($event, ['register', 'changer']) && $userData) {
|
||||
return $this->error('当前手机号已被占用');
|
||||
} else if ($event == 'forgot' && !$userinfo) {
|
||||
} else if ($event == 'forgot' && !$userData) {
|
||||
return $this->error('当前手机号未注册');
|
||||
}
|
||||
|
||||
@@ -63,10 +65,11 @@ class Ajax extends ApiController
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
* @return mixed|void
|
||||
* @return Response|void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function emailSend()
|
||||
{
|
||||
@@ -86,10 +89,10 @@ class Ajax extends ApiController
|
||||
return $this->error(__('发送频繁'));
|
||||
}
|
||||
|
||||
$userinfo = User::getByEmail($email);
|
||||
if (in_array($event, ['register', 'changer']) && $userinfo) {
|
||||
$userData = User::getByEmail($email);
|
||||
if (in_array($event, ['register', 'changer']) && $userData) {
|
||||
return $this->error('当前邮箱已被注册');
|
||||
} else if ($event == 'forgot' && !$userinfo) {
|
||||
} else if ($event == 'forgot' && !$userData) {
|
||||
return $this->error('当前邮箱不存在');
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use app\ApiController;
|
||||
use app\common\library\ResultCode;
|
||||
use app\common\library\Sms;
|
||||
use app\common\library\Upload;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
@@ -20,20 +21,20 @@ class User extends ApiController
|
||||
* 需要登录
|
||||
* @var bool
|
||||
*/
|
||||
public $needLogin = true;
|
||||
public bool $needLogin = true;
|
||||
|
||||
/**
|
||||
* 非鉴权方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedAuth = ['register', 'login'];
|
||||
public array $noNeedAuth = ['register', 'login'];
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
* @return mixed|void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws ModelNotFoundException|InvalidArgumentException
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
@@ -83,8 +84,6 @@ class User extends ApiController
|
||||
$response->withBody(json_encode(array_merge(ResultCode::LOGINSUCCESS, ['token' => $this->auth->token])));
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $this->throwError();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,19 +20,19 @@ class ApiPermissions implements MiddlewareInterface
|
||||
* 控制器登录鉴权
|
||||
* @var bool
|
||||
*/
|
||||
public $needLogin = false;
|
||||
public bool $needLogin = false;
|
||||
|
||||
/**
|
||||
* API验证流程
|
||||
* @var bool
|
||||
*/
|
||||
public $authWorkflow = true;
|
||||
public bool $authWorkflow = true;
|
||||
|
||||
/**
|
||||
* 非鉴权方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedAuth = [];
|
||||
public array $noNeedAuth = [];
|
||||
|
||||
/**
|
||||
* 校验权限
|
||||
@@ -57,10 +57,10 @@ class ApiPermissions implements MiddlewareInterface
|
||||
|
||||
$auth = Auth::instance();
|
||||
if ($auth->isLogin()) {
|
||||
$request->userId = $auth->userInfo['id'];
|
||||
$request->userInfo = $auth->userInfo;
|
||||
$request->user_id = $auth->userData['id'];
|
||||
$request->userData = $auth->userData;
|
||||
if ($this->authWorkflow && Event::hasListener('apiAuth')) {
|
||||
$result = Event::emit('apiAuth', ['method' => $method, 'userId' => $request->userId], true);
|
||||
$result = Event::emit('apiAuth', ['method' => $method, 'user_id' => $request->user_id], true);
|
||||
if (isset($result['code']) && $result['code'] != 200) {
|
||||
return json($result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user