コード例 #1
0
ファイル: Authorization.php プロジェクト: qlsove/chat
 public function action_registration()
 {
     Request::initial()->is_ajax() || die;
     $emailsignup = ORM::factory('User')->checkUser('email', $this->request->post('emailsignup'));
     $usernamesignup = ORM::factory('User')->checkUser('username', $this->request->post('usernamesignup'));
     if ($emailsignup->loaded() || $usernamesignup->loaded()) {
         if ($emailsignup->loaded()) {
             $message[0]['text'] = "User with this email is already exist!";
             $message[0]['item'] = "emailsignup";
             $message[0]['status'] = "error";
         }
         if ($usernamesignup->loaded()) {
             $message[1]['text'] = "User with username email is already exist!";
             $message[1]['item'] = "usernamesignup";
             $message[1]['status'] = "error";
         }
         die(json_encode($message));
     }
     $token = md5(time() . $this->request->post('usernamesignup') . $this->request->post('emailsignup'));
     $data = array('username' => $this->request->post('usernamesignup'), 'email' => $this->request->post('emailsignup'), 'password' => $this->request->post('passwordsignup'), 'password_confirm' => $this->request->post('passwordsignup_confirm'), 'token' => $token);
     $user = ORM::factory('User')->create_user($data, array('username', 'email', 'password', 'token'));
     $url = URL::site(NULL, TRUE) . 'approved?token=' . $token;
     $config = Kohana::$config->load('email');
     $from = $config['email'];
     $to = $this->request->post('emailsignup');
     $subject = "Registration approval";
     $text = "Thank you for registration on our site! You must follow this link to activate your account: " . $url;
     Email::connect($config['main']);
     Email::send($to, $from, $subject, $text, $html = false);
     $message[0]['text'] = "Link to activate your account sent for your email";
     $message[0]['item'] = "emailsignup";
     $message[0]['status'] = "ok";
     die(json_encode($message));
 }
コード例 #2
0
ファイル: Core.php プロジェクト: HappyKennyD/teest
 public function before()
 {
     parent::before();
     // detecting language, setting it
     $this->detect_language();
     $this->set('_language', $this->language);
     // creating and attaching page metadata
     $this->metadata = new Model_Metadata();
     $this->metadata->title(__(Application::instance()->get('title')), false);
     $this->set('_metadata', $this->metadata);
     //TODO: token auth
     /*
             if ($this->request->method() == Request::POST && Arr::get($_POST, 'token', '') !== Security::token())
             {
        throw new HTTP_Exception_403('Wrong token data');
             }
     */
     $this->set('_token', Security::token());
     // Handles return urls, cropping language out of it (will be appended by url.site at redirect time)
     $rr = Request::initial()->uri();
     $rr = trim($rr, '/');
     $rr = explode('/', $rr);
     if (in_array($rr[0], Application::instance()->get('language.list'))) {
         array_shift($rr);
     }
     $rr = implode('/', $rr);
     $this->set('_return', $rr);
     // detecting if user is logged in
     if (method_exists(Auth::instance(), 'auto_login')) {
         Auth::instance()->auto_login();
     }
     $this->user = Auth::instance()->get_user();
     $this->set('_user', $this->user);
 }
コード例 #3
0
 /**
  * Execute elFinder command and output result
  *
  * @return void
  * @author Dmitry (dio) Levashov
  **/
 public function run()
 {
     $isPost = Request::initial()->method() === Request::POST;
     $src = $_SERVER["REQUEST_METHOD"] == Request::POST ? Request::initial()->post() : Request::initial()->query();
     $cmd = isset($src['cmd']) ? $src['cmd'] : '';
     $args = array();
     if (!function_exists('json_encode')) {
         $error = $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_JSON);
         $this->output(array('error' => '{"error":["' . implode('","', $error) . '"]}', 'raw' => true));
     }
     if (!$this->elFinder->loaded()) {
         $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors));
     }
     // telepat_mode: on
     if (!$cmd && $isPost) {
         $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UPLOAD, elFinder::ERROR_UPLOAD_TOTAL_SIZE), 'header' => 'Content-Type: text/html'));
     }
     // telepat_mode: off
     if (!$this->elFinder->commandExists($cmd)) {
         $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)));
     }
     // collect required arguments to exec command
     foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) {
         $arg = $name == 'FILES' ? $_FILES : (isset($src[$name]) ? $src[$name] : '');
         if (!is_array($arg)) {
             $arg = trim($arg);
         }
         if ($req && (!isset($arg) || $arg === '')) {
             $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)));
         }
         $args[$name] = $arg;
     }
     $args['debug'] = isset($src['debug']) ? !!$src['debug'] : false;
     $this->output($this->elFinder->exec($cmd, $this->input_filter($args)));
 }
