public function setPreference($user_id, $key, $value)
 {
     $result = Doctrine_Query::create()->from('Preferences p')->andwhere('p.user_ref = ?', $user_id)->andWhere('p.pref_key = ?', $key)->fetchOne();
     if (!$result) {
         $result = new Preferences();
         $result->fromArray(array('user_ref' => $user_id, 'pref_key' => $key));
     }
     $result->setPrefValue($value);
     $result->save();
     return true;
 }
Beispiel #2
0
 /**
  * Saves user preferences
  */
 function save_prefs($username, Preferences $prefs)
 {
     $data = array('options' => $prefs->to_json());
     log_message('DEBUG', 'Storing user prefs [' . $prefs->to_json() . ']' . ' for user ' . $username);
     $query = $this->db->get_where('prefs', array('username' => $username));
     if ($query->num_rows() == 1) {
         $this->db->update('prefs', $data, array('username' => $username));
     } else {
         $data['username'] = $username;
         $this->db->insert('prefs', $data);
     }
 }
 function read($sessId)
 {
     $prefs = new Preferences();
     $idle = $prefs->idleTime();
     $expiry = time() - $idle;
     $query = "SELECT data FROM Sessions WHERE sessId='{$sessId}' AND lastAccess >= {$expiry}";
     $data = parent::query($query);
     if (isset($data[0])) {
         return $data[0]['data'];
     } else {
         return '';
     }
 }
Beispiel #4
0
 /**
  * @return Preferences
  */
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new Preferences();
     }
     return self::$_instance;
 }
