框架升级及修复升级后的bug

This commit is contained in:
Dev
2026-10-16 18:13:09 +08:00
parent dafb0c96c0
commit 2d342bcbd7
537 changed files with 49836 additions and 40933 deletions
+120
View File
@@ -0,0 +1,120 @@
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\library\Ems as Emslib;
use app\common\model\User;
use think\Hook;
/**
* 邮箱验证码接口
*/
class Ems extends Api
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
}
/**
* 发送验证码
*
* @ApiMethod (POST)
* @ApiParams (name="email", type="string", required=true, description="邮箱")
* @ApiParams (name="event", type="string", required=true, description="事件名称")
*/
public function send()
{
$email = $this->request->post("email");
$event = $this->request->post("event");
$event = $event ? $event : 'register';
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->error(__('邮箱格式错误'));
}
if (!preg_match("/^[a-z0-9_\-]{3,30}\$/i", $event)) {
$this->error(__('事件名称错误'));
}
$last = Emslib::get($email, $event);
if ($last && time() - $last['createtime'] < 60) {
$this->error(__('发送频繁'));
}
$ipSendTotal = \app\common\model\Ems::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
if ($ipSendTotal >= 5) {
$this->error(__('发送频繁'));
}
if ($event) {
$userinfo = User::getByEmail($email);
if ($event == 'register' && $userinfo) {
//已被注册
$this->error(__('已被注册'));
} elseif (in_array($event, ['changeemail']) && $userinfo) {
//被占用
$this->error(__('已被占用'));
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
//未注册
$this->error(__('未注册'));
}
}
$ret = Emslib::send($email, null, $event);
if ($ret) {
$this->success(__('发送成功'));
} else {
$this->error(__('发送失败'));
}
}
/**
* 检测验证码
*
* @ApiMethod (POST)
* @ApiParams (name="email", type="string", required=true, description="邮箱")
* @ApiParams (name="event", type="string", required=true, description="事件名称")
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
*/
public function check()
{
$email = $this->request->post("email");
$event = $this->request->post("event");
$event = $event ? $event : 'register';
$captcha = $this->request->post("captcha");
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->error(__('邮箱格式错误'));
}
if (!preg_match("/^[a-z0-9_\-]{3,30}\$/i", $event)) {
$this->error(__('事件名称错误'));
}
if (!preg_match("/^[a-z0-9]{4,6}\$/i", $captcha)) {
$this->error(__('验证码格式错误'));
}
if ($event) {
$userinfo = User::getByEmail($email);
if ($event == 'register' && $userinfo) {
//已被注册
$this->error(__('已被注册'));
} elseif (in_array($event, ['changeemail']) && $userinfo) {
//被占用
$this->error(__('已被占用'));
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
//未注册
$this->error(__('未注册'));
}
}
$ret = Emslib::check($email, $captcha, $event);
if ($ret) {
$this->success(__('成功'));
} else {
$this->error(__('验证码不正确'));
}
}
}
+8 -2
View File
@@ -34,8 +34,14 @@ class Token extends Api
$token = $this->auth->getToken();
\app\common\library\Token::delete($token);
//创建新Token
$token = Random::uuid();
\app\common\library\Token::set($token, $this->auth->id, 2592000);
$attempts = 0;
do {
$token = Random::uuid();
$result = \app\common\library\Token::set($token, $this->auth->id, 2592000);
} while (!$result && ++$attempts < 5);
if (!$result) {
$this->error('Failed to generate token');
}
$tokenInfo = \app\common\library\Token::get($token);
$this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
}
+16 -10
View File
@@ -5,7 +5,6 @@ namespace app\api\controller;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\service\UserService;
use fast\Random;
use think\Config;
use think\Validate;
@@ -76,7 +75,7 @@ class User extends Api
if (!Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('Mobile is incorrect'));
}
if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
if (!Sms::check($mobile, $captcha, 'mobilelogin', true)) {
$this->error(__('Captcha is incorrect'));
}
$user = \app\common\model\User::getByMobile($mobile);
@@ -124,12 +123,13 @@ class User extends Api
if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('Mobile is incorrect'));
}
$ret = Sms::check($mobile, $code, 'register');
$ret = Sms::check($mobile, $code, 'register', true);
if (!$ret) {
$this->error(__('Captcha is incorrect'));
}
$ret = $this->auth->register($username, $password, $email, $mobile, []);
if ($ret) {
Sms::flush($mobile, 'register');
$data = ['userinfo' => $this->auth->getUserinfo()];
$this->success(__('Sign up successful'), $data);
} else {
@@ -180,8 +180,15 @@ class User extends Api
}
$user->nickname = $nickname;
}
if ($avatar) {
//判断是否匹配config('upload.cdnurl')开头以及当前$SERVER['HTTP_HOST']开头。
if (preg_match('/^' . preg_quote(config('upload.cdnurl') . '/', '/') . '/i', $avatar)
|| preg_match('/^' . preg_quote(substr(config('upload.savekey'), 0, strpos(config('upload.savekey'), '{')), '/') . '/i', $avatar)
|| preg_match('/^' . preg_quote($_SERVER['HTTP_HOST'] . '/', '/') . '/i', $avatar)) {
$user->avatar = $avatar;
}
}
$user->bio = $bio;
$user->avatar = $avatar;
$user->save();
$this->success();
}
@@ -207,7 +214,7 @@ class User extends Api
if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
$this->error(__('Email already exists'));
}
$result = Ems::check($email, $captcha, 'changeemail');
$result = Ems::check($email, $captcha, 'changeemail', true);
if (!$result) {
$this->error(__('Captcha is incorrect'));
}
@@ -242,7 +249,7 @@ class User extends Api
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
$this->error(__('Mobile already exists'));
}
$result = Sms::check($mobile, $captcha, 'changemobile');
$result = Sms::check($mobile, $captcha, 'changemobile', true);
if (!$result) {
$this->error(__('Captcha is incorrect'));
}
@@ -279,7 +286,7 @@ class User extends Api
$loginret = \addons\third\library\Service::connect($platform, $result);
if ($loginret) {
$data = [
'userinfo' => $this->auth->getUserinfo(),
'userinfo' => $this->auth->getUserinfo(),
'thirdinfo' => $result
];
$this->success(__('Logged in successful'), $data);
@@ -318,7 +325,7 @@ class User extends Api
if (!$user) {
$this->error(__('User not found'));
}
$ret = Sms::check($mobile, $captcha, 'resetpwd');
$ret = Sms::check($mobile, $captcha, 'resetpwd', true);
if (!$ret) {
$this->error(__('Captcha is incorrect'));
}
@@ -331,7 +338,7 @@ class User extends Api
if (!$user) {
$this->error(__('User not found'));
}
$ret = Ems::check($email, $captcha, 'resetpwd');
$ret = Ems::check($email, $captcha, 'resetpwd', true);
if (!$ret) {
$this->error(__('Captcha is incorrect'));
}
@@ -346,5 +353,4 @@ class User extends Api
$this->error($this->auth->getError());
}
}
}