public function btnBrowserIdLogin_Click($strFormId, $strControlId, $strAssertion) { // open connection $ch = curl_init(); // set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, 'https://browserid.org/verify'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 2); curl_setopt($ch, CURLOPT_POSTFIELDS, sprintf('assertion=%s&audience=%s', $strAssertion, __HTTP_URL__)); // execute post $result = json_decode(curl_exec($ch)); // close connection curl_close($ch); if ($result && property_exists($result, 'status') && $result->status == 'okay') { $objUser = NarroUser::LoadByUsername($result->email); if (!$objUser instanceof NarroUser) { try { $objUser = NarroUser::RegisterUser($result->email, $result->email, '', $result->email); } catch (Exception $objEx) { $this->lblMessage->ForeColor = 'red'; $this->lblMessage->Text = sprintf(t('Failed to create an associated user for the email address "%s": %s'), $result->email, $objEx->getMessage()); return false; } $objUser->Reload(); QApplication::$Session->User = $objUser; QApplication::Redirect(NarroLink::UserPreferences($objUser->UserId)); exit; } elseif ($objUser->Password != $objHasher->HashPassword('')) { $this->lblMessage->ForeColor = 'red'; $this->lblMessage->Text = t('This user has a password set, please login with that instead'); return false; } QApplication::$Session->RegenerateId(); QApplication::$Session->User = $objUser; QApplication::$User = $objUser; if ($this->txtPreviousUrl) { $strUrl = preg_replace('/([\\?\\&]l\\=)[a-z0-9\\-\\_]+/', '\\1' . QApplication::$User->GetPreferenceValueByName('Language'), $this->txtPreviousUrl); if ($strUrl) { QApplication::Redirect($strUrl); } else { QApplication::Redirect($this->txtPreviousUrl); } } else { QApplication::Redirect(NarroLink::ProjectList(null, null, QApplication::$User->GetPreferenceValueByName('Language'))); } exit; } else { $this->lblMessage->Text = t('BrowserID login failed'); $this->lblMessage->ForeColor = 'red'; } }
/** * This Form_Validate event handler allows you to specify any custom Form Validation rules. * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control. */ protected function Form_Validate() { // By default, we report the result of validation from the parent $blnToReturn = parent::Form_Validate(); // Custom Validation Rules // TODO: Be sure to set $blnToReturn to false if any custom validation fails! // Check for records that may violate Unique Clauses if (($objNarroUser = NarroUser::LoadByUsername($this->txtUsername->Text)) && $objNarroUser->UserId != $this->mctNarroUser->NarroUser->UserId) { $blnToReturn = false; $this->txtUsername->Warning = QApplication::Translate("Already in Use"); } if (($objNarroUser = NarroUser::LoadByEmail($this->txtEmail->Text)) && $objNarroUser->UserId != $this->mctNarroUser->NarroUser->UserId) { $blnToReturn = false; $this->txtEmail->Warning = QApplication::Translate("Already in Use"); } if (($objNarroUser = NarroUser::LoadByRealName($this->txtRealName->Text)) && $objNarroUser->UserId != $this->mctNarroUser->NarroUser->UserId) { $blnToReturn = false; $this->txtRealName->Warning = QApplication::Translate("Already in Use"); } $blnFocused = false; foreach ($this->GetErrorControls() as $objControl) { // Set Focus to the top-most invalid control if (!$blnFocused) { $objControl->Focus(); $blnFocused = true; } // Blink on ALL invalid controls $objControl->Blink(); } return $blnToReturn; }