Ejemplo n.º 1
0
     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
  **/
 $recipients = [$requestObject->volEmail];
Ejemplo n.º 2
0
 /**
  * test grabbing a volunteer by "Volunteer is Administrator"; volIsAdmin
  */
 public function testGetValidVolIsAdmin()
 {
     // 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::getVolunteerByVolIsAdmin($this->getPDO(), $volunteer->getVolIsAdmin());
     $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("volunteer"));
     $this->assertSame($pdoVolunteer[0]->getOrgId(), $this->organization->getOrgId());
     $this->assertSame($pdoVolunteer[0]->getVolEmail(), $this->VALID_EMAIL);
     $this->assertSame($pdoVolunteer[0]->getVolEmailActivation(), $this->VALID_EMAIL_ACTIVATION);
     $this->assertSame($pdoVolunteer[0]->getVolFirstName(), $this->VALID_FIRST_NAME);
     $this->assertSame($pdoVolunteer[0]->getVolHash(), $this->VALID_HASH);
     $this->assertSame($pdoVolunteer[0]->getVolIsAdmin(), $this->VALID_VOL_IS_ADMIN);
     $this->assertSame($pdoVolunteer[0]->getVolLastName(), $this->VALID_LAST_NAME);
     $this->assertSame($pdoVolunteer[0]->getVolPhone(), $this->VALID_PHONE);
     $this->assertSame($pdoVolunteer[0]->getVolSalt(), $this->VALID_SALT);
 }