コード例 #4
0
ファイル: Kohana.php プロジェクト: openbuildings/spiderling
 public function execute($method, $url, array $post = array())
 {
     $redirects_count = 1;
     \Request::$initial = NULL;
     $this->_request = \Request::factory($url)->method($method)->post($post)->body(http_build_query($post));
     if ($this->_previous_url) {
         $this->_request->referrer($this->_previous_url);
     }
     $this->_previous_url = $this->current_url() . \URL::query($this->_request->query(), FALSE);
     \Request::$initial = $this->_request;
     $this->_response = $this->_request->execute();
     while ($this->_response->status() >= 300 and $this->_response->status() < 400) {
         $redirects_count++;
         if ($redirects_count >= $this->max_redirects()) {
             throw new Exception_Toomanyredirects('Maximum Number of redirects (5) for url :url', array(':url' => $url));
         }
         $url_parts = parse_url($this->_response->headers('location'));
         $query = isset($url_parts['query']) ? $url_parts['query'] : '';
         parse_str($query, $query);
         $_GET = $query;
         $url = $url_parts['path'];
         \Request::$initial = NULL;
         $this->_request = \Request::factory($url);
         \Request::$initial = $this->_request;
         $this->_response = $this->_request->execute();
     }
     return $this->_response->body();
 }
コード例 #5
0
ファイル: category.php プロジェクト: reznikds/Reznik
 public function action_index()
 {
     $data = array();
     $category = new Model_Category('tree');
     $category->checkTree(TRUE);
     $data['categories'] = $category->getTree();
     if ($this->isPressed('btnSubmitAdd')) {
         $categoryName = Arr::get($_POST, 'categoryName', '');
         $parentId = Arr::get($_POST, 'parentId', 0);
         $res = $category->catInsert($parentId, array('name' => $categoryName));
         if ($res) {
             Request::initial()->redirect('admin/category');
         }
         $data['errors'] = $category->getErrors();
     }
     if ($this->isPressed('btnSubmitChange')) {
         $categoryName = Arr::get($_POST, 'categoryName', '');
         $parentId = Arr::get($_POST, 'parentId', 0);
         if ($category->changeName($parentId, $categoryName)) {
             Request::initial()->redirect('admin/category');
         }
         $data['errors'] = $category->getErrors();
     }
     if ($this->isPressed('btnSubmitDel')) {
         $catDeleteId = Arr::get($_POST, 'catDeleteId', 0);
         $category->catDelete($catDeleteId);
         Request::initial()->redirect('admin/category');
     }
     $this->tpl->content = View::factory('admin/categoryeditview', $data);
 }
 /**
  * init: check if user is logged in
  * 
  * if not: redirect to login
  */
 public function init()
 {
     // call parent before first
     parent::init();
     // only check if the controller is not auth
     if (Request::initial()->controller() != 'Auth') {
         // url to loginpage
         $url = URL::to('Auth@login');
         // init identity
         $identity = Identity::instance();
         //revert identity to original user (maybe assume was called somewhere else)
         $identity->revert();
         // check authentication
         if (!$identity->authenticated()) {
             // if user is not allready authenticated, redirect to login page
             $this->redirect($url);
         } else {
             $website = Website::instance();
             // else: initialise acl
             Acl::init($identity, new Model_Rights($website->websites()));
             // set current environment
             Acl::environment($website->id());
             // if user is not entitled to access backend
             if (!Acl::instance()->allowed('Backend', 'access')) {
                 $this->redirect($url);
             }
             // if user is not entitled to access controller
             if (!Acl::instance()->allowed(Request::initial()->controller(), 'access')) {
                 $this->redirect($url);
             }
         }
     }
 }
