Пример #1
0
 public function get()
 {
     if (is_array($this->filters)) {
         $this->filters = Sanitize::rules($this->filters);
     }
     return Request::get($this->name, $this->default, $this->filters);
 }
Пример #2
0
 public function actionLogout(User $user, CSRF $CSRF)
 {
     $valid = $CSRF->check(Request::get($CSRF->csrfParam));
     if ($valid) {
         $user->logout(true);
     }
     $this->redirect(Url::set()->removeAllArgs()->getAbsolute())->send(true);
 }
 public function actionIndex(User $user, Session $session)
 {
     $placeholders = [];
     if ($session->hasFlash($this->keySessionFlash)) {
         $placeholders['content'] = i18n::t('successActivate');
         return $this->render('success', $placeholders);
     } elseif ($user->isGuest() && ($users = Users::activate(Request::get('token')))) {
         // auto-login
         $user->addMulti($users->toArray(['id', 'username', 'url']));
         $user->login();
         $session->setFlash($this->keySessionFlash);
         $this->response->redirect(Url::set()->removeAllArgs()->getAbsoluteUrl(true))->send(true);
         return null;
     }
     return $this->notPage('@frontend.views/layouts/notPage');
 }
Пример #4
0
 protected function getGlobalsVars()
 {
     if ($this->request->isPost() && in_array('POST', $this->verbs, true)) {
         return Request::post();
     }
     if ($this->request->isGet() && in_array('GET', $this->verbs, true)) {
         return Request::get();
     }
     if ($this->request->isPut() && in_array('PUT', $this->verbs, true)) {
         return Request::post();
     }
     if ($this->request->isDelete() && in_array('DELETE', $this->verbs, true)) {
         return Request::post();
     }
     return [];
 }
 /**
  * Returns items limit.
  * @param bool $recalculate
  * @return int
  */
 public function getLimit($recalculate = false)
 {
     if ($this->limit === null || $recalculate) {
         if ($this->request instanceof Request) {
             $this->limit = $this->request->get($this->limitParam, $this->defaultLimit, Sanitize::positive()->int());
         } else {
             $this->limit = isset($_GET[$this->limitParam]) ? (int) $_GET[$this->limitParam] : $this->defaultLimit;
             if ($this->limit < 0) {
                 $this->limit = $this->defaultLimit;
             }
         }
         if ($this->limit > $this->maxLimit) {
             $this->limit = $this->maxLimit;
         }
     }
     return $this->limit;
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function getAttributes($code = null)
 {
     if (!isset($code)) {
         $code = Request::get('code');
     }
     if (empty($code)) {
         return [];
     }
     // This was a callback request from google, get the token
     $this->service->requestAccessToken($code);
     // Send a request with it
     try {
         return Json::decode($this->service->request($this->apiUrl));
     } catch (JsonException $e) {
         if (class_exists('\\rock\\log\\Log')) {
             Log::err(BaseException::convertExceptionToString($e));
         }
     }
     return [];
 }
Пример #7
0
 /**
  * Returns a value indicating whether the current request has sent the session ID.
  *
  * The default implementation will check cookie and $_GET using the session name.
  * If you send session ID via other ways, you may need to override this method
  * or call {@see \rock\session\Session::setHasSessionId()} to explicitly set whether the session ID is sent.
  * @return boolean whether the current request has sent the session ID.
  */
 public function getHasSessionId()
 {
     if ($this->_hasSessionId === null) {
         $name = $this->getName();
         if (ini_get('session.use_cookies') && !empty($_COOKIE[$name])) {
             $this->_hasSessionId = true;
         } elseif (!ini_get('use_only_cookies') && ini_get('use_trans_sid')) {
             if ($name !== null) {
                 if (class_exists('\\rock\\request\\Request')) {
                     $this->_hasSessionId = (bool) Request::get($name);
                 } else {
                     $this->_hasSessionId = isset($_GET[$name]) && strip_tags($_GET[$name]);
                 }
             }
         } else {
             $this->_hasSessionId = false;
         }
     }
     return $this->_hasSessionId;
 }
Пример #8
0
 /**
  * Negotiates the application language.
  * @param Request $request
  * @return string the chosen language
  */
 protected function negotiateLanguage($request)
 {
     if (!empty($this->languageParam) && ($language = Request::get($this->languageParam)) !== null) {
         if (isset($this->languages[$language])) {
             return $this->languages[$language];
         }
         foreach ($this->languages as $key => $supported) {
             if (is_integer($key) && $this->isLanguageSupported($language, $supported)) {
                 return $supported;
             }
         }
         return $request->getPreferredLanguage();
         //reset($this->languages);
     }
     foreach ($request->getAcceptableLanguages() as $language => $params) {
         if (isset($this->languages[$language])) {
             return $this->languages[$language];
         }
         foreach ($this->languages as $key => $supported) {
             if (is_integer($key) && $this->isLanguageSupported($language, $supported)) {
                 return $supported;
             }
         }
     }
     return $request->getPreferredLanguage();
     //reset($this->languages);
 }
Пример #9
0
 /**
  * @return array the names of the requested fields. The first element is an array
  * representing the list of default fields requested, while the second element is
  * an array of the extra fields requested in addition to the default fields.
  * @see Model::fields()
  * @see Model::extraFields()
  */
 protected function getRequestedFields()
 {
     $fields = Request::get($this->fieldsParam);
     $exclude = Request::get($this->excludeParam);
     return [preg_split('/\\s*,\\s*/', $fields, -1, PREG_SPLIT_NO_EMPTY), preg_split('/\\s*,\\s*/', $exclude, -1, PREG_SPLIT_NO_EMPTY)];
 }
Пример #10
0
 protected function getParam()
 {
     if (empty($this->params)) {
         if ($this->request instanceof Request) {
             return $this->request->get($this->sortParam);
         }
         return isset($_GET[$this->sortParam]) ? strip_tags($_GET[$this->sortParam]) : null;
     }
     return isset($this->params[$this->sortParam]) ? strip_tags($this->params[$this->sortParam]) : null;
 }