Ejemplo n.º 1
0
 protected function Form_Create()
 {
     parent::Form_Create();
     if (QApplication::GetUserId() == NarroUser::ANONYMOUS_USER_ID) {
         $strPassHash = QApplication::QueryString('h');
         $strUsername = QApplication::QueryString('u');
         if ($strPassHash && $strUsername) {
             $objUser = NarroUser::LoadByUsernameAndPassword($strUsername, $strPassHash);
             if ($objUser instanceof NarroUser) {
                 QApplication::$User = $objUser;
             } else {
                 QApplication::Redirect('login.php');
             }
         } else {
             QApplication::Redirect('login.php');
         }
     }
     $this->lblMessage = new QLabel($this);
     $this->lblMessage->HtmlEntities = false;
     $this->txtPassword = new QTextBox($this);
     $this->txtPassword->TextMode = QTextMode::Password;
     $this->btnChangePassword = new QButton($this);
     $this->btnChangePassword->PrimaryButton = true;
     $this->btnChangePassword->Text = t('Change password');
     $this->btnChangePassword->AddAction(new QClickEvent(), new QServerAction('btnChangePassword_Click'));
 }
Ejemplo n.º 2
0
 protected function Form_Create()
 {
     if (isset($_GET['logout'])) {
         session_destroy();
         QApplication::Redirect('word_list.php');
     }
     $this->lblMessage = new QLabel($this);
     $this->lblMessage->HtmlEntities = false;
     $this->txtOpenIdUrl = new QTextBox($this, 'username');
     $this->txtOpenIdUrl->TabIndex = 1;
     $this->btnLogin = new QButton($this);
     $this->btnLogin->Text = 'Autentificare';
     $this->btnLogin->PrimaryButton = true;
     $this->btnLogin->TabIndex = 3;
     $this->btnLogin->AddAction(new QClickEvent(), new QServerAction('btnLogin_Click'));
     if (isset($_REQUEST['openid_mode'])) {
         require_once "Zend/Auth.php";
         require_once "Zend/Auth/Adapter/OpenId.php";
         require_once "Zend/Auth/Storage/NonPersistent.php";
         $auth = Zend_Auth::getInstance();
         $auth->authenticate(new Zend_Auth_Adapter_OpenId($this->txtOpenIdUrl->Text));
         if ($auth->hasIdentity()) {
             require_once 'Zend/Session/Namespace.php';
             $objSession = new Zend_Session_Namespace('SubmitWord');
             $objSession->User = $auth->getIdentity();
             QApplication::$User = $auth->getIdentity();
             QApplication::Redirect('word_list.php');
         } else {
             $this->lblMessage->ForeColor = 'red';
             $this->lblMessage->Text = 'N-am primit nicio identitate, astea sunt datele primite: ' . var_export($auth, true);
             return false;
         }
     }
     // Instantiate the Meta DataGrid
     $this->dtgWords = new WordDataGrid($this);
     // Style the DataGrid (if desired)
     $this->dtgWords->CssClass = 'datagrid';
     $this->dtgWords->AlternateRowStyle->CssClass = 'alternate';
     // Add Pagination (if desired)
     $this->dtgWords->Paginator = new QPaginator($this->dtgWords);
     $this->dtgWords->ItemsPerPage = 20;
     $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/word_edit.php';
     // Create the Other Columns (note that you can use strings for submit_word_word's properties, or you
     // can traverse down QQN::submit_word_word() to display fields that are down the hierarchy)
     $this->dtgWords->MetaAddColumn('WordId', 'Name=Id');
     if (QApplication::$User) {
         $this->dtgWords->MetaAddColumn('Word', 'Name=Cuvânt', 'HtmlEntities=false', 'Html=<?= \'<a href="' . $strEditPageUrl . '/\' . $_ITEM->WordId . \'">\' . $_ITEM->Word . \'</a>\'?>');
     } else {
         $this->dtgWords->MetaAddColumn('Word', 'Name=Cuvânt');
     }
     $this->dtgWords->MetaAddTypeColumn('StatusTypeId', 'StatusType', 'Name=Stare');
     $this->dtgWords->MetaAddColumn('ProposalCount', 'Name=Propuneri');
     $this->dtgWords->MetaAddColumn('LastSent', 'Name=Ultima propunere');
 }
