示例#1
0
文件: account.php 项目: Jobava/narro
 protected function Form_Create()
 {
     parent::Form_Create();
     if (QApplication::GetUserId() == NarroUser::ANONYMOUS_USER_ID) {
         QApplication::Redirect(NarroLink::ProjectList());
         exit;
     }
     if (QApplication::GetUserId() != QApplication::QueryString('u') && QApplication::HasPermissionForThisLang('Can manage users', null)) {
         $this->objUser = NarroUser::Load(QApplication::QueryString('u'));
     }
     if (!$this->objUser instanceof NarroUser) {
         $this->objUser = QApplication::$User;
     }
     $this->pnlBreadcrumb->setElements(NarroLink::ProjectList(t('Projects')), NarroLink::UserList('', t('Users')), $this->objUser->RealName);
     $this->pnlTab = new QTabs($this);
     new QPanel($this->pnlTab);
     $arrHeaders[] = NarroLink::UserProfile($this->objUser->UserId, t('Profile'));
     if (QApplication::GetUserId() == $this->objUser->UserId || QApplication::HasPermissionForThisLang('Can manage users', null)) {
         new QPanel($this->pnlTab);
         $arrHeaders[] = NarroLink::UserPreferences($this->objUser->UserId, t('Preferences'));
     }
     new QPanel($this->pnlTab);
     $arrHeaders[] = NarroLink::UserRole($this->objUser->UserId, t('Roles'));
     if (QApplication::GetUserId() == $this->objUser->UserId || QApplication::HasPermissionForThisLang('Can manage users', null)) {
         $this->pnlUser = new NarroUserEditPanel($this->objUser, $this->pnlTab);
         $arrHeaders[] = NarroLink::UserEdit($this->objUser->UserId, t('Edit'));
         $this->pnlTab->Selected = count($arrHeaders) - 1;
     }
     $this->pnlTab->Headers = $arrHeaders;
 }
 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';
     }
 }
示例#4
0
<?php

/**
 * Narro is an application that allows online software translation and maintenance.
 * Copyright (C) 2008-2011 Alexandru Szasz <*****@*****.**>
 * http://code.google.com/p/narro/
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
$this->objDefaultWaitIcon->Render();
if (QApplication::GetUserId() == NarroUser::ANONYMOUS_USER_ID) {
    echo sprintf(t('Translating in %s'), $_CONTROL->lstLanguage->ItemCount > 1 ? $_CONTROL->lstLanguage->Render(false) : $_CONTROL->lstLanguage->GetItem(0)->Name) . sprintf(', <a href="%s">' . t('sign in') . '</a>', 'login.php?l=' . QApplication::$TargetLanguage->LanguageCode);
} else {
    echo sprintf(t('Translating in %s as %s'), $_CONTROL->lstLanguage->ItemCount > 1 ? $_CONTROL->lstLanguage->Render(false) : $_CONTROL->lstLanguage->GetItem(0)->Name, sprintf(' <a title="%s" href="%s"><b>%s</b></a> ', t('Profile'), NarroLink::UserProfile(QApplication::$User->UserId), QApplication::$User->RealName ? QApplication::$User->RealName : QApplication::$User->RealName) . sprintf('<a title="%s" href="%s" style="vertical-align:middle"><img src="%s/settings.png" /></a>', t('Preferences'), NarroLink::UserPreferences(QApplication::GetUserId()), __NARRO_IMAGE_ASSETS__) . ' ' . $_CONTROL->btnLogout->Render(false));
}