public function btnRegister_Click($strFormId, $strControlId, $strParameter)
 {
     if (!trim($this->txtUsername->Text) || !trim($this->txtPassword->Text)) {
         $this->lblMessage->ForeColor = 'red';
         $this->lblMessage->Text = t("It's just three fields, don't leave one empty please.");
         return false;
     }
     try {
         $objUser = NarroUser::RegisterUser($this->txtUsername->Text, $this->txtEmail->Text, $this->txtPassword->Text, $this->txtRealname->Text);
     } catch (Exception $objEx) {
         $this->lblMessage->ForeColor = 'red';
         $this->lblMessage->Text = t("Seems like the username or email is already in use.") . $objEx->getMessage();
         return false;
     }
     if (!$objUser instanceof NarroUser) {
         QApplication::Redirect(sprintf('login.php?l=%s', QApplication::$TargetLanguage->LanguageCode));
     }
     QApplication::$Session->User = $objUser;
     QApplication::Redirect(NarroLink::UserPreferences($objUser->UserId));
 }
 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';
     }
 }