Example #1
0
 protected function _postSave()
 {
     parent::_postSave();
     // get the source bans admin model
     $sbAdminModel = new AWickham_SourceBansSync_Model_SourceBans_Admin();
     $xfUserModel = XenForo_Model::create('XenForo_Model_User');
     $xfUserExternalModel = XenForo_Model::create('XenForo_Model_UserExternal');
     // get the user's new identities
     $identities = unserialize($this->get('identities'));
     // only do this if the steam id is set
     if ($identities && array_key_exists('steam', $identities)) {
         // check to see if the user exists in source bans
         $sbUser = $sbAdminModel->fetchBySteamId($xfUserModel->toSteamId($this->_currentSteamId));
         // add the user to source bans
         if (!$sbUser) {
             // figure out the groups
             list($gid, $srvgroups_id, $serverGroupId) = $xfUserModel->getSourceBansGroups($this, XenForo_Application::get('options')->AWickham_SourceBansSync_Groups);
             if ($gid && $srvgroups_id && $serverGroupId) {
                 // add the user
                 $insertValues = array('user' => $this->get('username'), 'email' => $this->get('email'), 'authid' => $xfUserModel->toSteamId($identities['steam']['provider_key']), 'password' => XenForo_Application::generateRandomString(8), 'gid' => $gid, 'srvgroups_id' => $srvgroups_id, 'server_group_id' => $serverGroupId, 'validate' => '', 'extraflags' => 0);
                 $sbAdminModel->insert($this->get('user_id'), $insertValues);
                 // rehash the sourcebans servers
                 AWickham_SourceBansSync_Model_SourceBans_Rcon::rehash();
             }
         } else {
             // update the user if anything we care about changed
             if ($this->isChanged('user_group_id') || $this->isChanged('secondary_group_ids') || $this->isChanged('email') || $this->isChanged('username') || array_key_exists('steam', $this->_identities) && $this->_identities['steam'] != $identities['steam']) {
                 // figure out the groups
                 list($gid, $srvgroups_id, $serverGroupId) = $xfUserModel->getSourceBansGroups($this, XenForo_Application::get('options')->AWickham_SourceBansSync_Groups);
                 if (!$gid || !$srvgroups_id || !$serverGroupId) {
                     // remove the user from source bans
                     $sbAdminModel->delete($this->get('user_id'), $xfUserModel->toSteamId($this->_currentSteamId));
                 } else {
                     $updateArray = array('user' => $this->get('username'), 'email' => $this->get('email'), 'authid' => $xfUserModel->toSteamId($identities['steam']['provider_key']), 'gid' => $gid, 'srvgroups_id' => $srvgroups_id, 'server_group_id' => $serverGroupId);
                     $sbAdminModel->update($xfUserModel->toSteamId($this->_currentSteamId), $updateArray);
                 }
                 // rehash the sourcebans servers
                 AWickham_SourceBansSync_Model_SourceBans_Rcon::rehash();
             }
         }
     }
 }