Ejemplo n.º 3
0
 if (array_search('--translation-lang', $argv) !== false) {
     $strTargetLanguage = $argv[array_search('--translation-lang', $argv) + 1];
 }
 if (array_search('--user', $argv) !== false) {
     $intUserId = $argv[array_search('--user', $argv) + 1];
 }
 $objUser = NarroUser::LoadByUserId($intUserId);
 if (!$objUser instanceof NarroUser) {
     NarroLogger::LogInfo(sprintf('User id=%s does not exist in the database, will try to use the anonymous user.', $intUserId));
     $objUser = NarroUser::LoadAnonymousUser();
     if (!$objUser instanceof NarroUser) {
         NarroLogger::LogInfo(sprintf('The anonymous user id=%s does not exist in the database.', $intUserId));
         return false;
     }
 }
 QApplication::$User = $objUser;
 $objProject = NarroProject::Load($intProjectId);
 if (!$objProject instanceof NarroProject) {
     NarroLogger::LogInfo(sprintf('Project with id=%s does not exist in the database.', $intProjectId));
     return false;
 }
 $objLanguage = NarroLanguage::LoadByLanguageCode($strTargetLanguage);
 if (!$objLanguage instanceof NarroLanguage) {
     NarroLogger::LogInfo(sprintf('Language %s does not exist in the database.', $strTargetLanguage));
     return false;
 }
 QApplication::$TargetLanguage = $objLanguage;
 $objNarroImporter->TargetLanguage = $objLanguage;
 NarroLogger::LogInfo(sprintf('Target language is %s', $objNarroImporter->TargetLanguage->LanguageName));
 $objNarroImporter->SourceLanguage = NarroLanguage::LoadByLanguageCode($strSourceLanguage);
 if (!$objNarroImporter->SourceLanguage instanceof NarroLanguage) {
Ejemplo n.º 4
0
 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';
     }
 }
Ejemplo n.º 5
0
 public static function InitializeUser()
 {
     global $argv;
     if (QApplication::$Session->User) {
         QApplication::$User = QApplication::$Session->User;
     } elseif (is_array($argv) && array_search('--user', $argv) !== false) {
         QApplication::$User = NarroUser::LoadByUserId((int) $argv[array_search('--user', $argv) + 1]);
     }
     if (!QApplication::$User instanceof NarroUser) {
         QApplication::$User = NarroUser::LoadAnonymousUser();
         QApplication::$Session->User = QApplication::$User;
     }
     if (!QApplication::$User instanceof NarroUser) {
         // @todo add handling here
         throw new Exception('Could not create an instance of NarroUser');
     }
 }
Ejemplo n.º 6
0
 // Initialize the Application and DB Connections
 ////////////////////////////////////////////////
 QApplication::Initialize();
 QApplication::InitializeDatabaseConnections();
 /////////////////////////////
 // Start Session Handler (if required)
 /////////////////////////////
 if (strstr($_SERVER['SCRIPT_NAME'], 'codegen.php') === false) {
     /////////////////////////////
     // Start Session Handler (if required)
     /////////////////////////////
     require_once 'Zend/Session.php';
     Zend_Session::setOptions(array('cookie_lifetime' => 31 * 24 * 3600, 'gc_maxlifetime' => 31 * 24 * 3600));
     require_once 'Zend/Session/Namespace.php';
     $objSession = new Zend_Session_Namespace('SubmitWord');
     QApplication::$User = $objSession->User;
 }
 //////////////////////////////////////////////
 // Setup Internationalization and Localization (if applicable)
 // Note, this is where you would implement code to do Language Setting discovery, as well, for example:
 // * Checking against $_GET['language_code']
 // * checking against session (example provided below)
 // * Checking the URL
 // * etc.
 // TODO: options to do this are left to the developer
 //////////////////////////////////////////////
 QApplication::$CountryCode = 'ro';
 QApplication::$LanguageCode = 'ro';
 // Initialize I18n if QApplication::$LanguageCode is set
 if (QApplication::$LanguageCode) {
     QI18n::Initialize();