make a wrapper for validating email

This commit is contained in:
printempw 2016-07-28 15:09:29 +08:00
parent 1ce097c4e9
commit a0da888c1d
2 changed files with 13 additions and 4 deletions

View File

@ -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);
}

View File

@ -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) {