/** * This will create a provisional PublicLogin record, including setting up the hash. * NOTE: If the PublicLogin record already exists AND it is a non-provisional one, then this will throw an error * Otherwise, if the PublicLogin exists as a provisional one, it will simply overwrite the provisioned info. * * @param string $strUsername * @param string $strEmailAddress * @param string $strFirstName * @param string $strLastName * @return ProvisionalPublicLogin */ public static function CreateProvisional($strUsername, $strEmailAddress, $strFirstName, $strLastName) { $strEmailAddress = trim(strtolower($strEmailAddress)); $strUsername = QApplication::Tokenize($strUsername, false); if (strlen($strUsername) < 4) { throw new QCallerException('Username is too short: ' . $strUsername); } if (!self::IsProvisionalCreatableForUsername($strUsername)) { throw new QCallerException('Username is already taken: ' . $strUsername); } // Perform the Creation Tasks within a Single Transaction try { PublicLogin::GetDatabase()->TransactionBegin(); // Delete any other provisional login using this email address with a different username foreach (ProvisionalPublicLogin::QueryArray(QQ::Equal(QQN::ProvisionalPublicLogin()->EmailAddress, $strEmailAddress)) as $objProvisionalPublicLogin) { if ($objProvisionalPublicLogin->PublicLogin->Username != $strUsername) { $objPublicLogin = $objProvisionalPublicLogin->PublicLogin; $objProvisionalPublicLogin->Delete(); $objPublicLogin->Delete(); } } // Be sure to reuse the username record if applicable $objPublicLogin = PublicLogin::LoadByUsername($strUsername); $blnChangeHash = true; if ($objPublicLogin) { if ($objPublicLogin->ProvisionalPublicLogin->EmailAddress == $strEmailAddress) { $blnChangeHash = false; } $objProvisionalPublicLogin = $objPublicLogin->ProvisionalPublicLogin; $objPublicLogin->DateRegistered = QDateTime::Now(); $objPublicLogin->Save(); } else { $objPublicLogin = new PublicLogin(); $objPublicLogin->ActiveFlag = true; $objPublicLogin->Username = $strUsername; $objPublicLogin->DateRegistered = QDateTime::Now(); $objPublicLogin->Save(); $objProvisionalPublicLogin = new ProvisionalPublicLogin(); $objProvisionalPublicLogin->PublicLogin = $objPublicLogin; } // Update Values $objProvisionalPublicLogin->FirstName = trim($strFirstName); $objProvisionalPublicLogin->LastName = trim($strLastName); $objProvisionalPublicLogin->EmailAddress = trim($strEmailAddress); if ($blnChangeHash) { $objProvisionalPublicLogin->UrlHash = md5(microtime()); $objProvisionalPublicLogin->ConfirmationCode = rand(1000, 9999); } $objProvisionalPublicLogin->Save(); PublicLogin::GetDatabase()->TransactionCommit(); $objProvisionalPublicLogin->SendConfirmationEmail(); return $objProvisionalPublicLogin; } catch (Exception $objExc) { PublicLogin::GetDatabase()->TransactionRollBack(); throw $objExc; } }
/** * Gets the historical journal for an object from the log database. * Objects will have VirtualAttributes available to lookup login, date, and action information from the journal object. * @param integer intId * @return PublicLogin[] */ public static function GetJournalForId($intId) { $objDatabase = PublicLogin::GetDatabase()->JournalingDatabase; $objResult = $objDatabase->Query('SELECT * FROM public_login WHERE id = ' . $objDatabase->SqlVariable($intId) . ' ORDER BY __sys_date'); return PublicLogin::InstantiateDbResult($objResult); }