Beispiel #5
0
 function dataField($sessId)
 {
     $prefs = new Preferences();
     $idle = $prefs->idleTime();
     $expiry = time() - $idle;
     $query = "SELECT data FROM Sessions WHERE sessId='{$sessId}' AND lastAccess >= {$expiry}";
     $session = parent::query($query);
     $validData = parent::validateIndexes($session, 0, 'data');
     $vars = preg_split('/([a-z,A-Z]+)\\|/', $validData, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
     if (isset($vars[1])) {
         $validData = unserialize($vars[1]);
         return $validData;
     } else {
         return null;
     }
 }
Beispiel #6
0
 public function get_login()
 {
     $userDB = UserDB::getInstance();
     if (!is_object($userDB)) {
         return NULL;
     }
     $prefs = Preferences::getInstance();
     $config = $prefs->get('AuthMethod', 'Auto');
     if (array_key_exists('login', $_POST) && array_key_exists('uselogin', $config) && $config['uselogin'] == '1') {
         $this->login = $_POST['login'];
     } else {
         $this->login = '******' . gen_unique_string();
     }
     $u = new User();
     $u->setAttribute('login', $this->login);
     $u->setAttribute('password', $u->getAttribute('login'));
     $u->setAttribute('displayname', 'user ' . $u->getAttribute('login'));
     if ($userDB->add($u)) {
         $user = $userDB->import($u->getAttribute('login'));
     } else {
         Logger::error('main', 'AuthMethod::Auto::get_login failed to add user ' . $u->getAttribute('login'));
         return NULL;
     }
     if (!is_object($user)) {
         return NULL;
     }
     $this->login = $user->getAttribute('login');
     return $this->login;
 }
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = self::$mockmode ? new PreferencesMock() : new PreferencesImpl();
     }
     return self::$instance;
 }
 public function execute($par)
 {
     $this->setHeaders();
     $this->outputHeader();
     $out = $this->getOutput();
     $out->disallowUserJs();
     # Prevent hijacked user scripts from sniffing passwords etc.
     $user = $this->getUser();
     if ($user->isAnon()) {
         $out->showErrorPage('prefsnologin', 'prefsnologintext', array($this->getTitle()->getPrefixedDBkey()));
         return;
     }
     $this->checkReadOnly();
     if ($par == 'reset') {
         $this->showResetForm();
         return;
     }
     $out->addModules('mediawiki.special.preferences');
     if ($this->getRequest()->getCheck('success')) {
         $out->wrapWikiMsg("<div class=\"successbox\"><strong>\n\$1\n</strong></div><div id=\"mw-pref-clear\"></div>", 'savedprefs');
     }
     $htmlForm = Preferences::getFormObject($user, $this->getContext());
     $htmlForm->setSubmitCallback(array('Preferences', 'tryUISubmit'));
     $htmlForm->show();
 }
 public function execute($par)
 {
     $this->setHeaders();
     $this->outputHeader();
     $out = $this->getOutput();
     $out->disallowUserJs();
     # Prevent hijacked user scripts from sniffing passwords etc.
     $this->requireLogin('prefsnologintext2');
     $this->checkReadOnly();
     if ($par == 'reset') {
         $this->showResetForm();
         return;
     }
     $out->addModules('mediawiki.special.preferences');
     $out->addModuleStyles('mediawiki.special.preferences.styles');
     if ($this->getRequest()->getCheck('success')) {
         $out->wrapWikiMsg(Html::rawElement('div', array('class' => 'mw-preferences-messagebox successbox', 'id' => 'mw-preferences-success'), Html::element('p', array(), '$1')), 'savedprefs');
     }
     $this->addHelpLink('Help:Preferences');
     // Load the user from the master to reduce CAS errors on double post (T95839)
     $user = $this->getUser()->getInstanceForUpdate() ?: $this->getUser();
     $htmlForm = Preferences::getFormObject($user, $this->getContext());
     $htmlForm->setSubmitCallback(array('Preferences', 'tryUISubmit'));
     $sectionTitles = $htmlForm->getPreferenceSections();
     $prefTabs = '';
     foreach ($sectionTitles as $key) {
         $prefTabs .= Html::rawElement('li', array('role' => 'presentation', 'class' => $key === 'personal' ? 'selected' : null), Html::rawElement('a', array('id' => 'preftab-' . $key, 'role' => 'tab', 'href' => '#mw-prefsection-' . $key, 'aria-controls' => 'mw-prefsection-' . $key, 'aria-selected' => $key === 'personal' ? 'true' : 'false', 'tabIndex' => $key === 'personal' ? 0 : -1), $htmlForm->getLegend($key)));
     }
     $out->addHTML(Html::rawElement('ul', array('id' => 'preftoc', 'role' => 'tablist'), $prefTabs));
     $htmlForm->show();
 }
 /**
  * @param {String} $key valid key as specified in validTabs
  * @return {HtmlForm}
  */
 public function getPreferencesForm($key)
 {
     $prefs = array();
     $user = $this->getUser();
     $ctx = $this->getContext();
     switch ($key) {
         case 'personal':
             Preferences::profilePreferences($user, $ctx, $prefs);
             break;
         case 'skin':
             Preferences::skinPreferences($user, $ctx, $prefs);
             break;
         case 'dateformat':
             Preferences::datetimePreferences($user, $ctx, $prefs);
             break;
         case 'files':
             Preferences::filesPreferences($user, $ctx, $prefs);
             break;
         case 'rc':
             Preferences::rcPreferences($user, $ctx, $prefs);
             break;
     }
     Preferences::loadPreferenceValues($user, $ctx, $prefs);
     $htmlForm = new PreferencesForm($prefs, $ctx, 'prefs');
     $htmlForm->suppressReset();
     $htmlForm->setModifiedUser($user);
     $htmlForm->setId('mw-prefs-form');
     $htmlForm->setSubmitText($ctx->msg('saveprefs')->text());
     $htmlForm->setSubmitCallback(array('Preferences', 'tryUISubmit'));
     $htmlForm->setAction(SpecialPage::getTitleFor($this->getName(), $key)->getLocalUrl());
     return $htmlForm;
 }
 function execute($par)
 {
     global $wgOut, $wgUser, $wgRequest;
     $this->setHeaders();
     $this->outputHeader();
     $wgOut->disallowUserJs();
     # Prevent hijacked user scripts from sniffing passwords etc.
     if ($wgUser->isAnon()) {
         $wgOut->showErrorPage('prefsnologin', 'prefsnologintext', array($this->getTitle()->getPrefixedDBkey()));
         return;
     }
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     if ($par == 'reset') {
         $this->showResetForm();
         return;
     }
     $wgOut->addModules('mediawiki.legacy.prefs');
     $wgOut->addModules('mediawiki.special.preferences');
     if ($wgRequest->getCheck('success')) {
         $wgOut->wrapWikiMsg("<div class=\"successbox\"><strong>\n\$1\n</strong></div><div id=\"mw-pref-clear\"></div>", 'savedprefs');
     }
     if ($wgRequest->getCheck('eauth')) {
         $wgOut->wrapWikiMsg("<div class='error' style='clear: both;'>\n\$1\n</div>", 'eauthentsent', $wgUser->getName());
     }
     $htmlForm = Preferences::getFormObject($wgUser);
     $htmlForm->setSubmitCallback(array('Preferences', 'tryUISubmit'));
     $htmlForm->show();
 }
