/** * @param AuthorizedPage $Page * @param string $Email * @param string $AccessCode * @param string $ClientKey * @param string $ClientInfo * @return Authorization|boolean */ public static function Fetch(AuthorizedPage $Page, $Email, $AccessCode, $ClientKey = null, $ClientInfo = null) { if (!$Page || !$Page->ID || !$Page->IsAllowedEmail(strtolower($Email))) { return false; } return Authorization::get()->filter(array('PageID' => $Page->ID, 'Email' => strtolower($Email), 'AccessCode' => strtoupper($AccessCode), 'ClientKey' => $ClientKey ? $ClientKey : Authorization::generateClientKey(), 'ClientInfo' => $ClientInfo ? $ClientInfo : Authorization::generateClientInfo()))->First(); }
public function new_authorization() { // < 5.5 compat, as empty() only supports vars $postVars = $this->request->postVars(); if (empty($postVars) || !$this->data()) { return $this->redirectBack(); } unset($postVars); //clear var as we're using the method // We will create an authorization EVEN IF the email is not allowed. // This allows us to see who requested access, even if they're not allowed. // But, we email email them the access code. $email = strtolower($this->request->postVar('Email')); $Auth = Authorization::get()->filter(array('PageID' => $this->ID, 'Email' => $email, 'ClientKey' => Authorization::generateClientKey(), 'ClientInfo' => Authorization::generateClientInfo()))->First(); if (!$Auth) { $Auth = new Authorization(); $Auth->PageID = $this->ID; $Auth->Email = $email; $Auth->write(); } if ($this->data()->IsAllowedEmail($email)) { $Auth->EmailAuthorization(); } $Auth->write(); // Write for both so it updates EmailSent time return $this->redirect($this->data()->AbsoluteLink() . '?Email=' . rawurlencode($email) . '&EmailSent'); }