make a wrapper for validating email
This commit is contained in:
parent
1ce097c4e9
commit
a0da888c1d
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user