示例#1
0
 /**
  * Forgery constructor
  */
 public function __forge()
 {
     $user = \Magelight\Auth\Models\User::find(\Magelight\Http\Request::getInstance()->getGet('id'));
     if ($user) {
         $this->set('user', $user->asArray());
     }
 }
示例#2
0
 /**
  * Check value with rule
  * Returns:
  *    - true if rule passed.
  *    - false if value doesn`t match the rule.
  *
  * @param mixed $value
  * @return bool
  */
 public function check($value)
 {
     $reCaptcha = \Magelight\Webform\Models\Captcha\ReCaptcha::forge();
     $request = \Magelight\Http\Request::getInstance();
     $challenge = $request->getPost(\Magelight\Webform\Models\Captcha\ReCaptcha::CHALLENGE_INDEX);
     $response = $request->getPost(\Magelight\Webform\Models\Captcha\ReCaptcha::RESPONSE_INDEX);
     return $reCaptcha->recaptchaCheckAnswer($_SERVER['HTTP_HOST'], $challenge, $response)->is_valid;
 }
示例#3
0
 /**
  * Get login form
  *
  * @return \Magelight\Webform\Blocks\Form
  */
 public function getLoginForm()
 {
     $form = Form::forge()->setHorizontal()->setConfigs('remindpass-form', $this->url(\Magelight\Config::getInstance()->getConfigString('global/auth/urls/login_url')));
     $fieldset = Fieldset::forge();
     $fieldset->addRowField(Elements\Input::forge()->setName('email'), __('E-Mail'));
     $fieldset->addRowField(Elements\PasswordInput::forge()->setName('password'), __('Password'));
     return $form->addFieldset($fieldset)->createResultRow(true)->addButtonsRow([Elements\Button::forge()->setContent(__('Enter'))->addClass('btn-primary'), Elements\Abstraction\Element::forge()->setTag('a')->setAttribute('href', $this->url('auth/remindpass'))->setContent(__('Remind password'))->setClass('btn')])->loadFromRequest(\Magelight\Http\Request::getInstance())->setValidator($this->getLoginFormValidator());
 }
示例#4
0
 /**
  * Get form validator
  *
  * @return \Magelight\Webform\Models\Validator
  */
 public function getSampleFormValidator()
 {
     $validator = \Magelight\Webform\Models\Validator::forge();
     $validator->fieldRules('captcha')->validatePermanent()->captcha()->setCustomError(__('Protection code is incorrect'));
     $validator->fieldRules('password', __('Password'))->required()->chainRule()->minLength(3)->chainRule()->maxLength(32)->chainRule();
     $validator->fieldRules('passconf', __('Password confirmation'))->required()->chainRule()->equals(\Magelight\Http\Request::getInstance()->getPost('regform')['password'], __('entered password'));
     $validator->fieldRules('name')->required()->chainRule()->minLength(3)->chainRule()->maxLength(32)->chainRule()->pregMatch('/[a-z0-9а-я]*/i');
     $validator->fieldRules('email')->required()->chainRule()->email();
     $validator->setErrorsLimit(1);
     return $validator;
 }
示例#5
0
文件: Web.php 项目: rganin/magelight
 /**
  * Run app
  *
  * @throws \Exception|\Magelight\Exception
  */
 public function run()
 {
     try {
         \Magelight\Event\Manager::getInstance()->dispatchEvent('app_start', []);
         $request = \Magelight\Http\Request::getInstance();
         $action = \Magelight\Components\Router::getInstance($this)->getAction((string) $request->getRequestRoute());
         $request->appendGet($action['arguments']);
         $this->dispatchAction($action);
     } catch (\Exception $e) {
         \Magelight\Log::getInstance()->add($e->getMessage());
         if ($this->developerMode) {
             throw $e;
         }
     }
 }
