public function btnRecoverPassword_Click($strFormId, $strControlId, $strParameter)
 {
     if ($this->txtEmail->Text) {
         $objUser = NarroUser::QuerySingle(QQ::Equal(QQN::NarroUser()->Email, $this->txtEmail->Text));
     } elseif ($this->txtUsername->Text) {
         $objUser = NarroUser::QuerySingle(QQ::Equal(QQN::NarroUser()->Username, $this->txtUsername->Text));
     } else {
         $this->lblMessage->ForeColor = 'red';
         $this->lblMessage->Text = t('Please enter a username or email to continue.');
         return false;
     }
     if ($objUser instanceof NarroUser) {
         if ($objUser->UserId == NarroUser::ANONYMOUS_USER_ID) {
             $this->lblMessage->ForeColor = 'red';
             $this->lblMessage->Text = t('Hey, the anonymous user doesn\'t have a password. What are you trying to do?');
             return false;
         }
         $objMessage = new QEmailMessage();
         $objMessage->From = sprintf('%s <%s>', __FROM_EMAIL_NAME__, __FROM_EMAIL_ADDRESS__);
         $objMessage->To = sprintf('%s <%s>', $objUser->Username, $objUser->Email);
         $objMessage->Subject = sprintf('Password recovery for "%s" on "%s"', $objUser->Username, $_SERVER['HTTP_HOST']);
         $objMessage->Body = sprintf('Somebody, probably you, requested a password recovery for "%s" on "%s". To change your password, please follow this link: %s', $objUser->Username, $_SERVER['HTTP_HOST'], (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . sprintf('/change_password.php?l=%s&u=%s&h=%s', QApplication::$TargetLanguage->LanguageCode, $objUser->Username, $objUser->Password));
         try {
             QEmailServer::Send($objMessage);
             $this->lblMessage->ForeColor = 'green';
             $this->lblMessage->Text = t('You should have a new email message with instructions. Check your spam/bulk directory too.');
         } catch (Exception $objEx) {
             $this->lblMessage->ForeColor = 'red';
             $this->lblMessage->Text = t('Failed to send email. This may be a server issue. Please try again later.');
             return false;
         }
     } else {
         $this->lblMessage->ForeColor = 'red';
         $this->lblMessage->Text = t('Bad username or/and email');
     }
 }
示例#2
0
 public function dtgUser_Bind()
 {
     if ($this->txtSearch->Text != '') {
         $objSearchCondition = QQ::OrCondition(QQ::Like(QQN::NarroUser()->RealName, sprintf('%%%s%%', $this->txtSearch->Text)), QQ::Like(QQN::NarroUser()->Username, sprintf('%%%s%%', $this->txtSearch->Text)), QQ::Like(QQN::NarroUser()->Email, sprintf('%%%s%%', $this->txtSearch->Text)));
     } else {
         $objSearchCondition = QQ::All();
     }
     // Because we want to enable pagination AND sorting, we need to setup the $objClauses array to send to LoadAll()
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     $this->dtgUser->TotalItemCount = NarroUser::QueryCount($objSearchCondition);
     // Setup the $objClauses Array
     $objClauses = array();
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->dtgUser->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->dtgUser->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be the array of all NarroUser objects, given the clauses above
     $this->dtgUser->DataSource = NarroUser::QueryArray($objSearchCondition, $objClauses);
     QApplication::ExecuteJavaScript('highlight_datagrid();');
 }
示例#3
0
 /**
  * Load a single NarroUser object,
  * by RealName Index(es)
  * @param string $strRealName
  * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  * @return NarroUser
  */
 public static function LoadByRealName($strRealName, $objOptionalClauses = null)
 {
     return NarroUser::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroUser()->RealName, $strRealName)), $objOptionalClauses);
 }
