/** * test grabbing a volunteer by Email Activation */ public function testGetVolunteerByVolEmailActivation() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("volunteer"); // create a new Volunteer and insert to into mySQL $volunteer = new Volunteer(null, $this->organization->getOrgId(), $this->VALID_EMAIL, $this->VALID_EMAIL_ACTIVATION, $this->VALID_FIRST_NAME, $this->VALID_HASH, $this->VALID_VOL_IS_ADMIN, $this->VALID_LAST_NAME, $this->VALID_PHONE, $this->VALID_SALT); $volunteer->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoVolunteer = Volunteer::getVolunteerByVolEmailActivation($this->getPDO(), $volunteer->getVolEmailActivation()); $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("volunteer")); $this->assertSame($pdoVolunteer->getOrgId(), $this->organization->getOrgId()); $this->assertSame($pdoVolunteer->getVolEmail(), $this->VALID_EMAIL); $this->assertSame($pdoVolunteer->getVolEmailActivation(), $this->VALID_EMAIL_ACTIVATION); $this->assertSame($pdoVolunteer->getVolFirstName(), $this->VALID_FIRST_NAME); $this->assertSame($pdoVolunteer->getVolHash(), $this->VALID_HASH); $this->assertSame($pdoVolunteer->getVolIsAdmin(), $this->VALID_VOL_IS_ADMIN); $this->assertSame($pdoVolunteer->getVolLastName(), $this->VALID_LAST_NAME); $this->assertSame($pdoVolunteer->getVolPhone(), $this->VALID_PHONE); $this->assertSame($pdoVolunteer->getVolSalt(), $this->VALID_SALT); }
$volunteer = Volunteer::getVolunteerByVolEmail($pdo, $volEmail); if ($volunteer !== null) { throw new RuntimeException("This email already has an account", 422); } // create a new salt and email activation $volSalt = bin2hex(openssl_random_pseudo_bytes(32)); $volEmailActivation = bin2hex(openssl_random_pseudo_bytes(8)); // create the hash $volHash = hash_pbkdf2("sha512", $requestObject->password, $volSalt, 262144, 128); //create a new organization and insert into mySQL $organization = new Organization(null, $requestObject->orgAddress1, $requestObject->orgAddress2, $requestObject->orgCity, $requestObject->orgDescription, $requestObject->orgHours, $requestObject->orgName, $requestObject->orgPhone, $requestObject->orgState, $requestObject->orgType, $requestObject->orgZip); $organization->insert($pdo); $reply->message = "New organization has been created"; //create a new Volunteer and insert into mySQL $volunteer = new Volunteer(null, $organization->getOrgId(), $requestObject->volEmail, $volEmailActivation, $requestObject->volFirstName, $volHash, true, $requestObject->volLastName, $requestObject->volPhone, $volSalt); $volunteer->insert($pdo); $reply->message = "A new administrator has been created"; if ($volunteer->getVolIsAdmin() === true) { $_SESSION["volunteer"] = $volunteer; $reply->status = 200; $reply->message = "Logged in as administrator"; } // create Swift message $swiftMessage = Swift_Message::newInstance(); // attach the sender to the message // this takes the form of an associative array where the Email is the key for the real name $swiftMessage->setFrom(["*****@*****.**" => "Bread Basket"]); /** * attach the recipients to the message * notice this an array that can include or omit the the recipient's real name * use the recipients' real name where possible; this reduces the probability of the Email being marked as spam
public function testValidPut() { //create a new volunteer, and insert into the database $volunteer = new Volunteer(null, $this->valid_org_id, $this->VALID_EMAIL, $this->VALID_EMAIL_ACTIVATION, $this->VALID_FIRST_NAME, $this->VALID_HASH, $this->VALID_ADMIN, $this->VALID_LAST_NAME, $this->VALID_PHONE, $this->VALID_SALT); $volunteer->insert($this->getPDO()); //update the volunteer $volunteer->setVolPhone($this->VALID_ALT_PHONE); //$volunteer->setVolEmail($this->VALID_ALT_EMAIL); // var_dump($volunteer->getVolId()); //send the info to update the API $response = $this->guzzle->put('https://bootcamp-coders.cnm.edu/~kkeller13/bread-basket/public_html/php/api/volunteer/' . $volunteer->getVolId(), ['allow-redirects' => ['strict' => true], 'json' => $volunteer, 'headers' => ['X-XSRF-TOKEN' => $this->token]]); // var_dump($response); $newVolunteer = Volunteer::getVolunteerByVolId($this->getPDO(), $volunteer->getVolId()); var_dump($newVolunteer); //ensure the response was sent, and the api returned a positive status $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); var_dump((string) $response->getBody()); $retrievedVol = json_decode($body); // var_dump($retrievedVol); $this->assertSame(200, $retrievedVol->status); //pull the value from the DB, and make sure it was properly updated $newvol = Volunteer::getVolunteerByVolId($this->getPDO(), $volunteer->getVolId()); $this->assertSame($newvol->getVolPhone(), $this->VALID_ALT_PHONE); }