Example #1
0
 public static function register()
 {
     //If form hasn't been posted, return form...
     if (!isset($_POST['username'])) {
         return User::processRegisterForm();
     }
     //Check if form was filled out completely...
     if ($_POST['username'] == '') {
         return User::processRegisterForm(User::config('register_no_username_error'), NULL, $_POST['email']);
     }
     if ($_POST['email'] == '') {
         return User::processRegisterForm(User::config('register_no_email_error'), $_POST['username']);
     }
     if ($_POST['password'] == '') {
         return User::processRegisterForm(User::config('register_no_password_error'), $_POST['username'], $_POST['email']);
     }
     if ($_POST['passwordConfirm'] == '') {
         return User::processRegisterForm(User::config('register_no_confirm_password_error'), $_POST['username'], $_POST['email']);
     }
     //Check if entered details are valid...
     if (!User::validateUsername($_POST['username'])) {
         return User::processRegisterForm(User::config('register_invalid_username_error'), NULL, $_POST['email']);
     }
     if (!User::validateEmail($_POST['email'])) {
         return User::processRegisterForm(User::config('register_invalid_email_error'), $_POST['username']);
     }
     if (!User::validatePassword($_POST['password'])) {
         return User::processRegisterForm(User::config('register_invalid_password_error'), $_POST['username'], $_POST['email']);
     }
     //Check if username & email are available...
     if (!User::availableUsername($_POST['username'])) {
         return User::processRegisterForm(User::config('register_unavailable_username_error'), NULL, $_POST['email']);
     }
     if (!User::availableEmail($_POST['email'])) {
         return User::processRegisterForm(User::config('register_unavailable_email_error'), $_POST['username']);
     }
     //Ensure passwords match...
     if ($_POST['password'] != $_POST['passwordConfirm']) {
         return User::processRegisterForm(User::config('register_password_mismatch_error'), $_POST['username'], $_POST['email']);
     }
     //Add user to the usersPending table..
     User::addPending($_POST['username'], $_POST['password'], $_POST['email']);
     //Process any onRegister callbacks, passing them, at present, nothing...
     User::processEventHandlers('onRegister');
     return User::config('register_success_template');
 }