Beispiel #1
0
 function work(Request $request)
 {
     // Объект по URI запроса
     $obj = Data::read('/contents' . $request['REQUEST']['path']);
     $request->mix(['REQUEST' => ['object' => $obj]]);
     return parent::work($request);
 }
Beispiel #2
0
 function work(Request $request)
 {
     $user = Auth::get_user();
     if ($user->is_exists()) {
         if (!$user->confirm->is_draft()) {
             //новый и еще неактивный
             $this->_result = 5;
         } else {
             //Есть такой активный пользователь
             $this->_result = 4;
         }
         //пользователя еще нет
     } else {
         if ($request['REQUEST']['form']) {
             //Присвоим email новому пользователю и проверим уникальность
             $user->email->value($request['REQUEST']['email']);
             if ($request['REQUEST']['call'] == 'check') {
                 if (!$user->check()) {
                     if ($user->errors()->email->value->duplicate) {
                         $this->_result = 2;
                     } else {
                         //Другая ошибка
                         $this->_result = 3;
                     }
                 } else {
                     //все корректно
                     $this->_result = 1;
                 }
                 $session['result'] = $this->_result;
                 Session::set('form', array($this->uri() . $this->getToken() => $session));
                 setcookie('token', $this->getToken(), 0, '/');
                 return $session;
             } else {
                 if (isset($request['COOKIE']['token']) && Session::is_exist('form')) {
                     $form = Session::get('form');
                     if (isset($form[$this->uri() . $request['COOKIE']['token']])) {
                         $form = $form[$this->uri() . $request['COOKIE']['token']];
                         Session::remove('form');
                     }
                     if (isset($form['result'])) {
                         $this->_result = $form['result'];
                     }
                 }
                 if ($this->_result == 1 && isset($user)) {
                     $user->password->value($request['REQUEST']['password']);
                     $user->title->value($request['REQUEST']['email']);
                     $user->confirm->proto("/vendor/boolive/basic/string");
                     $user->confirm->value(uniqid('', true));
                     Data::write($user);
                     //Теперь у нас есть такой пользователь
                     $this->_result = 5;
                     $this->mailSender->sendMail($to = $user->email->value(), $subject = 'Подтвержление регистрации на ' . $this->mailSender->domain->value(), $message = 'Здравствйте, вы зарегистрировались на ' . $this->mailSender->domain->value() . ' , для подтверждения актуальности электронного адреса, перейдите, пожалуйста по <a href="' . $this->mailSender->domain->value() . '/profile?confirm=' . $user->confirm->value() . '">ссылке</a>');
                     $request->redirect('profile?confirm=0');
                 }
             }
         }
     }
     return parent::work($request);
 }
Beispiel #3
0
 function work(Request $request)
 {
     $user = Auth::get_user();
     if ($user->uri() != '/system/users/admin') {
         $request->redirect('sign-in');
     }
     $request->mix(['REQUEST' => ['object' => mb_substr($request['REQUEST']['path'], mb_strlen($this->path))]]);
     return parent::work($request);
 }
Beispiel #4
0
 function work(Request $request)
 {
     if ($request['REQUEST']['form']) {
         if ($request['REQUEST']['agree']) {
             $request->redirect('ask');
         }
     } else {
         return parent::work($request);
     }
 }
Beispiel #5
0
 /**
  * Преобразование ветки объектов в структуру из массивов для вывода в шаблоне
  * @param array $items Масив объектов - пунктов меню
  * @param Entity $active Активный пункт меню
  * @param bool $sub_active Признак, есть или нет активные подчиненные?
  * @return array
  */
 protected function itemsToArray($items, $active, &$sub_active = false)
 {
     $list = array();
     $have_active = false;
     foreach ($items as $item) {
         $children = $item['sub'];
         $item = $item['object'];
         $real = $item->linked();
         $info = array('title' => $item->title->value(), 'icon' => false, 'url' => Request::url($real->uri()), 'active' => $active && $active->eq($real) ? 1 : 0);
         // Иконка
         //            $icon = $item->icon->isExist() ? $item->icon : ($real->icon->isExist()? $real->icon : null);
         //            if ($icon && !$icon->isDraft() && !$icon->isHidden()){
         //                $info['icon'] = $icon->resize(0,30,Image::FIT_OUTSIDE_LEFT_TOP)->file();
         //            }
         // Если заголовок не определен
         if (empty($info['title'])) {
             $info['title'] = $real->title->value();
             if (empty($info['title'])) {
                 $info['title'] = $real->name();
             }
         }
         if ($children) {
             $info['children'] = $this->itemsToArray($children, $active, $sub_active);
             if (!$info['active'] && $sub_active) {
                 $info['active'] = 2;
             }
         }
         $have_active = $have_active || $info['active'];
         $list[] = $info;
     }
     $sub_active = $have_active;
     return $list;
 }