コード例 #7
0
ファイル: Orders.php プロジェクト: s4urp8n/kohana-admin
 public static function getCommonColumns()
 {
     $request = Request::initial();
     $id = $request->param('primary');
     $cart = ORM::factory('Orders', $id);
     return ['user_id' => ['dont_select' => true, 'label' => 'Пользователь', 'type' => 'caption', 'get_current_value' => function () use($cart) {
         $user = ORM::factory('User', $cart->user_id);
         if (!empty($user->id)) {
             return $user->username . ' <a href="/admin/dataEdit/Users/' . $user->id . '/?ref=' . urlencode(AdminHREF::getFullCurrentHREF()) . '">Просмотр пользователя</a>';
         }
         return 'Пользователь неопознан, его ID=' . $user->id;
     }], 'date' => ['label' => 'Дата', 'type' => 'date'], 'time' => ['label' => 'Время', 'type' => 'time'], 'cart' => ['label' => 'Корзина', 'type' => 'caption', 'dont_select' => true, 'get_current_value' => function () use($cart) {
         $cart = unserialize($cart->cart);
         $render = '';
         $sum = 0;
         if (is_array($cart) && !empty($cart)) {
             foreach ($cart as $good) {
                 $sum += $good['price'] * $good['count'];
                 $render .= "<div style='display:inline-block;padding: 5px;'><div><img class='previewAdminImage' src=\"/" . $good['image'] . "\"/> x " . $good['count'] . '</div>';
                 $render .= "<div> Артикул: " . ORM::factory('Articles', $good['article_id'])->article . "</div>";
                 $render .= "<div> Багет: " . $good['bag'] . "</div>";
                 $render .= "<div> Размер: " . $good['width'] . 'x' . $good['height'] . "</div></div>";
             }
             $render .= "<div> Сумма: " . $sum . " руб.</div>";
         }
         return $render;
     }], 'completed' => ['label' => 'Выполнен', 'type' => 'bool']];
 }
コード例 #8
0
ファイル: Articles.php プロジェクト: shurick31/ajax
 public function action_delete()
 {
     $error = true;
     $modelArticles = new Model_articles();
     $id = (int) $this->request->param('id');
     if ($id) {
         $error = !$modelArticles->delete($id);
         //Удаляем статью
     }
     if (Request::initial()->is_ajax()) {
         // выполняем только если запрос был через Ajax
         if ($error) {
             $result = array('error' => true, 'message' => 'Ошибка при удалении');
             // по умолчанию возвращаем код с ошибкой
         } else {
             $result['error'] = false;
             // возвращаем код успеха!
         }
         header('Content-Type: text/json; charset=utf-8');
         // Устанавоиваем правильный заголовок
         echo json_encode($result);
         // на выходе отдаем код в формате JSON
         exit;
     } else {
         $this->redirect('/articles');
         // если запрос был не Аяксом, то редиректим на страницу списка статей
     }
 }
コード例 #9
0
ファイル: Paginate.php プロジェクト: HappyKennyD/teest
 public function paginate($page = null, $link = null, $count = null)
 {
     if ($page == null) {
         $page = Arr::get($_GET, 'page', 1);
     }
     if (!empty($_GET['item_count'])) {
         $this->count = (int) Arr::get($_GET, 'item_count');
         $count = $this->count;
     } else {
         if ($count == null) {
             $count = $this->count;
         } else {
             $this->count = (int) $count;
         }
     }
     if ($link == null) {
         $link = Request::initial()->uri();
     }
     $count = (int) $count;
     $page = (int) $page;
     $start = $page * $count - $count;
     $max_page = $this->page_count();
     if ($page < 1) {
         $page = 1;
     } else {
         $page = min($page, $max_page);
     }
     $prev = $page == 1 ? false : true;
     $next = $page == $max_page ? false : true;
     $this->orm->limit($count)->offset($start);
     $this->view_vars = array('page' => $page, 'max_page' => $max_page, 'key' => $this->config->get('key', 'page'), 'count' => $count, 'link' => Security::xss_clean(HTML::chars($link)), 'next' => $next, 'prev' => $prev);
     return Security::xss_clean(HTML::chars($this));
 }
