public function testIsValidationCodeUnsed($email, $validationCode) { $gateway = new ValidationCodeGateway(); $email = '*****@*****.**'; $validationCode = '123456'; $this->assertTrue($gateway->isValidationCodeUnsed($email, $validationCode)); $email = '*****@*****.**'; $validationCode = '111111'; $this->assertFalse($gateway->isValidationCodeUnsed($email, $validationCode)); // No this email-vcode combination $email = 'sdfdsf345'; $validationCode = 'dsfdsfdsfs6'; $this->assertFalse($gateway->isValidationCodeUnsed($email, $validationCode)); }
function register_check_errors($username, $email, $password, $password2, $validationCode) { global $main_smarty; require_once mnminclude . 'check_behind_proxy.php'; $userip = check_ip_behind_proxy(); if (is_ip_banned($userip)) { $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_YourIpIsBanned'); $error = true; } if (!isset($username) || strlen($username) < 3) { // if no username was given or username is less than 3 characters $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_UserTooShort'); $error = true; } if (preg_match('/\\pL/u', 'a')) { // Check if PCRE was compiled with UTF-8 support if (!preg_match('/^[_\\-\\d\\p{L}\\p{M}]+$/iu', $username)) { // if username contains invalid characters $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_UserInvalid'); $error = true; } } else { if (!preg_match('/^[^~`@%&=\\/;:\\.,<>!"\\\'\\^\\.\\[\\]\\$\\(\\)\\|\\*\\+\\-\\?\\{\\}\\\\]+$/', $username)) { $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_UserInvalid'); $error = true; } } if (user_exists(trim($username))) { // if username already exists $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_UserExists'); $error = true; } if (!check_email(trim($email))) { // if email is not valid $form_email_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_BadEmail'); $error = true; } if (email_exists(trim($email))) { // if email already exists $form_email_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_EmailExists'); $error = true; } if (strlen($password) < 5) { // if password is less than 5 characters $form_password_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_FiveCharPass'); $error = true; } if ($password !== $password2) { // if both passwords do not match $form_password_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_NoPassMatch'); $error = true; } $vars = array('username' => $username, 'email' => $email, 'password' => $password); check_actions('register_check_errors', $vars); if ($vars['error'] == true) { $error = true; if ($vars['username_error']) { $form_username_error[] = $vars['username_error']; } if ($vars['email_error']) { $form_email_error[] = $vars['email_error']; } if ($vars['password_error']) { $form_password_error[] = $vars['password_error']; } } $gateway = new ValidationCodeGateway(); if (!$error && $gateway->isValidationCodeUnsed($email, $validationCode)) { $gateway->useValidationCode($email, $validationCode); } else { $error = true; $main_smarty->assign('form_validationCode_error', 'Validation code is invalid, please contact admin to acquire a valid code.'); } $main_smarty->assign('form_username_error', $form_username_error); $main_smarty->assign('form_email_error', $form_email_error); $main_smarty->assign('form_password_error', $form_password_error); return $error; }