Beispiel #1
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $page = $this->getServiceContainer()->getKernel()->getApplication()->getPage();
     $page->setTitle($this->getServiceContainer()->getTranslator()->trans('sessions'));
     if ($request->isMethod('POST')) {
         $post = $request->request;
         if ($post->has('token')) {
             SessionQuery::create()->findOneByToken($post->get('token'))->delete();
             $service = $this->getServiceContainer();
             $accountUrl = $service->getPreferenceLoader()->getSystemPreferences()->getAccountUrl();
             $translator = $service->getTranslator();
             $url = sprintf('%s%s/%s', $accountUrl, $translator->trans('slug.settings'), $translator->trans('slug.settings.sessions'));
             return new RedirectResponse($url);
         }
     }
     return $this->responder->run($request);
 }
Beispiel #2
0
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @throws LogicException if no primary key is defined
  *
  * @return Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = ChildSessionQuery::create();
     $criteria->add(SessionTableMap::COL_TOKEN, $this->token);
     return $criteria;
 }
Beispiel #3
0
 /**
  * Internal update mechanism of Sessions on User
  * 
  * @param User $model
  * @param mixed $data
  */
 protected function doUpdateSessions(User $model, $data)
 {
     // remove all relationships before
     SessionQuery::create()->filterByUser($model)->delete();
     // add them
     $errors = [];
     foreach ($data as $entry) {
         if (!isset($entry['id'])) {
             $errors[] = 'Missing id for Session';
         } else {
             $related = SessionQuery::create()->findOneById($entry['id']);
             $model->addSession($related);
         }
     }
     if (count($errors) > 0) {
         throw new ErrorsException($errors);
     }
 }
Beispiel #4
0
 /**
  * Returns a new ChildSessionQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildSessionQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildSessionQuery) {
         return $criteria;
     }
     $query = new ChildSessionQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Beispiel #5
0
 /**
  * Returns the number of related Session objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related Session objects.
  * @throws PropelException
  */
 public function countSessions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collSessionsPartial && !$this->isNew();
     if (null === $this->collSessions || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collSessions) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getSessions());
         }
         $query = ChildSessionQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByUser($this)->count($con);
     }
     return count($this->collSessions);
 }
Beispiel #6
0
 /**
  *
  * @param User $user
  * @return Session|null
  */
 private function findSession(User $user)
 {
     $request = Request::createFromGlobals();
     $ua = $request->headers->get('User-Agent');
     $detector = new DeviceDetector($ua);
     $detector->skipBotDetection(true);
     $detector->parse();
     return SessionQuery::create()->filterByUserId($user->getId())->filterByBrowser($detector->getClient('name'))->filterByOs($detector->getOs('name'))->findOne();
 }
Beispiel #7
0
 /**
  * Performs an INSERT on the database, given a Session or Criteria object.
  *
  * @param mixed               $criteria Criteria or Session object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *                         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(SessionTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Session object
     }
     // Set the correct dbName
     $query = SessionQuery::create()->mergeWith($criteria);
     // use transaction because $criteria could contain info
     // for more than one table (I guess, conceivably)
     return $con->transaction(function () use($con, $query) {
         return $query->doInsert($con);
     });
 }
Beispiel #8
0
 /**
  * Returns one Session with the given id from cache
  * 
  * @param mixed $id
  * @return Session|null
  */
 protected function get($id)
 {
     if ($this->pool === null) {
         $this->pool = new Map();
     } else {
         if ($this->pool->has($id)) {
             return $this->pool->get($id);
         }
     }
     $model = SessionQuery::create()->findOneById($id);
     $this->pool->set($id, $model);
     return $model;
 }