コード例 #10
0
ファイル: Messages.php プロジェクト: qlsove/chat
 public function action_set_delete()
 {
     Request::initial()->is_ajax() || die;
     $id = $this->request->post('id');
     $status = $this->request->post('status');
     ORM::factory('Message')->setDelOnce($id, $status);
 }
コード例 #11
0
ファイル: Admin.php プロジェクト: qlsove/faq
 public function action_add_article()
 {
     if (Request::initial()->is_ajax()) {
         ORM::factory('Article')->add_article($this->request->post("name"), $this->request->post("seo"), $this->request->post("body"), 1);
         //замість 1 буде вставлятися id домену з кук
         die($data["status"] = "ok");
     }
 }
コード例 #12
0
ファイル: Menu.php プロジェクト: ariol/adminshop
 public function action_top()
 {
     if (Request::initial() === Request::current()) {
         $this->forward_404();
     }
     $menu = ORM::factory('Menu')->get_parent_active_menus();
     $this->template->menu = $menu;
 }
コード例 #13
0
ファイル: RequestTest.php プロジェクト: cyclonephp/http
 /**
  * @dataProvider clientIpKeyProvider
  */
 public function testClientIp($key)
 {
     $ip = '1.2.3.4';
     $_SERVER[$key] = $ip;
     $actual = Request::initial();
     $this->assertEquals($ip, $actual->clientIp());
     unset($_SERVER[$key]);
 }
コード例 #14
0
 /**
  * Constructor
  *
  * @param Request  $request
  * @param Response $response
  */
 public function __construct(Request $request, Response $response)
 {
     // Ajax-like request setting if HMVC call or POST request with param `is_ajax` == `true`
     if ($request->is_ajax() or $request !== Request::initial() or $request->method() === HTTP_Request::POST and $request->post('is_ajax') === 'true') {
         $request->requested_with('xmlhttprequest');
     }
     parent::__construct($request, $response);
 }
コード例 #15
0
ファイル: UserProfile.php プロジェクト: s4urp8n/kohana-admin
 public function getAllowedRoles()
 {
     $primary = Request::initial()->param('primary');
     if ($primary == Auth::instance()->get_user() || is_null($primary)) {
         return ['admin', 'user'];
     }
     return ['admin'];
 }
コード例 #16
0
ファイル: cookie.php プロジェクト: nike-17/codeception-kohana
 public static function set($name, $value, $expiration = NULL)
 {
     if (Kohana::$environment == Kohana::TESTING) {
         Request::initial()->cookie($name, $value);
     } else {
         return parent::set($name, $value, $expiration);
     }
 }
コード例 #17
0
ファイル: Menuadmin.php プロジェクト: ruslankus/ligneus
 public function action_index()
 {
     $select = Request::initial()->controller();
     $select = strtolower($select);
     $menu = array('Страницы' => array('main'), 'Продукты' => array('products'), 'Настройки' => array('settings'));
     $this->template->menu = $menu;
     $this->template->select = $select;
 }
コード例 #18
0
ファイル: widget.php プロジェクト: ZerGabriel/cms-1
 public function filter()
 {
     $request = Request::initial();
     $types = (array) $request->query('widget_type');
     if (!empty($types)) {
         $this->where('type', 'in', $types);
     }
     return $this;
 }
コード例 #19
0
ファイル: json.php プロジェクト: nguyennv/kohana-common
 public function render($data = NULL)
 {
     $request = Request::initial();
     $request->response()->headers('Content-Type', 'application/json');
     if ($data !== NULL) {
         $this->_json_data = $data;
     }
     return HTML::json_encode($this->_json_data);
 }
