예제 #1
0
파일: Entity.php 프로젝트: johnstyle/sjo
 public function request($name)
 {
     if (Request::env('POST')->{$name}->exists()) {
         return Request::env('POST')->{$name}->val();
     }
     return isset($this->{$name}) ? $this->{$name} : null;
 }
예제 #2
0
파일: Alert.php 프로젝트: johnstyle/sjo
 public static function get()
 {
     $alert = self::$alerts;
     unset(Request::env('SESSION')->alerts);
     self::$alerts = null;
     return $alert;
 }
예제 #3
0
파일: Token.php 프로젝트: johnstyle/sjo
 public static function has($type = 'REQUEST')
 {
     if (Request::env($type)->token->eq(self::get(Router::getToken()))) {
         return true;
     }
     return false;
 }
예제 #4
0
파일: Manager.php 프로젝트: johnstyle/sjo
 public function delete()
 {
     if (Request::env('REQUEST')->{Admin::getInstance()->getPrimaryKey()}->val() == 1) {
         Alert::set(I18n::__('Vous ne pouvez pas supprimer cet administrateur.'));
         Http::redirect(Router::linkBack(Router::$controller));
     }
     parent::delete(new Admin());
 }
예제 #5
0
 public function display()
 {
     header('Content-type:application/json; charset=utf-8');
     if (Request::env('REQUEST')->callback->exsist()) {
         echo Request::env('REQUEST')->callback->val() . '(' . json_encode($this->callback()) . ');';
     } else {
         echo json_encode($this->callback());
     }
     exit;
 }
예제 #6
0
파일: Auth.php 프로젝트: johnstyle/sjo
 public static function secure()
 {
     $rc = new \ReflectionClass(self::model());
     $modelName = $rc->getShortName();
     if (Router::$controller !== $modelName . '\\Auth') {
         if (!self::model()->isLogged()) {
             http_response_code(401);
             Http::redirect(Router::link(Router::$interface, $modelName . '\\Auth', array('redirect' => Request::env('SERVER')->REQUEST_URI->val())));
         }
     } elseif (self::model()->isLogged() && !Router::$method) {
         Http::redirect(Router::link());
     }
 }
예제 #7
0
파일: Auth.php 프로젝트: johnstyle/sjo
 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'));
     }
 }
