/** * Constructor. * * @param sfUser A sfUser instance * @param array An array of options * @param string A CSRF secret (false to disable CSRF protection, null to use the global CSRF secret) * * @see sfForm */ public function __construct(sfUser $user, $options = array(), $CSRFSecret = null) { $this->user = $user; parent::__construct(array(), $options, $CSRFSecret); // the defaults depend on the options, so set them after construction $this->setDefaults(array('max_per_page' => $user->getAttribute(self::getMaxPerPageName(), self::getMaxPerPageValue()))); }
/** * Constructor. * * @param sfUser A sfUser instance * @param array An array of options * @param string A CSRF secret (false to disable CSRF protection, null to use the global CSRF secret) * * @see sfForm */ public function __construct(sfUser $user, $options = array(), $CSRFSecret = null) { $this->user = $user; if (!isset($options['languages'])) { throw new RuntimeException(sprintf('%s requires a "languages" option.', get_class($this))); } parent::__construct(array('language' => $user->getCulture()), $options, $CSRFSecret); }
public function getUser() { static $user; if (!$user) { $user = new sfUser(); $user->initialize($this); } return $user; }
protected static function undeleteFlash(sfUser $user) { $attributeHolder = $user->getAttributeHolder(); if ($names = $attributeHolder->getNames('symfony/user/sfUser/flash')) { foreach ($names as $name) { $attributeHolder->remove($name, null, 'symfony/user/sfUser/flash/remove'); } } }
/** * * @param Doctrine_Query $query * @param sfUser $user * @param type $alias * @return Doctrine_Query */ public function filterScope(Doctrine_Query $query, sfUser $user, $alias = 'l') { $where = "{$alias}.location_scope_id = 5"; if (!$user->isAnonymous()) { $uniq = self::$uniq++; $where .= "\r\n or {$alias}.location_scope_id = 1\r\n or {$alias}.location_scope_id = 3\r\n or {$alias}.created_by = " . $user->getProfile()->id . "\r\n or {$alias}.created_by in (SELECT fa{$uniq}.accepter_id FROM friend fa{$uniq} WHERE fa{$uniq}.accepted = 1 and fa{$uniq}.requester_id = " . $user->getProfile()->id . ")\r\n or {$alias}.created_by in (SELECT fr{$uniq}.requester_id FROM friend fr{$uniq} WHERE fr{$uniq}.accepted = 1 and fr{$uniq}.accepter_id = " . $user->getProfile()->id . ")"; } $query->addWhere($where); return $query; }
/** * Redirect process for a failed login * * @param sfRequest $request * @param sfUser $user * @return mixed */ protected function _redirectError($request, $user) { if ($request->isXmlHttpRequest()) { $this->getResponse()->setHeaderOnly(true); $this->getResponse()->setStatusCode(401); return sfView::NONE; } // if we have been forwarded, then the referer is the current URL // if not, this is the referer of the current request $user->setReferer($this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer()); $this->redirect(sfConfig::get('sf_login_module') . '/' . sfConfig::get('sf_login_action')); }
/** * Triggers a flash drop-down based on the flashes in the user * * @param sfUser $user */ function trigger_flash_from_user($user) { $validTypes = array('info', 'saved', 'error'); foreach ($validTypes as $validType) { if ($user->hasFlash($validType)) { return sprintf(' <script type="text/javascript"> $(document).ready(function(){ $.showFlashMessage("%s", "%s"); }); </script>', $validType, addslashes($user->getFlash($validType))); } } }
static function createByTokenAndUser($token, sfUser $user) { $rpx = new RPX(); $response = $rpx->call('auth_info', array('token' => $token)); if ($response->stat == 'ok') { //Save if not found already if (!Doctrine::getTable('sfAuthIdentity')->findOneByUrl($response->profile->identifier)) { //Assign $identity = new sfAuthIdentity(); $identity->sf_auth_user_id = $user->getId(); $identity->url = $response->profile->identifier; $identity->provider = $response->profile->providerName; //Save return $identity->save(); } return 'Identity already exists'; } return 'Could not retrieve user profile from partner'; }
/** * visszaadja a kért beállÃtást * ha nem találja egy fallback soron megy keresztül: * - hgabkaSfSettingHandler setting tömb * - fileCache * - load() - végsÅ‘ soron adatbázisból kapja meg * * @param string $settingName * @return object sfSetting */ public function getSetting($settingName) { // megnézzük, hogy jó-e a paraméterezés ($settingName) $settingName = $this->validateStringParameter($settingName); if ($this->hasOneRuntime($settingName)) { // ha igen, akkor vissza is térünk vele return $this->getFromRuntime($settingName); } elseif ($this->cache->hasSetting($settingName)) { // ha a fileCache-ben van, akkor vissza is adjuk $values = $this->cache->getSetting($settingName); return $values[$this->request->getLocale()]; } else { // ha nem voltak betöltve, akkor betöltjük a load függvénnyel if ($this->load($settingName)) { // a beállÃtás be lett töltve, visszaadhatjuk if ($this->hasOneRuntime($settingName)) { return $this->getFromRuntime($settingName); } else { return null; } } } }
public function shutdown() { $storage = $this->getContext()->getStorage(); // write the last request time to the storage $storage->write(self::LAST_REQUEST_NAMESPACE, $this->lastRequest); $storage->write(self::AUTH_NAMESPACE, $this->authenticated); $storage->write(self::CREDENTIAL_NAMESPACE, $this->credentials); // call the parent shutdown method parent::shutdown(); }
<?php // auto-generated by sfFactoryConfigHandler // date: 2009/08/15 10:45:03 $this->controller = sfController::newInstance(sfConfig::get('sf_factory_controller', 'sfFrontWebController')); $this->request = sfRequest::newInstance(sfConfig::get('sf_factory_request', 'sfWebRequest')); $this->response = sfResponse::newInstance(sfConfig::get('sf_factory_response', 'sfWebResponse')); $this->storage = sfStorage::newInstance(sfConfig::get('sf_factory_storage', 'sfSessionStorage')); $this->user = sfUser::newInstance(sfConfig::get('sf_factory_user', 'myUser')); $this->controller->initialize($this); $this->request->initialize($this, sfConfig::get('sf_factory_request_parameters', NULL), sfConfig::get('sf_factory_request_attributes', array())); $this->response->initialize($this, sfConfig::get('sf_factory_response_parameters', NULL)); $this->storage->initialize($this, sfConfig::get('sf_factory_storage_parameters', array('session_name' => 'symfony'))); $this->user->initialize($this, sfConfig::get('sf_factory_user_parameters', NULL)); if (sfConfig::get('sf_cache')) { $this->viewCacheManager = new sfViewCacheManager(); $this->viewCacheManager->initialize($this, sfConfig::get('sf_factory_view_cache', 'sfFileCache'), sfConfig::get('sf_factory_view_cache_parameters', array('automaticCleaningFactor' => 0, 'cacheDir' => '/Users/takizo/Sites/coscupdemo/cache/frontend/dev/template'))); }
/** * Create a new blog post. * * @throws sfInvalidException If a post with this slug already exists * * @param string $post_slug The post slug (permalink) * @param string $post_title The post title * @param string $post_body The post body * @param sfUser $post_author The authot's sfUser (or derivative) object * @param string $category An optional category for separating blog posts * @return sfBlogPost The generated object */ public static function makePost($slug, $post_title, $post_body, sfUser $post_author, $category = NULL) { $slug_check = sfCore::$db->query("SELECT count(*) FROM `swossh_blog_posts` WHERE `slug` = %s LIMIT 1;"); if ($slug_check->fetchScalar() == 1) { throw new sfInvalidException(array('slug' => sfInvalidException::EXISTING)); } $new_post = sfCore::$db->query("INSERT INTO `swoosh_blog_posts` (\n\t\t\t`post_id`, `title`, `author_id`, `timestamp`, `category`, `comments_enabled`, `slug`)\n\t\t\tVALUES (\n\t\t\t\tNULL, %s, %i, NOW(), %s, 1, %s)", $post_title, $post_author->getId(), $category, $slug); $post_body = sfCore::$db->query("INSERT INTO `swoosh_blog_contents` (\n\t\t\t`post_id`, `content`)\n\t\t\tVALUES (%i, %s)", $new_post->getAutoIncrementedValue(), $post_body); $obj = sfCore::make('sfBlogPost'); $obj->load($new_post->getAutoIncrementedValue()); return $obj; }
/** * Update storage with callables for the next tracker. * * @param sfUser $user */ public function shutdown($user) { if (sfConfig::get('sf_logging_enabled')) { sfGoogleAnalyticsToolkit::logMessage($this, 'Copying callables to session storage.'); } $user->getAttributeHolder()->set('callables', $this->parameterHolder->getAll('flash', array()), 'sf_google_analytics_plugin'); }
/** * Check if the user the necessary credentials to see this particular item * * @param array $item * @param sfUser $user */ public static function hasPermission($item, $user) { if (!$user->isAuthenticated()) { return false; } return isset($item['credentials']) ? $user->hasCredential($item['credentials']) : true; }
// ->setCulture() ->getCulture() $t->diag('->setCulture() ->getCulture()'); $user->setCulture('fr'); $t->is($user->getCulture(), 'fr', '->setCulture() changes the current user culture'); // ->setFlash() ->getFlash() ->hasFlash() $t->diag('->setFlash() ->getFlash() ->hasFlash()'); $user->initialize($dispatcher, $storage, array('use_flash' => true)); $user->setFlash('foo', 'bar'); $t->is($user->getFlash('foo'), 'bar', '->setFlash() sets a flash variable'); $t->is($user->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists'); user_flush($dispatcher, $user, $storage, array('use_flash' => true)); $userBis = new sfUser($dispatcher, $storage, array('use_flash' => true)); $t->is($userBis->getFlash('foo'), 'bar', '->getFlash() returns a flash previously set'); $t->is($userBis->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists'); user_flush($dispatcher, $user, $storage, array('use_flash' => true)); $userBis = new sfUser($dispatcher, $storage, array('use_flash' => true)); $t->is($userBis->getFlash('foo'), null, 'Flashes are automatically removed after the next request'); $t->is($userBis->hasFlash('foo'), false, '->hasFlash() returns true if the flash variable exists'); // array access for user attributes $user->setAttribute('foo', 'foo'); $t->diag('Array access for user attributes'); $t->is(isset($user['foo']), true, '->offsetExists() returns true if user attribute exists'); $t->is(isset($user['foo2']), false, '->offsetExists() returns false if user attribute does not exist'); $t->is($user['foo3'], false, '->offsetGet() returns false if attribute does not exist'); $t->is($user['foo'], 'foo', '->offsetGet() returns attribute by name'); $user['foo2'] = 'foo2'; $t->is($user['foo2'], 'foo2', '->offsetSet() sets attribute by name'); unset($user['foo2']); $t->is(isset($user['foo2']), false, '->offsetUnset() unsets attribute by name'); $user = new sfUser($dispatcher, $storage); // attribute holder proxy
/** * Returns user parameters as an array. * * @param sfUser $user A sfUser instance * * @return array The user parameters */ public static function userAsArray(sfUser $user = null) { if (!$user) { return array(); } return array('options' => $user->getOptions(), 'attributeHolder' => self::flattenParameterHolder($user->getAttributeHolder()), 'culture' => $user->getCulture()); }
/* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../bootstrap.php'; require_once dirname(__FILE__) . '/../../lib/form/sfFormLanguage.class.php'; $t = new lime_test(9, new lime_output_color()); // initialize objects $dispatcher = new sfEventDispatcher(); $sessionPath = sys_get_temp_dir() . '/sessions_' . rand(11111, 99999); $storage = new sfSessionTestStorage(array('session_path' => $sessionPath)); $user = new sfUser($dispatcher, $storage); $user->setCulture('en'); $request = new sfWebRequest($dispatcher); // __construct() $t->diag('__construct()'); try { new sfFormLanguage($user); $t->fail('__construct() throws a RuntimeException if you don\'t pass a "languages" option'); } catch (RuntimeException $e) { $t->pass('__construct() throws a RuntimeException if you don\'t pass a "languages" option'); } $form = new sfFormLanguage($user, array('languages' => array('en', 'fr'))); $t->is($form->getDefault('language'), 'en', '__construct() sets the default language value to the user language'); $w = $form->getWidgetSchema(); $t->is($w['language']->getOption('languages'), array('en', 'fr'), '__construct() uses the "languages" option for the select form widget'); $v = $form->getValidatorSchema();
/** * save cart to session */ public function save() { $this->_user->setAttribute('cart_items', $this->_items, tpyCart::SESSION_NS); }
protected function initialize() { $this->logger = sfLogger::getInstance(); if (sfConfig::get('sf_logging_enabled')) { $this->logger->info('{sfContext} initialization'); } if (sfConfig::get('sf_use_database')) { $this->databaseManager = new sfDatabaseManager(); $this->databaseManager->initialize(); } $this->actionStack = new sfActionStack(); $this->controller = sfController::newInstance(sfConfig::get('sf_factory_controller', 'sfFrontWebController')); $this->request = sfRequest::newInstance(sfConfig::get('sf_factory_request', 'sfWebRequest')); $this->response = sfResponse::newInstance(sfConfig::get('sf_factory_response', 'sfWebResponse')); $this->storage = sfStorage::newInstance(sfConfig::get('sf_factory_storage', 'sfSessionStorage')); $this->user = sfUser::newInstance(sfConfig::get('sf_factory_user', 'myUser')); $this->controller->initialize($this); $this->request->initialize($this, sfConfig::get('sf_factory_request_parameters', NULL), sfConfig::get('sf_factory_request_attributes', array())); $this->response->initialize($this, sfConfig::get('sf_factory_response_parameters', NULL)); $this->storage->initialize($this, sfConfig::get('sf_factory_storage_parameters', array('session_name' => 'symfony'))); $this->user->initialize($this, sfConfig::get('sf_factory_user_parameters', NULL)); if (sfConfig::get('sf_cache')) { $this->viewCacheManager = new sfViewCacheManager(); $this->viewCacheManager->initialize($this, sfConfig::get('sf_factory_view_cache', 'sfFileCache'), sfConfig::get('sf_factory_view_cache_parameters', array('automaticCleaningFactor' => 0, 'cacheDir' => 'C:\\xampp\\htdocs\\bm400\\cache\\pmbonline\\dev\\template'))); } register_shutdown_function(array($this, 'shutdown')); }
public function findOneByIdUser($id, sfUser $user) { $q = $this->createQuery('i'); $q->addWhere('i.id = ? AND i.sf_auth_user_id = ?', array($id, $user->getId())); return $q->fetchOne(); }
protected function initialize() { $this->logger = sfLogger::getInstance(); if (sfConfig::get('sf_logging_enabled')) { $this->logger->info('{sfContext} initialization'); } if (sfConfig::get('sf_use_database')) { $this->databaseManager = new sfDatabaseManager(); $this->databaseManager->initialize(); } $this->actionStack = new sfActionStack(); // 'config/factories.yml' config file // auto-generated by sfFactoryConfigHandler // date: 2015/09/01 13:56:04 $this->controller = sfController::newInstance(sfConfig::get('sf_factory_controller', 'sfFrontWebController')); $this->request = sfRequest::newInstance(sfConfig::get('sf_factory_request', 'sfWebRequest')); $this->response = sfResponse::newInstance(sfConfig::get('sf_factory_response', 'sfWebResponse')); $this->storage = sfStorage::newInstance(sfConfig::get('sf_factory_storage', 'sfSessionStorage')); $this->user = sfUser::newInstance(sfConfig::get('sf_factory_user', 'myUser')); $this->controller->initialize($this); $this->request->initialize($this, sfConfig::get('sf_factory_request_parameters', NULL), sfConfig::get('sf_factory_request_attributes', array())); $this->response->initialize($this, sfConfig::get('sf_factory_response_parameters', NULL)); $this->storage->initialize($this, sfConfig::get('sf_factory_storage_parameters', array('session_name' => 'symfony'))); $this->user->initialize($this, sfConfig::get('sf_factory_user_parameters', NULL)); if (sfConfig::get('sf_cache')) { $this->viewCacheManager = new sfViewCacheManager(); $this->viewCacheManager->initialize($this, sfConfig::get('sf_factory_view_cache', 'sfFileCache'), sfConfig::get('sf_factory_view_cache_parameters', array('automaticCleaningFactor' => 0, 'cacheDir' => '/Applications/MAMP/trademark/cache/backend/prod/template'))); } register_shutdown_function(array($this, 'shutdown')); }
$storage->clear(); $context->storage = $storage; $user = new sfUser(); $user->initialize($context); $context->user = $user; // ->initialize() $t->diag('->initialize()'); $t->is($user->getCulture(), 'en', '->initialize() sets the culture to "en" by default'); sfConfig::set('sf_i18n_default_culture', 'de'); $user->setCulture(null); user_flush($context); $t->is($user->getCulture(), 'de', '->initialize() sets the culture to the value of sf_i18n_default_culture if available'); sfConfig::set('sf_i18n_default_culture', 'fr'); user_flush($context); $t->is($user->getCulture(), 'de', '->initialize() reads the culture from the session data if available'); $userBis = new sfUser(); $userBis->initialize($context); $t->is($userBis->getCulture(), 'de', '->intialize() serializes the culture to the session data'); // ->setCulture() ->getCulture() $t->diag('->setCulture() ->getCulture()'); $user->setCulture('fr'); $t->is($user->getCulture(), 'fr', '->setCulture() changes the current user culture'); // parameter holder proxy require_once $_test_dir . '/unit/sfParameterHolderTest.class.php'; $pht = new sfParameterHolderProxyTest($t); $pht->launchTests($user, 'parameter'); // attribute holder proxy require_once $_test_dir . '/unit/sfParameterHolderTest.class.php'; $pht = new sfParameterHolderProxyTest($t); $pht->launchTests($user, 'attribute'); // mixins
/** * Returns user parameters as an array. * * @param sfUser $user A sfUser instance * * @return array The user parameters */ public static function userAsArray(sfUser $user = null) { if (!$user) { return array(); } $data = array('options' => $user->getOptions(), 'attributeHolder' => self::flattenParameterHolder($user->getAttributeHolder(), true), 'culture' => $user->getCulture()); if ($user instanceof sfBasicSecurityUser) { $data = array_merge($data, array('authenticated' => $user->isAuthenticated(), 'credentials' => $user->getCredentials(), 'lastRequest' => $user->getLastRequestTime())); } return $data; }
public static function search($criteria, sfUser $user) { $c = new Criteria(); $c->addSelectColumn(self::ID . ' ID'); $c->addSelectColumn(self::USERNAME . ' NAME'); $c->addSelectColumn(self::NAME . ' DESCRIPTION'); $tableName = self::TABLE_NAME; $c->addSelectColumn("'{$tableName}' TNAME"); $c->add(self::HIDDEN, 0); if ($user->isAuthenticated()) { $c->add(self::ID, $user->getRaykuUserId(), Criteria::NOT_EQUAL); } $cton = $c->getNewCriterion(self::USERNAME, "%{$criteria}%", Criteria::LIKE); $cton->addOr($c->getNewCriterion(self::NAME, "%{$criteria}%", Criteria::LIKE)); $cton->addOr($c->getNewCriterion(self::EMAIL, "%{$criteria}%", Criteria::LIKE)); $c->add($cton); return self::doSelectStmt($c); }