64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\api\logic\LoginLogic;
|
|
use app\common\validate\login\LoginAccountValidate;
|
|
use app\common\validate\login\RegisterValidate;
|
|
use app\common\validate\login\TokenValidate;
|
|
use think\response\Json;
|
|
|
|
/**
|
|
* 登录注册
|
|
* Class LoginController
|
|
* @package app\api\controller
|
|
*/
|
|
class LoginController extends BaseApiController
|
|
{
|
|
// 免登录方法
|
|
public array $notNeedLogin = ['register', 'login', 'verify'];
|
|
|
|
// 注册
|
|
public function register(): Json
|
|
{
|
|
$params = (new RegisterValidate())->post()->goCheck();
|
|
$result = LoginLogic::register($params);
|
|
if (true === $result) {
|
|
return $this->success('注册成功', [], 1, 1);
|
|
}
|
|
return $this->fail(LoginLogic::getError());
|
|
}
|
|
|
|
// 登录
|
|
public function login(): Json
|
|
{
|
|
$params = (new LoginAccountValidate())->post()->goCheck();
|
|
$result = LoginLogic::login($params);
|
|
if (false === $result) {
|
|
return $this->fail(LoginLogic::getError());
|
|
}
|
|
return $this->data($result);
|
|
}
|
|
|
|
// 退出
|
|
public function logout(): Json
|
|
{
|
|
$result = LoginLogic::logout($this->userInfo);
|
|
if($result){
|
|
return $this->success('成功');
|
|
}else{
|
|
return $this->fail('失败');
|
|
}
|
|
}
|
|
|
|
// 验证token
|
|
public function verify(): Json
|
|
{
|
|
$params = (new TokenValidate())->post()->goCheck();
|
|
$result = LoginLogic::verifyToken($params);
|
|
if (false === $result) {
|
|
return $this->fail(LoginLogic::getError());
|
|
}
|
|
return $this->data($result);
|
|
}
|
|
} |