Beispiel #12
0
 public function __construct()
 {
     parent::__construct();
     $prefs = Preferences::getInstance();
     if (!$prefs) {
         die_error('get Preferences failed', __FILE__, __LINE__);
     }
     $a_pref = $prefs->get('UserGroupDB', 'activedirectory');
     if (is_array($a_pref)) {
         foreach ($a_pref as $k => $v) {
             $this->preferences[$k] = $v;
         }
     }
     // Generate parent (ldap) settings
     $this->preferences['filter'] = '(objectClass=group)';
     $this->preferences['match'] = array('name' => 'name', 'description' => 'description');
     $this->preferences['group_match_user'] = array('user_field', 'group_field');
     $this->preferences['user_field'] = 'memberOf';
     $this->preferences['user_field_type'] = 'group_dn';
     $this->preferences['group_field'] = 'member';
     $this->preferences['group_field_type'] = 'user_dn';
     $this->preferences['ou'] = '';
     if (array_key_exists('use_child_group', $this->preferences)) {
         if (in_array($this->preferences['use_child_group'], array(1, '1'))) {
             $this->preferences['user_field'] .= ':1.2.840.113556.1.4.1941:';
             $this->preferences['group_field'] .= ':1.2.840.113556.1.4.1941:';
         }
     }
 }
 public function execute($par)
 {
     $this->setHeaders();
     $this->outputHeader();
     $out = $this->getOutput();
     $out->disallowUserJs();
     # Prevent hijacked user scripts from sniffing passwords etc.
     $user = $this->getUser();
     if ($user->isAnon()) {
         $out->showErrorPage('prefsnologin', 'prefsnologintext', array($this->getTitle()->getPrefixedDBkey()));
         return;
     }
     $this->checkReadOnly();
     if ($par == 'reset') {
         $this->showResetForm();
         return;
     }
     $out->addModules('mediawiki.special.preferences');
     /* Wikia change begin - @author: macbre */
     /* Enable custom notifications handling */
     wfRunHooks('SpecialPreferencesOnRender', array(&$this));
     /* Wikia change end */
     if ($this->getRequest()->getCheck('success')) {
         $out->wrapWikiMsg("<div class=\"successbox\"><strong>\n\$1\n</strong></div><div id=\"mw-pref-clear\"></div>", 'savedprefs');
     }
     if ($this->getRequest()->getCheck('eauth')) {
         $out->wrapWikiMsg("<div class='error' style='clear: both;'>\n\$1</div>", 'eauthentsent', $user->getName());
     }
     $htmlForm = Preferences::getFormObject($user, $this->getContext());
     $htmlForm->setSubmitCallback(array('Preferences', 'tryUISubmit'));
     $htmlForm->show();
 }
Beispiel #14
0
 public static function singleton($options = array())
 {
     if (!isset(self::$instance)) {
         self::$instance = new Preferences($options);
     }
     return self::$instance;
 }
 public static function callMethod($method_name_, $type_, $element_ = NULL, $group_ = NULL)
 {
     Logger::debug('main', "Abstract_Liaison::callMethod ('{$method_name_}', '{$type_}', '{$element_}', '{$group_}')");
     if ($type_ != 'UsersGroup') {
         $method_to_call = array('Abstract_Liaison_sql', $method_name_);
         $class_to_use = 'Abstract_Liaison_sql';
     } else {
         $prefs = Preferences::getInstance();
         if (!$prefs) {
             Logger::error('main', 'Abstract_Liaison::load get Preferences failed');
             return NULL;
         }
         $mods_enable = $prefs->get('general', 'module_enable');
         if (!in_array('UserGroupDB', $mods_enable)) {
             Logger::error('main', 'Abstract_Liaison::load UserGroupDB module must be enabled');
             return NULL;
         }
         $mod_usergroup_name = 'UserGroupDB_' . $prefs->get('UserGroupDB', 'enable');
         $liaison_type = call_user_func(array($mod_usergroup_name, 'liaisonType'));
         $method_to_call = array('Abstract_Liaison_' . $liaison_type, $method_name_);
         $class_to_use = 'Abstract_Liaison_' . $liaison_type;
     }
     if (!method_exists($class_to_use, $method_name_)) {
         Logger::error('main', "Abstract_Liaison::callMethod method '{$method_to_call}' does not exist");
         return NULL;
     }
     return call_user_func($method_to_call, $type_, $element_, $group_);
 }
Beispiel #16
0
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new Preferences();
     }
     return self::$instance;
 }