Beispiel #6
0
 function process(Request $request)
 {
     if (parent::process($request)) {
         $request->redirect(Request::url('/admin' . $request['REQUEST']['object']->uri()));
     } else {
         $request->redirect(Request::url(null, [], true));
     }
 }
Beispiel #7
0
 function show($v, Request $request)
 {
     $obj = $request['REQUEST']['object'];
     $v['uri'] = Request::url($obj->uri());
     $v['count'] = $request['REQUEST']['page_count'];
     $v['current'] = min($v['count'], $request['REQUEST']['page']);
     $v['show'] = $this->show_cnt->value();
     return parent::show($v, $request);
 }
Beispiel #8
0
 function work(Request $request)
 {
     if ($request['REQUEST']['form']) {
         $session = array();
         try {
             self::$config = Config::read('auth');
             $result = Data::find(array('from' => self::$config['users-list'], 'select' => 'children', 'depth' => 'max', 'where' => array(['child', 'email', array('value', '=', $request['REQUEST']['email'])], ['child', 'password', array('value', '=', $request['REQUEST']['password'])]), 'key' => false, 'limit' => array(0, 1), 'comment' => 'sign-in user by email and password'), false);
             if (!empty($result)) {
                 $user = $result[0];
                 Auth::set_user($user);
                 if ($request['REQUEST']['remember-me']) {
                     Auth::set_user($user, 1234565);
                 }
                 $request->redirect(self::$config['redirect']);
             } else {
                 $this->_result = 0;
             }
         } catch (\Exception $error) {
             $this->_result = 0;
         }
         $session['result'] = $this->_result;
         Session::set('form', array($this->uri() . $this->getToken() => $session));
         setcookie('token', $this->getToken(), 0, '/');
         return $session;
     } else {
         // Отображение формы
         $v = array();
         if (isset($request['COOKIE']['token']) && Session::is_exist('form')) {
             $form = Session::get('form');
             if (isset($form[$this->uri() . $request['COOKIE']['token']])) {
                 $form = $form[$this->uri() . $request['COOKIE']['token']];
                 Session::remove('form');
             }
             if (isset($form['result'])) {
                 $this->_result = $form['result'];
             }
         }
         $this->res->start($request);
         return $this->show($v, $request);
     }
 }
Beispiel #9
0
 function show($v, Request $request)
 {
     $page = $request['REQUEST']['object'];
     $v['title'] = $page->title->value();
     $v['text'] = $page->text->value();
     //
     if (($split_pos = mb_strpos($v['text'], '<a class="more"> </a>')) || ($split_pos = mb_strpos($v['text'], '<!--more-->'))) {
         $v['text'] = mb_substr($v['text'], 0, $split_pos);
     }
     //
     $v['url'] = Request::url($page->uri());
     return parent::show($v, $request);
 }
Beispiel #10
0
 function work(Request $request)
 {
     $name = $this->name();
     $version = $this->version->value();
     if (!is_dir(DIR . 'vendor_front/' . $name)) {
         CLI::run_php('bowerphp.phar install --save ' . $name . '#' . $version, false, true);
     }
     $files = explode(';', $this->import->value());
     if ($file = $this->file()) {
         $files[] = $file;
     }
     foreach ($files as $file) {
         $file = '/vendor_front/' . trim($file);
         switch (File::fileExtention($file)) {
             case 'js':
                 $request->htmlHead('script', ['type' => 'text/javascript', 'src' => $file, 'text' => '']);
                 break;
             case 'css':
                 $request->htmlHead('link', ['rel' => "stylesheet", 'type' => "text/css", 'href' => $file]);
                 break;
             default:
         }
     }
 }
