use Validate class in setup

This commit is contained in:
printempw 2016-08-06 19:54:03 +08:00
parent 8b9d902908
commit baeb967857
2 changed files with 11 additions and 6 deletions

View File

@ -12,12 +12,15 @@ class Validate
* @param array $keys * @param array $keys
* @return void * @return void
*/ */
public static function checkPost(Array $keys) public static function checkPost(Array $keys, $silent = false)
{ {
foreach ($keys as $key) { foreach ($keys as $key) {
if (!isset($_POST[$key])) if (!isset($_POST[$key])) {
if ($silent) return false;
throw new E('Invalid parameters.', 1); throw new E('Invalid parameters.', 1);
}
} }
return true;
} }
public static function email($email) public static function email($email)
@ -42,11 +45,13 @@ class Validate
return true; return true;
} }
public static function password($password) public static function password($password, $silent = false)
{ {
if (strlen($password) > 16 || strlen($password) < 8) { if (strlen($password) > 16 || strlen($password) < 8) {
if ($silent) return false;
throw new E('无效的密码。密码长度应该大于 8 并小于 16。', 2); throw new E('无效的密码。密码长度应该大于 8 并小于 16。', 2);
} else if (Utils::convertString($password) != $password) { } else if (Utils::convertString($password) != $password) {
if ($silent) return false;
throw new E('无效的密码。密码中包含了奇怪的字符。', 2); throw new E('无效的密码。密码中包含了奇怪的字符。', 2);
} }
return true; return true;

View File

@ -46,7 +46,7 @@ switch ($step) {
case 3: case 3:
// check post // check post
if (isset($_POST['email']) && isset($_POST['password']) && isset($_POST['confirm-pwd'])) if (Validate::checkPost(['email', 'password', 'confirm-pwd']))
{ {
if ($_POST['password'] != $_POST['confirm-pwd']) if ($_POST['password'] != $_POST['confirm-pwd'])
Http::redirect('index.php?step=2', '确认密码不一致'); Http::redirect('index.php?step=2', '确认密码不一致');
@ -55,8 +55,8 @@ switch ($step) {
$password = $_POST['password']; $password = $_POST['password'];
$sitename = isset($_POST['sitename']) ? $_POST['sitename'] : "Blessing Skin Server"; $sitename = isset($_POST['sitename']) ? $_POST['sitename'] : "Blessing Skin Server";
if (Validate::checkValidEmail($email)) { if (Validate::email($email)) {
if (strlen($password) > 16 || strlen($password) < 8) { if (!Validate::password($password)) {
Http::redirect('index.php?step=2', '无效的密码。密码长度应该大于 8 并小于 16。'); Http::redirect('index.php?step=2', '无效的密码。密码长度应该大于 8 并小于 16。');
} else if (Utils::convertString($password) != $password) { } else if (Utils::convertString($password) != $password) {