Exemple #1
0
 /**
  *
  *
  * @return bool
  */
 public function insertUserTable()
 {
     $CurrentUser = $this->SQL->getWhere('User', array('UserID' => Gdn::session()->UserID))->firstRow(DATASET_TYPE_ARRAY);
     $CurrentPassword = $CurrentUser['Password'];
     $CurrentHashMethod = $CurrentUser['HashMethod'];
     $CurrentTransientKey = gdn::session()->transientKey();
     // Delete the current user table.
     $this->SQL->Truncate('User');
     // Load the new user table.
     $UserTableInfo =& $this->Data['Tables']['User'];
     if (!$this->importExists('User', 'HashMethod')) {
         $this->_InsertTable('User', array('HashMethod' => $this->GetPasswordHashMethod()));
     } else {
         $this->_InsertTable('User');
     }
     $UserTableInfo['Inserted'] = true;
     $AdminEmail = val('OverwriteEmail', $this->Data);
     $SqlArgs = array(':Email' => $AdminEmail);
     $SqlSet = '';
     $SqlArgs[':Password'] = $CurrentPassword;
     $SqlArgs[':HashMethod'] = $CurrentHashMethod;
     $SqlSet = ', Password = :Password, HashMethod = :HashMethod';
     // If doing a password reset, save out the new admin password:
     if (strcasecmp($this->GetPasswordHashMethod(), 'reset') == 0) {
         if (!isset($SqlArgs[':Password'])) {
             $PasswordHash = new Gdn_PasswordHash();
             $Hash = $PasswordHash->HashPassword(val('OverwritePassword', $this->Data));
             $SqlSet .= ', Password = :Password, HashMethod = :HashMethod';
             $SqlArgs[':Password'] = $Hash;
             $SqlArgs[':HashMthod'] = 'Vanilla';
         }
         // Write it out.
         $this->query("update :_User set Admin = 1{$SqlSet} where Email = :Email", $SqlArgs);
     } else {
         // Set the admin user flag.
         $this->query("update :_User set Admin = 1{$SqlSet} where Email = :Email", $SqlArgs);
     }
     // Start the new session.
     $User = Gdn::userModel()->GetByEmail(val('OverwriteEmail', $this->Data));
     if (!$User) {
         $User = Gdn::userModel()->GetByUsername(val('OverwriteEmail', $this->Data));
     }
     Gdn::session()->start(val('UserID', $User), true);
     gdn::session()->transientKey($CurrentTransientKey);
     return true;
 }
Exemple #2
0
 /**
  * Aggressively prompt users to upgrade PHP version.
  *
  * @param $sender
  */
 public function settingsController_render_before($sender)
 {
     // Set this in your config to dismiss our upgrade warnings. Not recommended.
     if (c('Vanilla.WarnedMeToUpgrade') === 'PHP 5.6') {
         return;
     }
     if (version_compare(phpversion(), '5.6') < 0) {
         $UpgradeMessage = ['Content' => 'Upgrade to <b>PHP 5.6</b> or higher immediately. Version ' . phpversion() . ' is no longer supported.', 'AssetTarget' => 'Content', 'CssClass' => 'WarningMessage'];
         $MessageModule = new MessageModule($sender, $UpgradeMessage);
         $sender->addModule($MessageModule);
     }
     $mysqlVersion = gdn::sql()->version();
     if (version_compare($mysqlVersion, '5.6') < 0) {
         $UpgradeMessage = ['Content' => 'We recommend using <b>MySQL 5.6</b> or higher. Version ' . htmlspecialchars($mysqlVersion) . ' will not support all upcoming Vanilla features.', 'AssetTarget' => 'Content', 'CssClass' => 'InfoMessage'];
         $MessageModule = new MessageModule($sender, $UpgradeMessage);
         $sender->addModule($MessageModule);
     }
 }
 /**
  * Allow user to set their preferred locale via link-click.
  */
 public function profileController_setLocale_create($Sender, $locale, $TK)
 {
     if (!Gdn::Session()->UserID) {
         throw PermissionException('Garden.SignIn.Allow');
     }
     // Check intent.
     if (!Gdn::Session()->ValidateTransientKey($TK)) {
         safeRedirect($_SERVER['HTTP_REFERER']);
     }
     // If we got a valid locale, save their preference
     if (isset($locale)) {
         $locale = $this->validateLocale($locale);
         if ($locale) {
             $this->SetUserMeta(Gdn::Session()->UserID, 'Locale', $locale);
         }
     }
     $successRedirect = $_SERVER['HTTP_REFERER'];
     $target = gdn::request()->get('Target');
     if ($target) {
         $successRedirect = $target;
     }
     // Back from whence we came.
     safeRedirect($successRedirect);
 }
Exemple #4
0
 /**
  * Add user's viewable roles to gdn.meta if user is logged in.
  * @param $sender
  * @param $args
  */
 public function gdn_dispatcher_afterControllerCreate_handler($sender, $args)
 {
     // Function addDefinition returns the value of the definition if you pass only one argument.
     if (!gdn::controller()->addDefinition('Roles')) {
         if (Gdn::session()->isValid()) {
             $roleModel = new RoleModel();
             gdn::controller()->addDefinition("Roles", $roleModel->getPublicUserRoles(gdn::session()->UserID, "Name"));
         }
     }
 }
Exemple #5
0
?>
</th>
            <th class="options column-checkbox"></th>
        </tr>
        </thead>
        <tbody>
        <?php 
foreach ($this->data('Log') as $Row) {
    $RecordLabel = valr('Data.Type', $Row);
    if (!$RecordLabel) {
        $RecordLabel = $Row['RecordType'];
    }
    $RecordLabel = Gdn_Form::LabelCode($RecordLabel);
    $user = userBuilder($Row, 'Insert');
    $user = Gdn::userModel()->getByUsername(val('Name', $user));
    $viewPersonalInfo = gdn::session()->checkPermission('Garden.PersonalInfo.View');
    $userBlock = new MediaItemModule(val('Name', $user), userUrl($user));
    $userBlock->setView('media-sm')->setImage(userPhotoUrl($user))->addMetaIf($viewPersonalInfo, Gdn_Format::Email($user->Email));
    $Url = FALSE;
    if (in_array($Row['Operation'], array('Edit', 'Moderate'))) {
        switch (strtolower($Row['RecordType'])) {
            case 'discussion':
                $Url = "/discussion/{$Row['RecordID']}/x/p1";
                break;
            case 'comment':
                $Url = "/discussion/comment/{$Row['RecordID']}#Comment_{$Row['RecordID']}";
        }
    } elseif ($Row['Operation'] === 'Delete') {
        switch (strtolower($Row['RecordType'])) {
            case 'comment':
                $Url = "/discussion/{$Row['ParentRecordID']}/x/p1";