Beispiel #11
0
 function work(Request $request)
 {
     $out = $request['REQUEST']['handler']->start($request);
     if ($redirect = $request->getCommands('redirect')) {
         header("HTTP/1.1 303 See Other");
         header('Location: ' . $redirect[0][0]);
     } else {
         if ($out != false) {
             if (is_array($out)) {
                 header('Content-Type: application/json');
                 echo F::toJSON($out, false);
             } else {
                 echo $out;
             }
         } else {
             header('Location: ' . Request::url());
             //текущий адрес без аргументов
         }
     }
 }
Beispiel #12
0
 function work(Request $request)
 {
     if ($file = $this->file()) {
         $request->htmlHead('link', ['rel' => "stylesheet", 'type' => "text/css", 'href' => $file]);
     }
 }
Beispiel #13
0
 function work(Request $request)
 {
     $user = Auth::get_user();
     $request->mix(['REQUEST' => ['object' => $user]]);
     return parent::work($request);
 }
Beispiel #14
0
 function startCheck(Request $request)
 {
     return $request->setFilter($this->startRule());
 }
Beispiel #15
0
 function work(Request $request)
 {
     $this->_base_uri = $request['REQUEST']['object']->uri();
     $request->mix(['REQUEST' => ['base_uri' => $this->_base_uri]]);
     if ($request['REQUEST']['form'] !== false) {
         // Обработка формы
         $session = array();
         try {
             // Вызов полей для свойств объекта
             $request->mix(['REQUEST' => ['call' => 'check']]);
             $list = $this->getList($request);
             if (is_array($list)) {
                 $input = $request->getInput();
                 $views = $this->linked()->views->linked();
                 foreach ($list as $obj) {
                     $name = preg_replace('/' . preg_quote($this->_base_uri . '/', '/') . '/u', '', $obj->uri());
                     $obj_input = [];
                     if (isset($input['REQUEST'][$name])) {
                         $obj_input['REQUEST']['value'] = $input['REQUEST'][$name];
                     }
                     if (isset($input['FILES'][$name])) {
                         $obj_input['FILES']['value'] = $input['FILES'][$name];
                     }
                     $obj_input['REQUEST']['object'] = $obj;
                     $views->start($request->mix($obj_input));
                 }
             }
             if (!$request['REQUEST']['object']->errors()->isExist()) {
                 // Выполнение действия
                 $this->process($request);
                 $this->_result = self::FORM_RESULT_OK;
                 if (!($redirect = $this->getCommands('redirect'))) {
                     $redirect = $this->redirect->inner();
                     if (!$redirect->is_draft() && $redirect->value() != '') {
                         $request->redirect(Request::url($redirect->value()));
                     }
                 }
             } else {
                 $this->_result = self::FORM_RESULT_ERROR;
             }
         } catch (\Exception $error) {
             $this->_result = self::FORM_RESULT_ERROR;
         }
         $session['result'] = $this->_result;
         if ($this->_result == self::FORM_RESULT_ERROR) {
             $session['object'] = $request['REQUEST']['object']->toArray();
             // @todo Для ajax запросов нужна развернутая информация об ошибках для каждого поля
             $session['message'] = 'Ошибки';
         } else {
             if ($this->_result == self::FORM_RESULT_ERROR) {
                 $session['message'] = 'Успех';
             }
         }
         // @todo Для ajax запросов в сессию сохранять нет смысла
         Session::set('form', array($this->uri() . $this->getToken() => $session));
         setcookie('token', $this->getToken(), 0, '/');
         return $session;
     } else {
         // Отображение формы
         $v = array();
         if (isset($request['COOKIE']['token']) && Session::is_exist('form')) {
             $form = Session::get('form');
             if (isset($form[$this->uri() . $request['COOKIE']['token']])) {
                 $form = $form[$this->uri() . $request['COOKIE']['token']];
                 Session::remove('form');
             }
             if (isset($form['object'])) {
                 $request['REQUEST']['object'] = Entity::fromArray($form['object']);
             }
             if (isset($form['result'])) {
                 $this->_result = $form['result'];
             }
         }
         $this->res->start($request);
         return $this->show($v, $request);
     }
 }