示例#4
0
 public static function RegisterUser($strUsername, $strEmail, $strPassword, $strRealName)
 {
     $objMaxUser = NarroUser::LoadAll(QQ::Clause(QQ::LimitInfo(1, 0), QQ::OrderBy(QQN::NarroUser()->UserId, false)));
     $objUser = new NarroUser();
     $objUser->UserId = $objMaxUser[0]->UserId + 1;
     $objUser->Username = $strUsername;
     if ($strRealName) {
         $objUser->RealName = $strRealName;
     }
     $objUser->Email = $strEmail;
     require_once __NARRO_INCLUDES__ . '/PasswordHash.class.php';
     $objHasher = new PasswordHash(8, FALSE);
     $objUser->Password = $objHasher->HashPassword($strPassword);
     try {
         $objUser->Save();
     } catch (Exception $objEx) {
         throw $objEx;
     }
     /**
      * set up default roles
      */
     $objUserRole = new NarroUserRole();
     if ($objUser->UserId == 1) {
         $objUserRole->RoleId = 5;
     } else {
         $objUserRole->RoleId = 2;
     }
     $objUserRole->UserId = $objUser->UserId;
     $objUserRole->Save();
     return NarroUser::LoadByUsernameAndPassword($strUsername, md5($strPassword));
 }
 public function __set($strName, $mixValue)
 {
     switch ($strName) {
         case "TranslationPath":
             if (file_exists($mixValue)) {
                 $this->strTranslationPath = $mixValue;
             } else {
                 if (!file_exists(dirname($mixValue))) {
                     throw new Exception(sprintf('Cannot create "%s" because the parent directory "%s" does not exist', $mixValue, dirname($mixValue)));
                 }
                 if (!is_writable(dirname($mixValue))) {
                     throw new Exception(sprintf('Cannot create "%s" because the parent directory "%s" is not writable', $mixValue, dirname($mixValue)));
                 }
                 chmod(dirname($mixValue), 0777);
                 if (mkdir($mixValue, 0777, true)) {
                     $this->strTranslationPath = $mixValue;
                 } else {
                     throw new Exception(sprintf(t('TranslationPath "%s" does not exist.'), $mixValue));
                 }
                 NarroUtils::RecursiveChmod($mixValue);
             }
             break;
         case "TemplatePath":
             if (file_exists($mixValue)) {
                 $this->strTemplatePath = $mixValue;
             } else {
                 if (!file_exists(dirname($mixValue))) {
                     throw new Exception(sprintf('Cannot create "%s" because the parent directory "%s" does not exist', $mixValue, dirname($mixValue)));
                 }
                 if (!is_writable(dirname($mixValue))) {
                     throw new Exception(sprintf('Cannot create "%s" because the parent directory "%s" is not writable', $mixValue, dirname($mixValue)));
                 }
                 chmod(dirname($mixValue), 0777);
                 if (mkdir($mixValue, 0777, true)) {
                     $this->strTranslationPath = $mixValue;
                 } else {
                     throw new Exception(sprintf(t('TranslationPath "%s" does not exist.'), $mixValue));
                 }
                 NarroUtils::RecursiveChmod($mixValue);
             }
             break;
         case "User":
             if ($mixValue instanceof NarroUser) {
                 $this->objUser = $mixValue;
             } else {
                 throw new Exception(t('User should be set with an instance of NarroUser'));
             }
             break;
         case "Project":
             if ($mixValue instanceof NarroProject) {
                 $this->objProject = $mixValue;
             } else {
                 throw new Exception(t('Project should be set with an instance of NarroProject'));
             }
             break;
         case "TargetLanguage":
             if ($mixValue instanceof NarroLanguage) {
                 $this->objTargetLanguage = $mixValue;
             } else {
                 throw new Exception(t('TargetLanguage should be set with an instance of NarroLanguage'));
             }
             break;
         case "SourceLanguage":
             if ($mixValue instanceof NarroLanguage) {
                 $this->objSourceLanguage = $mixValue;
             } else {
                 throw new Exception(t('SourceLanguage should be set with an instance of NarroLanguage'));
             }
             break;
         case "Approve":
             try {
                 $this->blnApprove = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "SkipUntranslated":
             try {
                 $this->blnSkipUntranslated = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ApproveAlreadyApproved":
             try {
                 $this->blnApproveAlreadyApproved = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "CheckEqual":
             try {
                 $this->blnCheckEqual = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ImportUnchangedFiles":
             try {
                 $this->blnImportUnchangedFiles = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ImportSuggestions":
             try {
                 $this->blnImportSuggestions = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "CopyUnhandledFiles":
             try {
                 $this->blnCopyUnhandledFiles = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "OnlySuggestions":
             try {
                 $this->blnOnlySuggestions = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ExportedSuggestion":
             try {
                 $this->intExportedSuggestion = QType::Cast($mixValue, QType::Integer);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ExportAuthorList":
             try {
                 if (is_array($mixValue)) {
                     $this->arrExportAuthorList = QType::Cast($mixValue, QType::ArrayType);
                 } else {
                     $arrAuthor = explode(',', $mixValue);
                     foreach ($arrAuthor as $intIdx => $strAuthor) {
                         $arrAuthor[$intIdx] = trim($strAuthor);
                     }
                     foreach (NarroUser::QueryArray(QQ::In(QQN::NarroUser()->RealName, $arrAuthor)) as $objUser) {
                         $this->arrExportAuthorList[] = $objUser->UserId;
                     }
                 }
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         default:
             return false;
     }
 }
 /**
  * Used internally by the Meta-based Add Column tools.
  *
  * Given a QQNode or a Text String, this will return a NarroUser-based QQNode.
  * It will also verify that it is a proper NarroUser-based QQNode, and will throw an exception otherwise.
  *
  * @param mixed $mixContent
  * @return QQNode
  */
 protected function ResolveContentItem($mixContent)
 {
     if ($mixContent instanceof QQNode) {
         if (!$mixContent->_ParentNode) {
             throw new QCallerException('Content QQNode cannot be a Top Level Node');
         }
         if ($mixContent->_RootTableName == 'narro_user') {
             if ($mixContent instanceof QQReverseReferenceNode && !$mixContent->_PropertyName) {
                 throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
             }
             $objCurrentNode = $mixContent;
             while ($objCurrentNode = $objCurrentNode->_ParentNode) {
                 if (!$objCurrentNode instanceof QQNode) {
                     throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
                 }
                 if ($objCurrentNode instanceof QQReverseReferenceNode && !$objCurrentNode->_PropertyName) {
                     throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
                 }
             }
             return $mixContent;
         } else {
             throw new QCallerException('Content QQNode has a root table of "' . $mixContent->_RootTableName . '". Must be a root of "narro_user".');
         }
     } else {
         if (is_string($mixContent)) {
             switch ($mixContent) {
                 case 'UserId':
                     return QQN::NarroUser()->UserId;
                 case 'Username':
                     return QQN::NarroUser()->Username;
                 case 'Password':
                     return QQN::NarroUser()->Password;
                 case 'Email':
                     return QQN::NarroUser()->Email;
                 case 'RealName':
                     return QQN::NarroUser()->RealName;
                 case 'Data':
                     return QQN::NarroUser()->Data;
                 default:
                     throw new QCallerException('Simple Property not found in NarroUserDataGrid content: ' . $mixContent);
             }
         } else {
             if ($mixContent instanceof QQAssociationNode) {
                 throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
             } else {
                 throw new QCallerException('Invalid Content type');
             }
         }
     }
 }
示例#7
0
 public function __construct($strDate, $objParentObject, NarroProject $objProject = null, $strControlId = null)
 {
     // Call the Parent
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     $this->strTemplate = dirname(__FILE__) . '/' . __CLASS__ . '.tpl.php';
     $this->blnAutoRenderChildren = true;
     // Tabs
     $this->tabTop = new QTabs($this);
     $pnlTranslators = new NarroUserDataGrid($this->tabTop);
     $pnlTranslators->CssClass = 'datagrid';
     $colUsername = $pnlTranslators->MetaAddColumn(QQN::NarroUser()->Username);
     $colUsername->HtmlEntities = false;
     $colUsername->Html = '<?=NarroLink::UserProfile($_ITEM->UserId, $_ITEM->Username)?>';
     $colCnt = new QDataGridColumn(t('Translations'));
     $colCnt->Html = '<?=$_ITEM->GetVirtualAttribute("suggestion_cnt")?>';
     $pnlTranslators->SortColumnIndex = 1;
     $pnlTranslators->ShowHeader = false;
     $pnlTranslators->SortDirection = 1;
     $pnlTranslators->AddColumn($colCnt);
     $pnlTranslators->AdditionalConditions = QQ::AndCondition(QQ::GreaterOrEqual(QQN::NarroUser()->NarroSuggestionAsUser->Created, $strDate), QQ::Equal(QQN::NarroUser()->NarroSuggestionAsUser->LanguageId, QApplication::GetLanguageId()), QQ::NotEqual(QQN::NarroUser()->UserId, NarroUser::ANONYMOUS_USER_ID), $objProject ? QQ::Equal(QQN::NarroUser()->NarroSuggestionAsUser->Text->NarroContextAsText->ProjectId, $objProject->ProjectId) : QQ::All());
     $pnlTranslators->AdditionalClauses = array(QQ::Count(QQN::NarroUser()->NarroSuggestionAsUser->SuggestionId, 'suggestion_cnt'), QQ::GroupBy(QQN::NarroUser()->UserId));
     $pnlReviewers = new NarroUserDataGrid($this->tabTop);
     $pnlReviewers->CssClass = 'datagrid';
     $colUsername = $pnlReviewers->MetaAddColumn(QQN::NarroUser()->Username);
     $colUsername->HtmlEntities = false;
     $colUsername->Html = '<?=NarroLink::UserProfile($_ITEM->UserId, $_ITEM->Username)?>';
     $colCnt = new QDataGridColumn(t('Reviewers'));
     $colCnt->Html = '<?=$_ITEM->GetVirtualAttribute("suggestion_cnt")?>';
     $pnlReviewers->SortColumnIndex = 1;
     $pnlReviewers->ShowHeader = false;
     $pnlReviewers->SortDirection = 1;
     $pnlReviewers->AddColumn($colCnt);
     $pnlReviewers->AdditionalConditions = QQ::AndCondition(QQ::GreaterOrEqual(QQN::NarroUser()->NarroContextInfoAsValidatorUser->Modified, $strDate), QQ::Equal(QQN::NarroUser()->NarroContextInfoAsValidatorUser->LanguageId, QApplication::GetLanguageId()), QQ::NotEqual(QQN::NarroUser()->UserId, NarroUser::ANONYMOUS_USER_ID), $objProject ? QQ::Equal(QQN::NarroUser()->NarroContextInfoAsValidatorUser->Context->ProjectId, $objProject->ProjectId) : QQ::All());
     $pnlReviewers->AdditionalClauses = array(QQ::Count(QQN::NarroUser()->NarroContextInfoAsValidatorUser->ValidSuggestionId, 'suggestion_cnt'), QQ::GroupBy(QQN::NarroUser()->UserId));
     $pnlVoters = new NarroUserDataGrid($this->tabTop);
     $pnlVoters->CssClass = 'datagrid';
     $colUsername = $pnlVoters->MetaAddColumn(QQN::NarroUser()->Username);
     $colUsername->HtmlEntities = false;
     $colUsername->Html = '<?=NarroLink::UserProfile($_ITEM->UserId, $_ITEM->Username)?>';
     $colCnt = new QDataGridColumn(t('Reviewers'));
     $colCnt->Html = '<?=$_ITEM->GetVirtualAttribute("suggestion_cnt")?>';
     $pnlVoters->SortColumnIndex = 1;
     $pnlVoters->ShowHeader = false;
     $pnlVoters->SortDirection = 1;
     $pnlVoters->AddColumn($colCnt);
     $pnlVoters->AdditionalConditions = QQ::AndCondition(QQ::GreaterOrEqual(QQN::NarroUser()->NarroSuggestionVoteAsUser->Created, $strDate), QQ::Equal(QQN::NarroUser()->NarroSuggestionVoteAsUser->Suggestion->LanguageId, QApplication::GetLanguageId()), QQ::NotEqual(QQN::NarroUser()->UserId, NarroUser::ANONYMOUS_USER_ID), $objProject ? QQ::Equal(QQN::NarroUser()->NarroSuggestionVoteAsUser->Suggestion->Text->NarroContextAsText->ProjectId, $objProject->ProjectId) : QQ::All());
     $pnlVoters->AdditionalClauses = array(QQ::Count(QQN::NarroUser()->NarroSuggestionVoteAsUser->SuggestionId, 'suggestion_cnt'), QQ::GroupBy(QQN::NarroUser()->UserId));
     $pnlComments = new NarroUserDataGrid($this->tabTop);
     $pnlComments->CssClass = 'datagrid';
     $colUsername = $pnlComments->MetaAddColumn(QQN::NarroUser()->Username);
     $colUsername->HtmlEntities = false;
     $colUsername->Html = '<?=NarroLink::UserProfile($_ITEM->UserId, $_ITEM->Username)?>';
     $colCnt = new QDataGridColumn(t('Reviewers'));
     $colCnt->Html = '<?=$_ITEM->GetVirtualAttribute("suggestion_cnt")?>';
     $pnlComments->SortColumnIndex = 1;
     $pnlComments->ShowHeader = false;
     $pnlComments->SortDirection = 1;
     $pnlComments->AddColumn($colCnt);
     $pnlComments->AdditionalConditions = QQ::AndCondition(QQ::GreaterOrEqual(QQN::NarroUser()->NarroTextCommentAsUser->Created, $strDate), QQ::Equal(QQN::NarroUser()->NarroTextCommentAsUser->LanguageId, QApplication::GetLanguageId()), QQ::NotEqual(QQN::NarroUser()->UserId, NarroUser::ANONYMOUS_USER_ID));
     $pnlComments->AdditionalClauses = array(QQ::Count(QQN::NarroUser()->NarroTextCommentAsUser->TextCommentId, 'suggestion_cnt'), QQ::GroupBy(QQN::NarroUser()->UserId));
     $this->tabTop->Headers = array(t('Translators'), t('Reviewers'), t('Voters'), t('Comments'));
 }