This commit is contained in:
2025-08-13 20:28:23 +08:00
parent 537426593a
commit 7f48675193
9 changed files with 92 additions and 29 deletions

View File

@@ -0,0 +1,67 @@
<?php
namespace app\czg\app\controller;
use app\api\model\Msg;
use app\api\model\TbUser;
use app\common\controller\BaseController;
use app\common\model\SysUser;
use think\facade\Db;
use think\Request;
use Throwable;
use ba\Captcha;
use ba\ClickCaptcha;
use think\facade\Config;
use app\common\facade\Token;
use app\common\controller\Frontend;
use app\api\validate\User as UserValidate;
class LoginController extends BaseController
{
protected array $noNeedLogin = ['*'];
public function index()
{
$data = $this->request->post();
if(empty($data['phone']) || empty($data['password'])){
$this->n_error('参数不完整');
}
$res = $this->auth->newlogin($data['phone'], $data['password'], 0);
if (isset($res) && $res === true) {
$data = $this->auth->getUser();
$this->n_success([
'token' => $this->auth->getUserInfo()['token'],
'user' => apiconvertToCamelCase($data)
]);
} else {
$msg = $this->auth->getError();
$msg = $msg ?: __('Check in failed, please try again or contact the website administrator~');
$this->n_error($msg);
}
}
// 注册
public function register()
{
return $this->ApiDataReturn(TbUser::register($this->request->post()));
}
// 发送验证码
public function sendMsg()
{
$get = $this->request->route();
return $this->ApiDataReturn(Msg::sendMsg($get['phone'], $get['event']));
}
// 忘记密码
public function forgetPwd()
{
$post = $this->request->post();
return $this->ApiDataReturn(TbUser::forgetPwd($post['phone'], $post['pwd'], $post['msg']));
}
}