Beispiel #1
0
 public function action_index()
 {
     //ログイン用のオブジェクト生成
     $auth = Auth::instance();
     $auth->logout();
     Response::redirect('/');
 }
Beispiel #2
0
 public function sidebar($options = array())
 {
     $identifier = array('nav' => array('id' => 'sidebar', 'class' => 'sidebar nav-collapse collapse'), 'ul' => array('id' => 'side-nav', 'class' => 'side-nav'), 'li' => array('id' => '', 'class' => '', 'role' => ''));
     if (isset($options['nav'])) {
         $identifier['nav'] = $options['nav'];
     }
     if (isset($options['ul'])) {
         $identifier['ul'] = $options['ul'];
     }
     if (isset($options['li'])) {
         $identifier['li'] = $options['li'];
     }
     $ul = ' <nav id="' . $identifier['nav']['id'] . '" class="' . $identifier['nav']['class'] . '">
 				<ul id="' . $identifier['ul']['id'] . '" class="' . $identifier['ul']['class'] . '">';
     foreach ($options['data'] as $k => $v) {
         if (isset($v['filter'])) {
             if ($v['filter'] == '*') {
                 $ul .= '<li><a href="' . Uri::base() . $v['link'] . '">' . $v['name'] . '</a></li>';
             } elseif (in_array(\Auth\Auth::instance()->get('group')->id, $v['filter'])) {
                 $ul .= '<li><a href="' . Uri::base() . $v['link'] . '">' . $v['name'] . '</a></li>';
             }
         }
     }
     $ul .= '</ul></nav>';
     return $ul;
 }
Beispiel #3
0
 public static function admin_login($username_or_email, $password)
 {
     if (Auth::instance()->login($username_or_email, $password)) {
         list(list(, $group_id)) = Auth::get_groups();
         if ($group_id == 100) {
             return true;
         }
     }
     return false;
 }
Beispiel #4
0
 public function before()
 {
     $uri_string = explode('/', Uri::string());
     if (count($uri_string) > 1 and $uri_string[0] == 'user' and $uri_string[1] == 'login') {
         return;
     } else {
         $user_id = \Auth\Auth::instance()->get_user_id()[1];
         /*($user_id);
           exit();*/
         if ($user_id) {
             $user = Model_User::find($user_id);
             if (!$user || $user->group != 100) {
                 Response::redirect('/user/login');
             }
         } else {
             Response::redirect('/user/login');
         }
     }
 }
Beispiel #5
0
 public function post_add()
 {
     $requestData = Input::json();
     $auth = Auth::instance();
     $userData = $auth->get_user_array();
     $post = $requestData['data'];
     $post['Author'] = $userData['screen_name'];
     //Session::get('user.name');
     $date = new \DateTime();
     $post['DateCreate'] = date_format($date, 'Y-m-d H:i:s');
     $post['Tag'] = '';
     $post['Views'] = 0;
     $storyManager = new StoryManager();
     if ($storyManager->createNewStory($post)) {
         Session::set_flash('success', 'Success create new story!');
     } else {
         Session::set_flash('error', 'Server error! Please try again later or contact administrator!');
     }
     Response::redirect('admin/modules/news/add');
 }
Beispiel #6
0
 public function action_index()
 {
     //すでにログイン済であればログイン後のページへリダイレクト
     Auth::check() and Response::redirect('top');
     //エラーメッセージ用変数初期化
     $error = null;
     //ログイン用のオブジェクト生成
     $auth = Auth::instance();
     //ログインボタンが押されたら、ユーザ名、パスワードをチェックする
     if (Input::post()) {
         if ($auth->login(Input::post('username'), Input::post('password'))) {
             // ログイン成功時、ログイン後のページへリダイレクト
             Response::redirect('top');
         } else {
             // ログイン失敗時、エラーメッセージ作成
             $error = 'ユーザ名かパスワードに誤りがあります';
         }
     }
     //ビューテンプレートを呼び出し
     $this->template->content = View::forge('login/index');
     //エラーメッセージをビューにセット
     $this->template->content->set('error', $error);
     $this->template->title = "login";
 }