コード例 #20
0
ファイル: jsonp.php プロジェクト: nguyennv/kohana-common
 public function render($data = NULL)
 {
     $request = Request::initial();
     $request->response()->headers('Content-Type', 'application/javascript');
     if ($data !== NULL) {
         $this->_json_data = $data;
     }
     return $this->_callback . '(' . HTML::encode_js($this->_json_data) . ');';
 }
コード例 #21
0
ファイル: Fileman.php プロジェクト: s4urp8n/kohana-admin
 public static function getCurrentDir()
 {
     $request = Request::initial();
     $path = $request->query('path');
     $path = \Str\Str::load($path)->remove('\\.{2}');
     if (!empty($path)) {
         return $path;
     }
     return '';
 }
コード例 #22
0
 public function before()
 {
     $session = Session::instance();
     $session->set('auth_redirect', $_SERVER['REQUEST_URI']);
     $auth = Auth::instance();
     if ($auth->logged_in() == 0) {
         Request::initial()->redirect('auth');
     }
     return parent::before();
 }
コード例 #23
0
ファイル: 404.php プロジェクト: HappyKennyD/teest
 protected function detect_language()
 {
     $this->language = mb_strtolower((string) Request::initial()->param('language', false));
     if (!$this->language) {
         $this->language = 'ru';
     }
     I18n::lang($this->language);
     URL::$language = $this->language;
     return $this->language;
 }
コード例 #24
0
ファイル: Abstract.php プロジェクト: ariol/adminshop
 public function before()
 {
     if (Request::initial()->protocol() != 'CLI') {
         throw new HTTP_Exception_403();
     }
     while (ob_get_level()) {
         ob_end_flush();
     }
     Kohana::$profiling = FALSE;
 }
コード例 #25
0
ファイル: UsersRoles.php プロジェクト: s4urp8n/kohana-admin
 public static function getCommonColumns()
 {
     $options = DB::select('id', 'name')->from('roles')->order_by('name')->execute()->as_array('id', 'name');
     return ['username' => ['label' => 'Пользователь', 'type' => 'caption'], 'roles[]' => ['dont_select' => true, 'label' => 'Роли', 'type' => 'multiselect', 'options' => $options, 'get_current_value' => function () {
         $request = Request::initial();
         $user_id = $request->param('primary');
         $current_roles = DB::select('role_id')->from('roles_users')->where('user_id', '=', $user_id)->execute()->as_array('role_id', 'role_id');
         return $current_roles;
     }]];
 }
コード例 #26
0
ファイル: auth.php プロジェクト: raku/MorCMS
 public function action_create($login = null, $password = null)
 {
     $user = Model::factory('user');
     $user->username = '******';
     $user->password = '******';
     $user->email = '*****@*****.**';
     $user->save();
     $login_role = new Model_Role(array('name' => 'login'));
     $user->add('roles', $login_role);
     Request::initial()->redirect($this->signout_to);
 }
コード例 #27
0
ファイル: Kitsune.php プロジェクト: ziopod/kitsune
 /**
  * Assign the [Kostache_Layout] render as the request response
  **/
 public function after()
 {
     parent::after();
     if ($this->auto_render) {
         if (isset($this->view)) {
             $this->response->body($this->layout->render($this->view));
         } else {
             $this->response->body('View Model <code>View_' . ucfirst(Request::initial()->controller()) . '_' . ucfirst(Request::initial()->action()) . '</code> not found!');
         }
     }
 }