Beispiel #17
0
 function __construct()
 {
     parent::__construct();
     $this->prefs = Preferences::singleton($this->session->userdata('prefs'));
     $this->load->library('caldav');
     $this->output->set_content_type('application/json');
 }
Beispiel #18
0
 function __construct()
 {
     parent::__construct();
     // Force authentication
     $this->auth->force_auth();
     // Preferences
     $this->prefs = Preferences::singleton($this->session->userdata('prefs'));
 }
Beispiel #19
0
 public function __construct()
 {
     $prefs = Preferences::getInstance();
     $sql_conf = $prefs->get('general', 'sql');
     if (is_array($sql_conf)) {
         $this->table = $sql_conf['prefix'] . 'user';
     }
 }
Beispiel #20
0
 public function __construct()
 {
     $this->prefs = Preferences::getInstance();
     if (!$this->prefs) {
         Logger::critical('main', 'SessionManagement::__construct - get Preferences failed');
         throw_response(INTERNAL_ERROR);
     }
 }
Beispiel #21
0
 public function __construct()
 {
     $prefs = Preferences::getInstance();
     if ($prefs) {
         $this->config = $prefs->get('UserGroupDB', 'sql_external');
     } else {
         die_error('USERGROUPDB::MYSQL_external::construct get Prefs failed', __FILE__, __LINE__);
     }
 }
Beispiel #22
0
 public function __construct()
 {
     $prefs = Preferences::getInstance();
     if (!$prefs) {
         die_error('get Preferences failed', __FILE__, __LINE__);
     }
     $this->config = $prefs->get('UserDB', 'ldap');
     $this->cache_users = array();
 }
Beispiel #23
0
 public function __construct()
 {
     $prefs = Preferences::getInstance();
     $sql_conf = $prefs->get('general', 'sql');
     if (is_array($sql_conf)) {
         @define('APPLICATION_TABLE', $sql_conf['prefix'] . 'application');
     }
     $this->cache = array();
 }
Beispiel #24
0
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new Preferences();
         // если экземпляр не создан, создаём его
     }
     return self::$instance;
     // получаем экземпляр объекта этого класса
 }
 public function actionCreate()
 {
     $model = new Clients();
     $account = new Accounts();
     $preference = new Preferences();
     if (isset($_POST['Clients'], $_POST['Accounts'], $_POST['Preferences'])) {
         $model->attributes = $_POST['Clients'];
         $account->attributes = $_POST['Accounts'];
         $preference->attributes = $_POST['Preferences'];
         $model->login_name = $account->login_name;
         $model->client_code = RandomGenerator::generateString(AdminGlobals::CLIENT_CODE_LENGTH);
         $model->subscription_status = "active";
         $preference->prepaid_passwd = RandomGenerator::generateString(AdminGlobals::PREPAID_PASSWD_LENGTH);
         $account->account_name = $model->client_name;
         $account->email = $model->email;
         $account->is_visible = 0;
         $valid = $model->validate();
         $valid = $account->validate() && $valid;
         $valid = $preference->validate() && $valid;
         if ($valid) {
             $transaction = Yii::app()->db->beginTransaction();
             $success = $model->save(false);
             if ($success) {
                 $account->client_id = $preference->client_id = $model->id;
             }
             $success = $success && $account->save(false);
             $success = $success && $preference->save(false);
             if ($success) {
                 $transaction->commit();
                 if (Yii::app()->request->isAjaxRequest) {
                     $this->renderPartial('view', array('model' => $this->loadModel($model->id), 'account' => $account, 'preference' => $preference), false, true);
                     Yii::app()->end();
                 }
                 $this->redirect(array('view', 'id' => $model->id));
             }
             $transaction->rollBack();
         }
     }
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('create', array('model' => $model, 'account' => $account, 'preference' => $preference), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'account' => $account, 'preference' => $preference));
 }
