Exemplo n.º 1
0
 public function insert($welcomeForm = NULL, $params = NULL)
 {
     $sqlParams = array();
     $sqlParams[] = $this->expoid;
     $sqlParams[] = swwat_format_isodate($this->expirationDate);
     $sqlParams[] = hashField($this->code);
     $sqlParams[] = $this->workerid;
     // null or not, is good
     if (is_null($this->workerid)) {
         $sqlParams[] = $this->email;
         $sqlParams[] = $this->phone;
         $sqlParams[] = $this->firstName;
         $sqlParams[] = $this->middleName;
         $sqlParams[] = $this->lastName;
     } else {
         $sqlParams[] = NULL;
         // email
         $sqlParams[] = NULL;
         // phone
         $sqlParams[] = NULL;
         // firstName
         $sqlParams[] = NULL;
         // middleName
         $sqlParams[] = NULL;
         // lastName
     }
     try {
         $dbh = getPDOConnection();
         $dbh->beginTransaction();
         $stmt = $dbh->prepare("INSERT INTO invitation (expoid, expirationDate, code, workerid, " . " email, phone, firstName, middleName, lastName) VALUES " . " (?, ?, ?, ?, lower(?), ?, ?, ?, ?)");
         $stmt->execute($sqlParams);
         $dbh->commit();
         if (!is_null($welcomeForm)) {
             $welcomeForm->sendForm($this->email, $params);
         }
         return $this;
     } catch (PDOException $pe) {
         logMessage('Invitation::insert()', $pe->getMessage());
     }
 }
Exemplo n.º 2
0
 /**
  * This method does NOT call FormMail::sendPasswordReset;
  * that is the responsibility of the calling function.
  */
 public static function password_reset($email)
 {
     try {
         $dbh = getPDOConnection();
         $stmt = $dbh->prepare("SELECT isDisabled, externalAuthentication FROM worker WHERE lower(email) = lower(?)");
         $stmt->execute(array($email));
         $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
         if (count($rows) == 0) {
             throw new Exception('Can not find worker account.');
         } else {
             if (count($rows) > 1) {
                 throw new Exception('There are more than one worker account with the same email address.');
             }
         }
         $isDisabled = $rows[0]['isDisabled'];
         $externalAuthentication = $rows[0]['externalAuthentication'];
         if ($isDisabled == TRUE) {
             throw new Exception('Worker account is disabled.');
         }
         if ($externalAuthentication == TRUE) {
             throw new Exception('This worker account uses external authentication.');
         }
         $resetCodeHash = self::generate_random_password();
         $dbh->beginTransaction();
         // note the reset forces pw NULL
         $stmt = $dbh->prepare("UPDATE worker SET passwordHash = NULL, resetCodeHash = ? WHERE lower(email) = lower(?)");
         $stmt->execute(array(hashField($resetCodeHash), $email));
         $dbh->commit();
         return $resetCodeHash;
     } catch (PDOException $pe) {
         // do NOT log password
         logMessage('WorkerLogin::password_reset(' . $email . ')', $pe->getMessage());
     }
     return NULL;
 }