diff --git a/app/Middlewares/CheckPostMiddleware.php b/app/Middlewares/CheckPostMiddleware.php index 4c0d9c48..bc16530d 100644 --- a/app/Middlewares/CheckPostMiddleware.php +++ b/app/Middlewares/CheckPostMiddleware.php @@ -5,6 +5,7 @@ namespace App\Middlewares; use \Pecee\Http\Middleware\IMiddleware; use \Pecee\Http\Request; use App\Exceptions\E; +use Validate; use View; class CheckPostMiddleware implements IMiddleware @@ -12,7 +13,7 @@ class CheckPostMiddleware implements IMiddleware public function handle(Request $request) { if (isset($_POST['email']) && $_POST['email'] != "") { - if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { + if (!Validate::checkValidEmail($_POST['email'])) { View::json('邮箱格式错误', 3); } diff --git a/app/Services/Validate.php b/app/Services/Validate.php index a1210dff..09d57371 100644 --- a/app/Services/Validate.php +++ b/app/Services/Validate.php @@ -6,13 +6,20 @@ use App\Exceptions\E; class Validate { - public static function checkValidPlayerName($player_name) { + public static function checkValidEmail($email) + { + return filter_var($email, FILTER_VALIDATE_EMAIL); + } + + public static function checkValidPlayerName($player_name) + { $regx = (Option::get('allow_chinese_playername') == "1") ? "/^([A-Za-z0-9\x{4e00}-\x{9fa5}_]+)$/u" : "/^([A-Za-z0-9_]+)$/"; return preg_match($regx, $player_name); } - public static function checkValidTextureName($texture_name) { + public static function checkValidTextureName($texture_name) + { if (strlen($texture_name) > 32 || strlen($texture_name) < 1) { throw new E('无效的材质名称。材质名长度应该小于 32。', 2); } else if (Utils::convertString($texture_name) != $texture_name) { @@ -21,7 +28,8 @@ class Validate return true; } - public static function checkValidPwd($passwd) { + public static function checkValidPwd($passwd) + { if (strlen($passwd) > 16 || strlen($passwd) < 8) { throw new E('无效的密码。密码长度应该大于 8 并小于 16。', 2); } else if (Utils::convertString($passwd) != $passwd) {