Exemplo n.º 1
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));
 }
                case 12:
                case 13:
                case 14:
                case 15:
                case 16:
                case 17:
                    $objUserRole->RoleId = 5;
                    break;
            }
            if (!$objUserRole->RoleId) {
                continue;
            }
            $objUserRole->LanguageId = $objUserPermission->LanguageId;
            $objUserRole->ProjectId = $objUserPermission->ProjectId;
            $objUserRole->UserId = $objUserPermission->UserId;
            if (!isset($arrUserPermissions[$objUserRole->RoleId . '-' . $objUserRole->LanguageId . '-' . $objUserRole->ProjectId])) {
                try {
                    $objUserRole->Save();
                } catch (Exception $objEx) {
                    /**
                     * Most probably we already added the role
                     */
                    $objEx = null;
                }
                $arrUserPermissions[$objUserRole->RoleId . '-' . $objUserRole->LanguageId . '-' . $objUserRole->ProjectId] = 1;
            }
        }
    }
} else {
    QApplication::Redirect('login.php');
}
Exemplo n.º 3
0
 public function btnAddRole_Click($strFormId, $strControlId, $strParameter)
 {
     if (is_numeric($strParameter)) {
         $objUserRole = NarroUserRole::Load($strParameter);
         $this->btnAddRole->Text = t('Add');
         $strControlId = 'btnEditRole' . $strParameter;
         $btnEdit = $this->Form->GetControl($strControlId);
         $btnEdit->Text = t('Edit');
         $this->btnAddRole->ActionParameter = 'a';
     } else {
         $objUserRole = new NarroUserRole();
         $objUserRole->UserId = $this->objUser->UserId;
     }
     $objUserRole->LanguageId = $this->lstLanguage->SelectedValue;
     $objUserRole->ProjectId = $this->lstProject->SelectedValue;
     $objUserRole->RoleId = $this->lstRole->SelectedValue;
     if (!QApplication::HasPermission('Can manage user roles', $objUserRole->ProjectId, $objUserRole->LanguageId)) {
         QApplication::ExecuteJavaScript(sprintf('alert(\'%s\')', sprintf(t('You don\\\'t have permissions to give permissions on the project %s, language %s'), $this->lstProject->SelectedName, $this->lstLanguage->SelectedName)));
         return false;
     }
     if ($this->lstRole->SelectedName == 'Administrator' && !QApplication::HasPermission('Administrator')) {
         QApplication::ExecuteJavaScript(sprintf('alert(\'%s\')', sprintf(t('You don\\\'t have the Administrator permission, so you cannot give it'))));
         return false;
     }
     try {
         $objUserRole->Save();
     } catch (QMySqliDatabaseException $objExc) {
         if (strpos($objExc->getMessage(), 'Duplicate entry') === false) {
             throw $objExc;
         } else {
             //
         }
     }
     $this->dtgUserRole_Bind();
 }