public static function isLogged() { if (static::session()->{static::getInstance()->getPrimaryKey()}->exists() && static::session()->token->eq(Token::get(static::getSessionId()))) { return true; } return false; }
public function setElement($element) { $token = isset($element[$this->wrapper][0]) ? $element[$this->wrapper][0] : null; $controller = null; $method = null; if ($token) { if (preg_match("#^([a-z]+(\\\\([a-z]+))?)(" . Router::$__map['method']['separator'] . "([a-z]+))?\$#i", $token, $match)) { $controller = $match[1]; $method = $match[5]; } $token = Loader\Token::get($token); } $element['elements'] = array(self::createStatic('Input', Lib\Arr::extend(self::$element, array('attributes' => array('name' => 'token', 'value' => $token)))), self::createStatic('Input', Lib\Arr::extend(self::$element, array('attributes' => array('name' => 'controller', 'value' => $controller)))), self::createStatic('Input', Lib\Arr::extend(self::$element, array('attributes' => array('name' => 'method', 'value' => $method))))); return $element; }
public function signin() { if (Request::env('POST')->email->exists()) { if (Request::env('POST')->password->exists()) { if ($id = self::model()->exists(Request::env('POST')->email->val(), Request::env('POST')->password->val())) { Logger::getInstance()->info('Signin {admin}', array('admin' => Request::env('POST')->email->val())); self::model()->session()->id = $id; self::model()->session()->token = Token::get($id); $url = SJO_BASEHREF; if (preg_match('#^(\\./|/)#', Request::env('GET')->redirect->val())) { $url = Request::env('GET')->redirect->val(); } Http::redirect($url); } else { Alert::set(Lib\I18n::__('Les informations de connexion sont incorrects')); } } else { Alert::set(Lib\I18n::__('Veuillez renseigner votre mot de passe')); } } else { Alert::set(Lib\I18n::__('Veuillez renseigner votre identifiant')); } }
public function display() { $render = null; if (Router::$method) { switch (Request::env('GET')->content_type->val()) { case 'json': header('Content-type:application/json; charset=' . SJO_CHARSET); if (method_exists(Router::$controllerClass, Router::$method)) { if (Token::has()) { echo json_encode($this->instance->{Router::$method}()); } else { $this->ErrorDocument('http403', Lib\I18n::__('Warning ! Prohibited queries.')); } } exit; break; default: header('Content-type:text/html; charset=' . SJO_CHARSET); if (method_exists(Router::$controllerClass, Router::$method)) { if (Request::env('POST')->exists()) { if (Token::has()) { $render = $this->instance->{Router::$method}(); } else { $this->ErrorDocument('http403', Lib\I18n::__('Warning ! Prohibited queries.')); } } else { $render = $this->instance->{Router::$method}(); } } break; } } $this->event('loadedView'); $this->view->display($render); $this->event('displayedView'); }
/** * @param string $type * * @return bool */ public function isSubmitedForm($type = 'POST') { return Request::env($type)->exists() && Token::has($type); }