Beispiel #7
0
 /**
  * @return array
  *
  */
 private function _user_info()
 {
     $group = \Auth\Auth::instance()->get_groups();
     $data = array('id' => \Auth\Auth::instance()->get('id'), 'username' => \Auth\Auth::instance()->get_screen_name(), 'email' => \Auth\Auth::instance()->get_email());
     return $data;
 }
Beispiel #8
0
 public function action_file($folder = null, $size = null, $crop = 'no')
 {
     try {
         if (is_null($folder)) {
             throw new Exception('Folder name is not given!');
         }
         if (is_null($size)) {
             throw new Exception('Image file name is not given!');
         }
         if (!strpos($size, 'x')) {
             throw new Exception('Image size is not given!');
         }
         if (!\Fuel\Core\Input::get('image')) {
             throw new Exception('Image is not given!');
         }
         $file = \Fuel\Core\Input::get('image');
         /** @var  $upload_path */
         $upload_path = '/var/www/html/' . $this->_dir;
         /** @var  $file_path */
         $file_path = $folder . '/' . $file;
         /** @var  $real_path */
         $real_path = $upload_path . '/' . $file_path;
         /** @var  $new_name */
         $new_name = $size . '_' . $file;
         /** @var  $resize_path : Path for resize only */
         $resize_path = $upload_path . '/' . $folder . '/resize/';
         /** @var  $resize_file */
         $resize_file = $upload_path . '/' . $folder . '/resize/' . $new_name;
         /** @var  $crop_path : Path for crop only */
         $crop_path = $upload_path . '/' . $folder . '/crop/';
         /** @var  $crop_file */
         $crop_file = $upload_path . '/' . $folder . '/crop/' . $new_name;
         /** @var  $image */
         $image = \Fuel\Core\Image::forge(array('driver' => 'gd', 'bgcolor' => null, 'quality' => 100));
         /** @var  $where_are_file */
         $where_are_file = '';
         /** @var  $where_are_path */
         $where_are_path = '';
         if ($crop == 'no') {
             $where_are_file = $resize_file;
             $where_are_path = $resize_path;
         } else {
             $where_are_file = $crop_file;
             $where_are_path = $crop_path;
         }
         if (!file_exists($where_are_file)) {
             /**
              *  Check if not dir then make it.
              */
             if (!is_dir($where_are_path)) {
                 if (!mkdir($where_are_path, 0777)) {
                     throw new Exception('Permission denied!');
                 }
             }
             /** @var  $size */
             $size = explode('x', $size);
             if ($crop == 'crop') {
                 /**
                  *  Chaining to crop_resize() function
                  */
                 $image->load($real_path)->crop_resize($size[0], $size[1])->save($where_are_file);
             } else {
                 /**
                  *  Chaining to resize() function
                  */
                 $image->load($real_path)->resize($size[0], $size[1], true, false)->save($where_are_file);
             }
             /**
              *  Load file and output image.
              */
             $image->load($where_are_file)->output();
         } else {
             /**
              *  If file exist force output to show image.
              */
             if (\Fuel\Core\Input::get('action') == 'delete') {
                 if (\Auth\Auth::instance()->get('group') == 100) {
                     $model = Model_Filemanager::find_by_value($file);
                     if ($model) {
                         $model->deleted_at = time();
                         $model->value = null;
                         if ($model->save()) {
                             \Fuel\Core\File::delete($where_are_file);
                             \Fuel\Core\File::delete($real_path);
                             \Fuel\Core\Response::redirect('filemanager/folder/' . $folder);
                         } else {
                             throw new Exception('Cannot delete in database!');
                         }
                     } else {
                         throw new Exception('Image not found!');
                     }
                 } else {
                     throw new Exception('You are not an Administrator!');
                 }
             } else {
                 $image->load($where_are_file)->output();
             }
         }
     } catch (Exception $e) {
         /** @var  $error */
         $error = '<ul>';
         $error .= '<li>' . $e->getLine() . '</li>';
         $error .= '<li>' . $e->getFile() . '</li>';
         $error .= '<li>' . $e->getMessage() . '</li>';
         $error .= '</ul>';
         return $error;
     }
     exit;
 }