blessing-skin-server/app/Services/Validate.php

55 lines
1.6 KiB
PHP
Raw Normal View History

2016-07-21 22:01:57 +08:00
<?php
namespace App\Services;
2016-07-24 15:56:23 +08:00
use App\Exceptions\E;
2016-07-21 22:01:57 +08:00
class Validate
{
2016-08-06 19:38:37 +08:00
/**
* Check POST values in a simple way
*
* @param array $keys
* @return void
*/
public static function checkPost(Array $keys)
{
foreach ($keys as $key) {
if (!isset($_POST[$key]))
throw new E('Invalid parameters.', 1);
}
}
public static function email($email)
2016-07-28 15:09:29 +08:00
{
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
2016-08-06 19:38:37 +08:00
public static function playerName($player_name)
2016-07-28 15:09:29 +08:00
{
2016-07-21 22:01:57 +08:00
$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);
}
2016-08-06 19:38:37 +08:00
public static function textureName($texture_name)
2016-07-28 15:09:29 +08:00
{
2016-07-21 22:01:57 +08:00
if (strlen($texture_name) > 32 || strlen($texture_name) < 1) {
throw new E('无效的材质名称。材质名长度应该小于 32。', 2);
} else if (Utils::convertString($texture_name) != $texture_name) {
throw new E('无效的材质名称。材质名称中包含了奇怪的字符。', 2);
}
return true;
}
2016-08-06 19:38:37 +08:00
public static function password($password)
2016-07-28 15:09:29 +08:00
{
2016-08-06 19:38:37 +08:00
if (strlen($password) > 16 || strlen($password) < 8) {
2016-07-21 22:01:57 +08:00
throw new E('无效的密码。密码长度应该大于 8 并小于 16。', 2);
2016-08-06 19:38:37 +08:00
} else if (Utils::convertString($password) != $password) {
2016-07-21 22:01:57 +08:00
throw new E('无效的密码。密码中包含了奇怪的字符。', 2);
}
return true;
}
}