/**
  * Implementation of the signup logic.
  *
  * @param SignupRequest $p_request
  * @return ViewSpec
  * @throw \Runtimeexception account creation failed
  */
 private function doWork($p_request)
 {
     $preconfirm = self::preconfirm_some_emails($p_request->enteredEmail);
     $confirm = rand(1000, 9999);
     //generate confirmation code
     $player_params = ['send_email' => $p_request->enteredEmail, 'send_pass' => $p_request->enteredPass, 'send_class' => $p_request->enteredClass, 'preconfirm' => $preconfirm, 'confirm' => $confirm, 'referred_by' => $p_request->enteredReferral, 'ip' => $p_request->clientIP];
     // Create the player
     if ($error = create_account_and_ninja($p_request->enteredName, $player_params)) {
         throw new \RuntimeException($error, 4);
     }
     if ($preconfirm) {
         $completedPhase = 4;
         confirm_player($p_request->enteredName, false, true);
         // name, no confirm #, just autoconfirm.
         $confirmed = true;
     } else {
         $completedPhase = 5;
         $confirmed = false;
     }
     return ['template' => self::TEMPLATE, 'title' => self::TITLE, 'parts' => ['classes' => $this->classes, 'class_display' => class_display_name_from_identity($p_request->enteredClass), 'signupRequest' => $p_request, 'submit_successful' => true, 'completedPhase' => $completedPhase, 'confirmed' => $confirmed, 'submitted' => true, 'error' => ''], 'options' => ['quickstat' => false]];
 }
 public static function create_alternate_testing_account($confirm = false)
 {
     $ip = isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     if ((bool) get_char_id(TestAccountCreateAndDestroy::$alt_test_ninja_name)) {
         throw new Exception('Test user found [' . $found . '] with name [' . TestAccountCreateAndDestroy::$alt_test_ninja_name . '] already exists');
     }
     // Create test user, unconfirmed, whatever the default is for activity.
     $preconfirm = true;
     $confirm = rand(1000, 9999);
     //generate confirmation code
     // Use the function from lib_player
     $player_params = array('send_email' => TestAccountCreateAndDestroy::$alt_test_email, 'send_pass' => TestAccountCreateAndDestroy::$test_password, 'send_class' => 'dragon', 'preconfirm' => true, 'confirm' => $confirm, 'referred_by' => 'ninjawars.net', 'ip' => $ip);
     ob_start();
     // Skip extra output
     $error = create_account_and_ninja(TestAccountCreateAndDestroy::$alt_test_ninja_name, $player_params);
     ob_end_clean();
     if ($confirm) {
         $confirmed = confirm_player(TestAccountCreateAndDestroy::$alt_test_ninja_name, false, true);
         // name, no confirm #, just autoconfirm.
     }
     $char_id = get_char_id(TestAccountCreateAndDestroy::$alt_test_ninja_name);
     return $char_id;
 }
    /**
     * group accountconf
     **/
    function testPauseAccountAndLoginShouldFail()
    {
        $confirm_worked = confirm_player($this->test_ninja_name, false, true);
        // name, no confirm #, just autoconfirm.
        $this->assertTrue((bool) $confirm_worked);
        $char_id = get_char_id($this->test_ninja_name);
        $paused = @pauseAccount($char_id);
        // Fully pause the account, make the operational bit = false
        $this->assertTrue((bool) $paused);
        $account_operational = query_item('select operational from accounts 
				join account_players on account_id = _account_id where _player_id = :char_id', array(':char_id' => $char_id));
        $this->assertFalse($account_operational);
        $res = @login_user($this->test_email, $this->test_password);
        $this->assertFalse($res['success'], 'Login should not be successful when account is paused');
        $this->assertTrue(is_string($res['login_error']));
        $this->assertTrue((bool) $res['login_error']);
    }
Exemple #4
0
function validate_signup($enteredName, $enteredEmail, $enteredClass, $enteredReferral, $enteredPass)
{
    $successful = false;
    $sql = $GLOBALS['sql'];
    assert($sql);
    $send_name = $enteredName;
    $send_pass = $enteredPass;
    $send_class = $enteredClass;
    $send_email = $enteredEmail;
    $referred_by = $enteredReferral;
    echo "Your responses:<br> Name - {$send_name},<br>\n\t\t Password - " . (isset($send_pass) ? "***yourpassword***" : "NO PASSWORD") . ",<br>\n\t\t Class - {$send_class},<br>\n\t\t Email - {$send_email},<br>\n\t\t Site Referred By - {$referred_by}<br><br>\n";
    //  *** Requirement checking Section  ***
    if ($send_name != "" && $send_pass != "" && $send_email != "" && $send_class != "") {
        //When everything is non-blank.
        $check_name = 0;
        $check_email = 0;
        $sql->QueryItem("SELECT uname FROM players WHERE uname = '{$send_name}'");
        $check_name = $sql->getRowCount();
        $sql->QueryItem("SELECT email FROM players WHERE email = '{$send_email}'");
        $check_email = $sql->getRowCount();
        // Validate the username symbols!
        $username_error = validate_username($send_name);
        if ($username_error) {
            echo $username_error;
        } else {
            //when all the name requirement errors didn't trigger.
            $send_name = trim($send_name);
            // Just cuts off any white space at the end.
            $filter = new Filter();
            $send_name = $filter->toUsername($send_name);
            // Filter any un-whitelisted characters.
            echo "Phase 1 Complete: Name passes requirements.<hr>\n";
            // Validate the password!
            $password_error = validate_password($send_pass);
            if ($password_error) {
                echo $password_error;
            } else {
                $send_pass = trim($send_pass);
                // *** Trims any extra space off of the password.
                $send_pass = $filter->toPassword($send_pass);
                // Filter any un-whitelisted characters.
                echo "Phase 2 Complete: Password passes requirements.<hr>\n";
                if (FALSE) {
                    // CURRENTLY NO BLOCKED EMAIL SERVICES strstr($send_email, "@") == "@aol.com" || strstr($send_email, "@") == "@netscape.com" || strstr($send_email, "@") == "@aim.com"
                    //Throws error if email from blocked domain.
                    echo "Phase 3 Incomplete: We cannot currently accept @aol.com, @netscape.com, or @aim.com email addresses.";
                } elseif (!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\\.[a-z]{2,4}\$", trim($send_email))) {
                    echo "Phase 3 Incomplete: The email address (" . htmlentities($send_email) . ") \n\t\t\t\t\t    must contain an @ symbol and a domain name to be valid.";
                } else {
                    if ($check_name == 0 && $check_email == 0 && $send_name != "SysMsg" && $send_name != "NewUserList") {
                        //Uses previous query to make sure name and email aren't duplicates.
                        echo "Phase 3 Complete: Username and Email are unique.<br><hr>\n";
                        if ($send_class != 'Red' && $send_class != 'Blue' && $send_class != 'White' && $send_class != 'Black') {
                            echo "Phase 4 Incomplete: No proper class was specified.<br>";
                        } else {
                            echo "Phase 4 Complete: Class was specified.<br><hr>";
                            // *** Signup is successful at this point  ***
                            $preconfirm = 0;
                            $preconfirm = preconfirm_some_emails($send_email);
                            if (!$preconfirm) {
                                /* not blacklisted by, so require a normal email confirmation */
                                echo "Phase 5: When you receive an email from SysMsg,\n\t\t\t\t\t\t\t it will describe how to activate your account.<br><br>\n";
                            }
                            // The preconfirmation message occurs later.
                            $confirm = rand(1000, 9999);
                            //generate confirmation code
                            // Use the function from lib_player
                            $player_params = array('send_email' => $send_email, 'send_pass' => $send_pass, 'send_class' => $send_class, 'preconfirm' => $preconfirm, 'confirm' => $confirm, 'referred_by' => $referred_by);
                            $successful = create_player($send_name, $player_params);
                            // Create the player.
                            if (!$successful) {
                                echo "There was a problem with creating a player account.  Please contact us as below: ";
                            } else {
                                if (!$preconfirm) {
                                    //  *** Continues the page display ***
                                    echo "Confirmation email has been sent to <b>" . $send_email . "</b>.  <br>\n    \t\t\t\t  \t\t\t\t\tBe sure to also check for the email in any \"Junk Mail\" or \"Spam\" folders.\n    \t\t\t\t  \t\t\t\t\tDelivery typically takes less than 15 minutes.";
                                } else {
                                    // Use the confirm function from lib_player.
                                    confirm_player($send_name, false, true);
                                    // name, no confirm #, just autoconfirm.
                                    echo "<p>Account with the login name \"" . $send_name . "\" is now confirmed!  Please login on the login bar of the ninjawars.net page.</p>";
                                }
                                echo "<p>Only one account per person is allowed.</p>";
                            }
                            echo "If you require help use the forums at <a href='" . WEB_ROOT . "forum/'>" . WEB_ROOT . "forum/</a> or email: " . SUPPORT_EMAIL;
                        }
                        // *** End of class checking.
                    } else {
                        // Default, displays when the username or email are not unique.
                        $what = $check_email != 0 ? "Email" : "Username";
                        echo "Phase 3 Incomplete: That {$what} is already in use. Please choose a different one.\n";
                    }
                }
            }
        }
    } else {
        //  ***  Response for when nothing was submitted.  ***
        echo "Phase 1 Incomplete: You did not correctly fill out all the necessary information.\n";
    }
    //This is the final signup return section, which only shows if a successful
    //insert and confirmation number has -not- been acheived.
    echo "<br><br>";
    return $successful;
}
 /**
  * group accountconf
  */
 function testPauseAccountAndLoginShouldFail()
 {
     $accountController = new AccountController();
     $confirm_worked = confirm_player($this->test_ninja_name, false, true);
     // name, no confirm #, just autoconfirm.
     $this->assertTrue((bool) $confirm_worked);
     $char_id = get_char_id($this->test_ninja_name);
     $paused = $accountController->pauseAccount($char_id);
     // Fully pause the account, make the operational bit = false
     $this->assertTrue((bool) $paused);
     $account_operational = query_item('SELECT operational FROM accounts JOIN account_players ON account_id = _account_id WHERE _player_id = :char_id', [':char_id' => $char_id]);
     $this->assertFalse($account_operational);
     $res = login_user($this->test_email, $this->test_password);
     $this->assertFalse($res['success'], 'Login should not be successful when account is paused');
     $this->assertTrue(is_string($res['login_error']));
     $this->assertTrue((bool) $res['login_error']);
 }
Exemple #6
0
                 $confirm = rand(1000, 9999);
                 //generate confirmation code
                 Request::setTrustedProxies(Constants::$trusted_proxies);
                 $request = Request::createFromGlobals();
                 $ip = $request->getClientIp();
                 $player_params = array('send_email' => $enteredEmail, 'send_pass' => $enteredPass, 'send_class' => $enteredClass, 'preconfirm' => $preconfirm, 'confirm' => $confirm, 'referred_by' => $enteredReferral, 'ip' => $ip);
                 if ($error = create_account_and_ninja($enteredName, $player_params)) {
                     // Create the player.
                     if (!$error) {
                         $error = 'There was a problem with creating a player account. Please contact us as mentioned below: ';
                     }
                 } else {
                     $submit_successful = true;
                     if ($preconfirm) {
                         // Use the confirm function from lib_player.
                         confirm_player($enteredName, false, true);
                         // name, no confirm #, just autoconfirm.
                         $confirmed = true;
                     } else {
                         /* not blacklisted by, so require a normal email confirmation */
                         $completedPhase = 5;
                         $confirmed = false;
                     }
                 }
             }
             // phase 4
         }
         // phase 3
     }
     // phase 2
 }