コード例 #1
0
 /**
  * test grabbing a user by userEmail
  **/
 public function testGetValidUserByUserEmail()
 {
     //count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("user");
     //create a new user and insert into mySQL
     $user = new User(null, $this->company->getCompanyId(), $this->crew->getCrewId(), $this->access->getAccessId(), $this->VALID_USERPHONE, $this->VALID_USERFIRSTNAME, $this->VALID_USERLASTNAME, $this->VALID_USEREMAIL, $this->VALID_USERACTIVATION, $this->VALID_USERHASH, $this->VALID_USERSALT);
     $user->insert($this->getPDO());
     //grab the data from mySQL and enforce the fields match our expectations
     $results = User::getUserByUserEmail($this->getPDO(), $user->getUserEmail());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("user"));
     $this->assertEquals($results->getUserCompanyId(), $this->company->getCompanyId());
     $this->assertEquals($results->getUserCrewId(), $this->crew->getCrewId());
     $this->assertEquals($results->getUserAccessId(), $this->access->getAccessId());
     $this->assertSame($results->getUserPhone(), $this->VALID_USERPHONE);
     $this->assertSame($results->getUserFirstName(), $this->VALID_USERFIRSTNAME);
     $this->assertSame($results->getUserLastName(), $this->VALID_USERLASTNAME);
     $this->assertSame($results->getUserEmail(), $this->VALID_USEREMAIL);
     $this->assertEquals($results->getUserActivation(), $this->VALID_USERACTIVATION);
     $this->assertEquals($results->getUserHash(), $this->VALID_USERHASH);
     $this->assertEquals($results->getUserSalt(), $this->VALID_USERSALT);
 }
コード例 #2
0
                        $hash = hash_pbkdf2("sha512", $password, $salt, 262144);
                        $emailActivation = bin2hex(random_bytes(16));
                        //create new user
                        $user = new User(null, $_SESSION["company"]->getCompanyId(), $requestObject->userCrewId, $requestObject->userAccessId, $requestObject->userPhone, $requestObject->userFirstName, $requestObject->userLastName, $requestObject->userEmail, $emailActivation, $hash, $salt);
                        $user->insert($pdo);
                        //building the activation link that can travel to another server and still work. This is the link that will be clicked to confirm the account.
                        $basePath = dirname($_SERVER["SCRIPT_NAME"], 4);
                        $urlglue = $basePath . "/activation/?emailActivation=" . $user->getUserActivation();
                        $confirmLink = "https://" . $_SERVER["SERVER_NAME"] . $urlglue;
                        $messageSubject = "This is an important message about your account activation.";
                        $message = <<<EOF
<h1>You've been registered for the Timecrunchers Scheduling!</h1>
<p>Visit the following URL to set a new password and complete the registration process: </p>
<p><a href="{$confirmLink}">{$confirmLink}</a></p>
EOF;
                        $response = sendEmail($user->getUserEmail(), $user->getUserFirstName(), $user->getUserLastName(), $messageSubject, $message);
                        if ($response === "Email sent.") {
                            $reply->message = "sign up was successful, please check your email for activation message.";
                        }
                        /**
                         * the send method returns the number of recipients that accepted the Email
                         * so, if the number attempted is not the number accepted, this is an Exception
                         **/
                    }
                }
            } else {
                if ($method === "DELETE") {
                    $reply->debug = "delete started";
                    $user = User::getUserByUserId($pdo, $id);
                    if ($user === null) {
                        throw new RuntimeException("User does not exist", 404);