コード例 #28
0
ファイル: Core.php プロジェクト: HappyKennyD/teest
 public function before()
 {
     //$this->redirect('http://ehistory.kz/manage');
     parent::before();
     $this->response->headers('cache-control', 'private');
     // creating and attaching page metadata
     $this->metadata = new Model_Metadata();
     $this->metadata->title(__(Application::instance()->get('title')), false);
     $this->set('_metadata', $this->metadata);
     Auth::instance()->auto_login();
     if (!Auth::instance()->logged_in()) {
         $this->redirect('manage/auth/login');
     } else {
         $id = Auth::instance()->get_user()->id;
         $user = ORM::factory('user', $id);
         $input = $user->has('roles', ORM::factory('role', array('name' => 'admin'))) || $user->has('roles', ORM::factory('Role', array('name' => 'moderator')));
         $input_redactor = $user->has('roles', ORM::factory('Role', array('name' => 'redactor')));
         if (!$input && !$input_redactor) {
             $this->redirect('/manage/auth/logout');
         }
         if (!$input && (strtolower($this->request->controller()) != 'ehistory' && strtolower($this->request->controller()) != 'language')) {
             $this->redirect('manage/ehistory');
         }
     }
     $this->user = Auth::instance()->get_user();
     if (Request::$initial === Request::$current) {
         $messages = Notify::instance()->get_all_once();
         $this->set('_notifications', $messages);
     }
     $language = Session::instance()->get('_language', 'ru');
     $this->language = in_array($language, array('ru', 'en', 'kz')) ? $language : 'ru';
     I18n::lang($this->language);
     $rr = Request::initial()->uri() . urlencode(URL::query(null, true));
     $rr = trim($rr, '/');
     //$this->metadata->title('Sharua.kz', false);
     $countcomm = ORM::factory('Comment')->where('status', '=', '0')->count_all();
     //смотрим сколько новых коментов
     $this->set('_user', $this->user)->set('_language', $this->language)->set('_return_url', $rr)->set('_countcomm', $countcomm);
     //вносим в переменную количество новых коментов
     $knigi = ORM::factory('Book')->where('category_id', '=', '0')->find_all();
     //смотрим сколько книг без категории
     if ($knigi) {
         if (count($knigi) > 0) {
             $this->set('_uncatcount', count($knigi));
             //вносим в переменную количество книг без категории
         }
     }
     $this->referrer = Request::initial()->referrer();
     if (Message::get()) {
         $this->set('basic_message', Message::display('/message/basic'));
     }
 }
コード例 #29
0
ファイル: Ajax.php プロジェクト: qlsove/faq
 public function action_get_article()
 {
     if (Request::initial()->is_ajax()) {
         $path = explode('/', htmlentities(trim($_POST['url'])));
         $url = end($path);
         $domain = htmlentities(trim($_POST['domain']));
         if (substr($url, -5) == '.html') {
             $url = substr($url, 0, -5);
             $active_article = ORM::factory('Article')->get_article_by_seo($url, $domain)->body;
             echo $active_article;
         }
     }
 }
コード例 #30
0
ファイル: Paginatemain.php プロジェクト: HappyKennyD/teest
 public function paginate($page = null, $link = null, $count = null, $mosaic = null)
 {
     if ($page == null) {
         if (!isset($_GET['page'])) {
             $page = (int) Request::initial()->param('page', 1);
         } else {
             $page = (int) Arr::get($_GET, 'page', 1);
         }
     }
     if (!empty($_GET['item_count'])) {
         $this->count = (int) Arr::get($_GET, 'item_count');
         $count = $this->count;
     } else {
         if ($count == null) {
             $count = $this->count;
         } else {
             $this->count = (int) $count;
         }
     }
     if ($link == null) {
         $link = Request::initial()->uri();
         $link = explode('/', $link);
         foreach ($link as $l) {
             if (mb_strpos($l, 'page-') === false) {
                 $link_new[] = $l;
             }
         }
         $link = implode('/', $link_new);
     }
     $count = (int) $count;
     $page = (int) $page;
     $start = $page * $count - $count;
     $max_page = $this->page_count();
     if ($page != 1 && $page > $max_page) {
         throw new HTTP_Exception_404();
     }
     if ($page < 1) {
         throw new HTTP_Exception_404();
     } else {
         $page = min($page, $max_page);
     }
     $prev = $page == 1 ? false : true;
     $next = $page == $max_page ? false : true;
     if (get_class($this->orm) == "Massiv") {
         $this->orm->limit_offset($count, $start);
     } else {
         $this->orm->limit($count)->offset($start);
     }
     $this->view_vars = array('page' => $page, 'max_page' => $max_page, 'key' => $this->config->get('key', 'page'), 'count' => $count, 'link' => HTML::chars($link), 'next' => $next, 'prev' => $prev, 'mosaic' => $mosaic);
     return $this;
 }