示例#6
0
 /**
  * Run app
  *
  * @throws \Exception|Exception
  */
 public function run()
 {
     try {
         \Magelight\Event\Manager::getInstance()->dispatchEvent('app_start', []);
         $request = \Magelight\Http\Request::getInstance();
         $resource = $request->getGet('resource');
         $staticDir = realpath($this->getAppDir() . DS . \Magelight\Config::getInstance()->getConfigString('global/view/published_static_dir', 'pub/static'));
         foreach (array_reverse($this->getModuleDirectories()) as $modulesPath) {
             $resource = str_replace('\\/', DS, $resource);
             $filename = $modulesPath . DS . $resource;
             $targetFilename = $staticDir . DS . $resource;
             if (file_exists($filename)) {
                 if (!is_dir(dirname($targetFilename))) {
                     mkdir(dirname($targetFilename), 0777, true);
                 }
                 if (\Magelight\Config::getInstance()->getConfigBool('global/app/developer_mode', false)) {
                     $pathinfo = pathinfo($filename, PATHINFO_EXTENSION);
                     if (isset($this->mimeTypes[$pathinfo])) {
                         $mimeType = $this->mimeTypes[$pathinfo];
                         header('Content-type: ' . $mimeType);
                     }
                     echo file_get_contents($filename);
                     break;
                 }
                 copy($filename, $targetFilename);
                 header('Location: ' . \Magelight\Helpers\UrlHelper::getInstance()->getUrl($resource));
                 break;
             }
         }
     } catch (\Exception $e) {
         \Magelight\Log::getInstance()->add($e->getMessage());
         if ($this->developerMode) {
             throw $e;
         }
     }
 }
示例#7
0
文件: Form.php 项目: rganin/magelight
 /**
  * Load form from request
  *
  * @param \Magelight\Http\Request $request
  * @return Form
  */
 public function loadFromRequest(\Magelight\Http\Request $request = null)
 {
     if (empty($request)) {
         $request = \Magelight\Http\Request::getInstance();
     }
     $method = $this->getAttribute('method', 'post');
     $methodName = 'get' . ucfirst(strtolower($method));
     if (!empty($this->wrapIndex)) {
         $this->requestFields = $request->{$methodName}($this->wrapIndex, []);
         $this->requestUploads = $request->getFilesNormalized($this->wrapIndex, []);
     } else {
         $methodName .= 'Array';
         $this->requestFields = $request->{$methodName}();
         $this->requestUploads = $request->getFilesArrayNormalized();
     }
     return $this->setFormValuesFromRequestFields($this->requestFields);
 }
示例#8
0
 /**
  * Constructor
  * 
  * @param array $routeAction
  *
  */
 public function init(array $routeAction = [])
 {
     $this->request = \Magelight\Http\Request::getInstance();
     $this->routeAction = $routeAction;
     $this->app = \Magelight\App::getInstance();
     $this->response = \Magelight\Http\Response::forge();
 }
示例#9
0
文件: App.php 项目: rganin/magelight
 /**
  * Dispatch action
  *
  * @param array $action
  *
  * @return App
  * @throws \Magelight\Exception
  */
 public function dispatchAction(array $action)
 {
     $this->currentAction = $action;
     $eventManager = \Magelight\Event\Manager::getInstance();
     $request = \Magelight\Http\Request::getInstance();
     $eventManager->dispatchEvent('app_dispatch_action', ['action' => $action, 'request' => $request]);
     $controllerName = str_replace('/', '\\', $action['module'] . '\\Controllers\\' . ucfirst($action['controller']));
     $controllerMethod = $action['action'] . 'Action';
     $controller = call_user_func([$controllerName, 'forge']);
     /* @var $controller \Magelight\Controller */
     $eventManager->dispatchEvent('app_controller_init', ['controller' => $controller, 'action' => $action, 'request' => $request]);
     $controller->init($action);
     $eventManager->dispatchEvent('app_controller_initialized', ['controller' => $controller, 'action' => $action, 'request' => $request]);
     $controller->beforeExecute();
     $controller->{$controllerMethod}();
     $controller->afterExecute();
     $eventManager->dispatchEvent('app_controller_executed', ['controller' => $controller, 'action' => $action, 'request' => $request]);
     return $this;
 }