Beispiel #26
0
 /**
  * Changes preferences of the current user.
  */
 public function execute()
 {
     $user = $this->getUser();
     if ($user->isAnon()) {
         $this->dieUsage('Anonymous users cannot change preferences', 'notloggedin');
     }
     if (!$user->isAllowed('editmyoptions')) {
         $this->dieUsage('You don\'t have permission to edit your options', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     $changed = false;
     if (isset($params['optionvalue']) && !isset($params['optionname'])) {
         $this->dieUsageMsg(array('missingparam', 'optionname'));
     }
     if ($params['reset']) {
         $user->resetOptions();
         $changed = true;
     }
     $changes = array();
     if (count($params['change'])) {
         foreach ($params['change'] as $entry) {
             $array = explode('=', $entry, 2);
             $changes[$array[0]] = isset($array[1]) ? $array[1] : null;
         }
     }
     if (isset($params['optionname'])) {
         $newValue = isset($params['optionvalue']) ? $params['optionvalue'] : null;
         $changes[$params['optionname']] = $newValue;
     }
     if (!$changed && !count($changes)) {
         $this->dieUsage('No changes were requested', 'nochanges');
     }
     $prefs = Preferences::getPreferences($user, $this->getContext());
     foreach ($changes as $key => $value) {
         if (empty($prefs[$key])) {
             // This is not a default preference and cannot be modified by this API
             $validation = 'not a valid preference';
         } else {
             $field = HTMLForm::loadInputFromParameters($key, $prefs[$key]);
             $validation = $field->validate($value, $user->getOptions());
         }
         if ($validation === true) {
             $user->setGlobalPreference($key, $value);
             $changed = true;
         } else {
             $this->setWarning("Validation error for '{$key}': {$validation}");
         }
     }
     if ($changed) {
         // Commit changes
         $user->saveSettings();
     }
     $this->getResult()->addValue(null, $this->getModuleName(), 'success');
 }
Beispiel #27
0
 public function __construct($array_env)
 {
     $this->search_item = '';
     $this->search_fields = array('login');
     if (array_keys_exists_not_empty(array('search_item'), $array_env) && isset($array_env['search_fields'])) {
         $this->search_item = $array_env['search_item'];
         $this->search_fields = $array_env['search_fields'];
     }
     $prefs = Preferences::getInstance();
     $this->search_limit = $prefs->get('general', 'max_items_per_page');
 }
Beispiel #28
0
function send_alert_mail($subject_, $message_)
{
    $prefs = Preferences::getInstance();
    if (!$prefs) {
        die_error('get Preferences failed', __FILE__, __LINE__);
    }
    $tos = $prefs->get('events', 'mail_to');
    foreach ($tos as $to) {
        sendamail($to, $subject_, $message_);
    }
}
 function execute($par)
 {
     $user = $this->getUser();
     $out = $this->getOutput();
     if (!$user->isAllowed('edituser')) {
         $out->permissionRequired('edituser');
         return false;
     }
     $this->setHeaders();
     $request = $this->getRequest();
     $this->target = isset($par) ? $par : $request->getText('username', '');
     if ($this->target === '') {
         $out->addHtml($this->makeSearchForm());
         return;
     }
     $targetuser = User::NewFromName($this->target);
     if ($targetuser->getID() == 0) {
         $out->addWikiMsg('edituser-nouser', htmlspecialchars($this->target));
         return;
     }
     $this->targetuser = $targetuser;
     #Allow editing self via this interface
     if ($targetuser->isAllowed('edituser-exempt') && $targetuser->getName() != $user->getName()) {
         $out->addWikiMsg('edituser-exempt', $targetuser->getName());
         return;
     }
     $this->setHeaders();
     $this->outputHeader();
     $out->disallowUserJs();
     # Prevent hijacked user scripts from sniffing passwords etc.
     if (wfReadOnly()) {
         $out->readOnlyPage();
         return;
     }
     if ($request->getCheck('reset')) {
         $this->showResetForm();
         return;
     }
     $out->addModules('mediawiki.special.preferences');
     //$this->loadGlobals( $this->target );
     $out->addHtml($this->makeSearchForm() . '<br />');
     #End EditUser additions
     if ($request->getCheck('success')) {
         $out->wrapWikiMsg("<div class=\"successbox\"><strong>\n\$1\n</strong></div><div id=\"mw-pref-clear\"></div>", 'savedprefs');
     }
     if ($request->getCheck('eauth')) {
         $out->wrapWikiMsg("<div class='error' style='clear: both;'>\n\$1\n</div>", 'eauthentsent', $this->target);
     }
     $htmlForm = Preferences::getFormObject($targetuser, $this->getContext(), 'EditUserPreferencesForm', array('password'));
     $htmlForm->setSubmitCallback('Preferences::tryUISubmit');
     $htmlForm->addHiddenField('username', $this->target);
     $htmlForm->show();
 }
Beispiel #30
0
 public function __construct()
 {
     $prefs = Preferences::getInstance();
     if ($prefs) {
         $sql_conf = $prefs->get('general', 'sql');
         if (is_array($sql_conf)) {
             $this->table = $sql_conf['prefix'] . UserGroupDBDynamicCached_internal::$tablename;
         } else {
             $this->table = NULL;
         }
     }
 }