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
* @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;

View File

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