From baeb967857520868b5842bfca7d643bbf4d3fb75 Mon Sep 17 00:00:00 2001 From: printempw Date: Sat, 6 Aug 2016 19:54:03 +0800 Subject: [PATCH] use Validate class in setup --- app/Services/Validate.php | 11 ++++++++--- setup/index.php | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Services/Validate.php b/app/Services/Validate.php index e8ee512c..0b308ab6 100644 --- a/app/Services/Validate.php +++ b/app/Services/Validate.php @@ -12,12 +12,15 @@ class Validate * @param array $keys * @return void */ - public static function checkPost(Array $keys) + public static function checkPost(Array $keys, $silent = false) { foreach ($keys as $key) { - if (!isset($_POST[$key])) + if (!isset($_POST[$key])) { + if ($silent) return false; throw new E('Invalid parameters.', 1); + } } + return true; } public static function email($email) @@ -42,11 +45,13 @@ class Validate return true; } - public static function password($password) + public static function password($password, $silent = false) { if (strlen($password) > 16 || strlen($password) < 8) { + if ($silent) return false; throw new E('无效的密码。密码长度应该大于 8 并小于 16。', 2); } else if (Utils::convertString($password) != $password) { + if ($silent) return false; throw new E('无效的密码。密码中包含了奇怪的字符。', 2); } return true; diff --git a/setup/index.php b/setup/index.php index aada0d19..0c9db8a9 100644 --- a/setup/index.php +++ b/setup/index.php @@ -46,7 +46,7 @@ switch ($step) { case 3: // 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']) Http::redirect('index.php?step=2', '确认密码不一致'); @@ -55,8 +55,8 @@ switch ($step) { $password = $_POST['password']; $sitename = isset($_POST['sitename']) ? $_POST['sitename'] : "Blessing Skin Server"; - if (Validate::checkValidEmail($email)) { - if (strlen($password) > 16 || strlen($password) < 8) { + if (Validate::email($email)) { + if (!Validate::password($password)) { Http::redirect('index.php?step=2', '无效的密码。密码长度应该大于 8 并小于 16。'); } else if (Utils::convertString($password) != $password) {