예제 #8
0
파일: Image.php 프로젝트: johnstyle/sjo
 /**
  * @param $dest
  *
  * @throws \sJo\File\UploadException
  * @return bool
  */
 public function copy($dest)
 {
     $src = Request::env('FILES')->{$this->requestName}->tmp_name->val();
     list($width, $height, $type) = getimagesize($src);
     $newWidth = $width;
     $newHeight = $height;
     $source = null;
     switch ($type) {
         case IMG_GIF:
             $source = imagecreatefromgif($src);
             break;
         case IMG_JPG:
             $source = imagecreatefromjpeg($src);
             break;
         case IMG_PNG:
             $source = imagecreatefrompng($src);
             break;
     }
     if (is_null($source)) {
         throw new UploadException(I18n::__('Error image mime'));
     }
     if ($height > self::IMAGE_MAX_HEIGHT) {
         $newWidth = self::IMAGE_MAX_HEIGHT / $height * $width;
         $newHeight = self::IMAGE_MAX_HEIGHT;
     }
     if ($width > self::IMAGE_MAX_WIDTH) {
         $newHeight = self::IMAGE_MAX_WIDTH / $width * $height;
         $newWidth = self::IMAGE_MAX_WIDTH;
     }
     $img = imagecreatetruecolor($newWidth, $newHeight);
     imagecopyresampled($img, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
     if (!imagejpeg($img, $dest, static::IMAGE_QUALITY)) {
         throw new UploadException(I18n::__('Error image create.'));
     }
     return true;
 }
예제 #9
0
파일: Router.php 프로젝트: johnstyle/sjo
 private static function loadMethod()
 {
     self::$method = Request::env('REQUEST')->{self::$__map['method']['name']}->val(self::$__map['method']['default'], true);
 }
예제 #10
0
파일: Logger.php 프로젝트: johnstyle/sjo
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed $level
  * @param string $message
  * @param array $context
  * @return null
  */
 public function log($level, $message, array $context = array())
 {
     File::append(SJO_ROOT_LOG . '/app.' . $level . '.log', date('Y-m-d H:i:s') . "\t" . Request::env('SERVER')->REQUEST_URI->val() . "\t" . self::interpolate($message, $context) . "\n");
 }
예제 #11
0
파일: Upload.php 프로젝트: johnstyle/sjo
 /**
  * @param $dest
  *
  * @return bool
  */
 public function copy($dest)
 {
     return File::copy(Request::env('FILES')->{$this->requestName}->tmp_name->val(), $dest);
 }
예제 #12
0
파일: Map.php 프로젝트: johnstyle/sjo
 public static function getPrimaryRequest($type = 'GET')
 {
     return Request::env($type)->{static::getInstance()->getPrimaryKey()}->val();
 }
예제 #13
0
파일: Auth.php 프로젝트: johnstyle/sjo
 public static function cookie()
 {
     return Request::env('COOKIES')->{__CLASS__};
 }
예제 #14
0
파일: Auth.php 프로젝트: johnstyle/sjo
?>
" />
    <title><?php 
Lib\I18n::_e('Authentification');
?>
</title>
    <meta name="description" content="<?php 
Lib\I18n::_e('Authentification');
?>
">
    <?php 
if (Helper\Style::hasRegistry()) {
    ?>
        <?php 
    Helper\Style::applyRegistry();
    ?>
    <?php 
}
?>
    <style type="text/css">
        body{background:#333}
        form{background:#fff;width:300px;margin:150px auto 0;padding:0 20px 20px;border:5px solid #000;border-radius:10px;box-shadow:0 0 10px #000}
    </style>
</head>
<body>

<?php 
Helper\Form::create(array(Helper\Fieldset::create(array(Helper\Token::create(Router::getToken('signin')), Helper\Container::create(array('tagname' => 'h2', 'attributes' => array('class' => 'form-signin-heading'), 'elements' => Lib\I18n::__('Authentification'))), Helper\Alert::create(), Helper\Input::create(array('attributes' => array('name' => 'email', 'value' => Request::env('POST')->email->val(), 'placeholder' => Lib\I18n::__('Adresse email'), 'autofocus' => true))), Helper\Input::create(array('attributes' => array('type' => 'password', 'name' => 'password', 'placeholder' => Lib\I18n::__('Mot de passe')))), Helper\Button::create(array('attributes' => array('class' => 'btn-lg btn-block btn-primary', 'value' => Lib\I18n::__('Connexion'))))))))->render();
?>
</body>
</html>
예제 #15
0
파일: Loader.php 프로젝트: johnstyle/sjo
 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');
 }
예제 #16
0
파일: Form.php 프로젝트: johnstyle/sjo
 /**
  * @return bool
  */
 protected function validateForm()
 {
     foreach ($this->getFormFields() as $name => $attr) {
         // Get field label
         $label = $this->getFieldLabel($name);
         if (isset($attr['validate'])) {
             if (Validate::isCallable($attr['validate'])) {
                 call_user_func($attr['validate'], $attr, $name, $label);
             } elseif (preg_match("#^:([[:alnum:]]+)\$#", $attr['validate'], $match)) {
                 if (Request::env('POST')->{$name}->val() !== Request::env('POST')->{$match[1]}->val()) {
                     $this->setError($name, I18n::__('The field %s must be identical to %s.', '<strong>' . $label . '</strong>', '<strong>' . $this->getFieldLabel($match[1]) . '</strong>'));
                 }
             }
         }
     }
     return !$this->hasErrors();
 }