/** * tries to create a new user, throws exception on error * * @param string $given_name * @param string $family_name * @param string $email * @param string $login * @param string $password1 * @param string $password2 * @return void * @throws ControllerException * @throws DataSourceException * @throws UserCreationException */ public static function register($given_name, $family_name, $email, $login, $password1, $password2) { // check the infos for validity if (empty($given_name) || empty($family_name) || empty($email) || empty($login) || empty($password1) || empty($password2)) { throw new ControllerException('Parameters missing.'); } // check given name if (!preg_match("/^([a-zA-Z]+[a-zA-Z' -]+[a-zA-Z']+)?\$/", $given_name)) { throw new ControllerException('Invalid firstname. allowed characters: \' -a-Z'); } // check family name if (!preg_match("/^([a-zA-Z]+[a-zA-Z' -]+[a-zA-Z']+)?\$/", $family_name)) { throw new ControllerException('Invalid lastname. allowed characters: \' -a-Z'); } // check email if (!preg_match("/^([a-zA-Z0-9._%+-]{1,30}@[a-zA-Z0-9.-]{1,30}\\.[a-zA-Z]{2,4})?\$/", $email)) { throw new ControllerException('Invalid email.'); } // check login if (!preg_match("/^([a-zA-Z]+[a-zA-Z0-9]{3,})?\$/", $login)) { throw new ControllerException('Invalid username. Only letters and numbers allowed.'); } // check if passwords match if ($password1 !== $password2) { throw new ControllerException('Please enter the same password twice.'); } // check password if (!preg_match("/^([a-zA-Z0-9\$%'-]{5,})?\$/", $password1)) { throw new ControllerException('Password invalid. Minimum of 5 characters. Allowed characters: a-Z0-9$%\'-'); } // create new user $verify = range(1, 10); shuffle($verify); $verify = $verify[0] . $verify[1] . $verify[2] . $verify[3] . $verify[4] . $verify[5] . $verify[6] . $verify[7] . $verify[8] . $verify[9]; $user = ModelUser::create($given_name, $family_name, $login, $password1, $email, $verify); // mail new user info to admin $to = ADMIN_MAIL; $subject = 'New Attack Online Account'; $from = '*****@*****.**'; $text = 'New User:'******'From:' . $from . "\n"; mail($to, $subject, $msg, $headers); // mail verification code to the user $verificationCode = $user->getVerify(); $id_newuser = $user->getUserId(); $to = $email; $subject = 'Activation-Link Attack Online Account'; $verificationLink = DOMAIN_ORIGIN . ABS_REF_PREFIX . 'verify/?user_id=' . $id_newuser . '&verificationCode=' . $verificationCode; $msg = '<html> <head> <title>Activation-Link Attack Online Account</title> </head> <body> <p> You just registered a new account at ' . DOMAIN_ORIGIN . '. To active the account please use the following link: <br /> <a href="' . $verificationLink . '"> ' . $verificationLink . ' </a> <br /> If you haven\'t created an account, please just ignore this mail. <br /> Your Attack Team </p> </body> </html>'; $headers = "Content-type: text/html\n"; mail($to, $subject, $msg, $headers); }