/** * Login verification gate. * * @param Request $request Current Router request. * * @return void */ protected function checkLogged(Request $request) { if (1 === Core\Session()->get('cms_user_logged')) { $this->user = unserialize(rawurldecode(Core\Session()->get('cms_user_info'))); Core\Registry()->set('current_cms_user', $this->user); Core\Helpers\DateTime::setEnvironmentTimezone($this->user->timezone); } else { $request->redirectTo(array('controller' => 'authentication', 'action' => 'login', 'redirect' => $request->meta('REQUEST_URI'))); } }
/** * Fetches the HTML for the captcha. * * @param array $configuration Configuration data. * * @static * @uses Core\Session() * * @return \Captcha\Captcha */ public static function get(array $configuration) { $captcha = Core\Session()->get('captcha'); if (!$captcha && Core\Session()->get('authentication_error')) { $captcha = new \Captcha\Captcha(); $captcha->setPublicKey($configuration['public_key']); $captcha->setPrivateKey($configuration['private_key']); Core\Session()->set('captcha', $captcha); } return $captcha; }
/** * Generates an application url. * * @param array $options Array of options. * * @access public * @uses Core\Registry(); * @uses Core\Config(); * * @return string */ public function toUrl(array $options) { static $_cache; $_cache_key = md5(serialize($options)); $options = array_merge(array('controller' => $this->request->controller()), $options); if (!isset($_cache[$_cache_key])) { $mode = isset($options['_mode']) ? Core\Config()->modes($options['_mode']) : $this->request->mode(); if ($mode != $this->request->mode()) { $routes = new Routes($mode); unset($options['_mode']); $route = $routes->extractUrl($options); $route['pattern'] = $routes->toRoute($route['pattern']); } else { unset($options['_mode']); $route = $this->routes->extractUrl($options); $route['pattern'] = $this->routes->toRoute($route['pattern']); } foreach ($route['pattern'] as $key => $url_element) { if (isset($url_element[0]) && $url_element[0] === Core\Config()->ROUTER['variables_prefix']) { $option_key = str_replace(Core\Config()->ROUTER['variables_prefix'], '', $url_element); $options[$option_key] = isset($options[$option_key]) ? $options[$option_key] : null; $route['pattern'][$key] = $options[$option_key]; } } foreach ($options as $key => $option) { if (array_key_exists($key, $route['maps_to'])) { unset($options[$key]); } } if (Core\Config()->SESSION['transparency']) { $options[Core\Config()->SESSION['parameter']] = Core\Session()->getKey(); } $_prefix = ''; if (!Core\Config()->ROUTER['rewrite']) { $_prefix = '?'; } $mode['url'] = $mode['url'] ? $mode['url'] . Core\Config()->ROUTER['separator'] : ''; $_cache[$_cache_key] = $_prefix . $mode['url'] . rtrim(implode(Core\Config()->ROUTER['separator'], $route['pattern']), Core\Config()->ROUTER['separator']) . (!empty($options) ? '?' . http_build_query($options, false, '&') : ''); } return $_cache[$_cache_key]; }
/** * Save a message in the session array. * * @param string $message Message string. * @param string $context Context(optional). * @param array $additional Additional info string(optional). * * @access public * @static * @uses Core\Session() * * @return void */ public static function set($message, $context = 'default', array $additional = array()) { Core\Session()->set('flash_message', array('message' => $message, 'context' => $context, 'additional' => $additional)); }
/** * Password reset action. * * @param Request $request Current router request. * * @return void */ public function reset(Request $request) { if ($request->is('post')) { $this->errors = array(); $user = new Models\CMSUser(); if ($this->captcha && !Helpers\Captcha::isValid($this->captcha)) { $this->errors['captcha'] = true; } elseif (filter_var($request->post('email'), FILTER_VALIDATE_EMAIL) === false) { $this->errors['email'] = true; } elseif (!($user = Models\CMSUser::find()->where('email = ?', array($request->post('email')))->first())) { $this->errors['email'] = true; } if (!$this->errors) { $user->save(array('updated_on' => gmdate('Y-m-d H:i:s')), true); $this->name = $user->name; $this->password_reset_link = Core\Router()->toFullUrl(array('controller' => 'authentication', 'action' => 'renew', 'id' => sha1($user->password . Core\Config()->USER_AUTH['cookie_salt'] . $user->email))); $mailForPasswordReset = array('from' => array(Core\Config()->MAILER['identity']['email'] => Core\Config()->MAILER['identity']['name']), 'to' => array($user->email => $user->name), 'subject' => $this->labels['mails']['reset']['subject'], 'content' => $this->getPartialOutput('authentication/mails/password_reset')); Core\Helpers\Mailer::send($mailForPasswordReset); Helpers\FlashMessage::set($this->labels['reset']['success'], 'success'); Core\Session()->remove('authentication_error'); Core\Session()->remove('captcha'); } else { if ($this->captcha) { Helpers\FlashMessage::set($this->labels['captcha']['error'], 'danger'); } else { Helpers\FlashMessage::set($this->labels['reset']['error'], 'danger'); } Core\Session()->set('authentication_error', true); if (Core\Config()->CAPTCHA['enabled']) { $this->loadCaptcha(Core\Config()->CAPTCHA); } } } }
/** * Reloads current user info stored in the application session. * * @param Request $request Current router request. * * @return void */ protected function afterEdit(Request $request) { parent::afterEdit($request); if ($request->is('post') && !$this->resource->hasErrors()) { if ($this->resource->getPrimaryKeyValue() == $this->user->getPrimaryKeyValue()) { Core\Session()->set('cms_user_info', rawurlencode(serialize($this->resource))); $this->user = $this->resource; } } }
/** * Assigns common template engine vars. * * @param Modules\Render\Render $renderer Render module object. * * @access private * * @return Modules\Render\Render */ private static function assignVariablesToRender(Modules\Render\Render &$renderer) { $renderer->set('_mode', Core\Config()->paths('mode')); $renderer->set('_registry', Core\Registry()); $renderer->set('_config', Core\Config()); $renderer->set('_session', Core\Session()); $renderer->set('_assets', $renderer->assets()); $renderer->set('_urls', Core\Config()->urls()); $renderer->set('_paths', Core\Config()->paths()); $renderer->set('_request', Core\Router()->request); $renderer->set('_get', Core\Router()->request->get()); $renderer->set('_post', Core\Router()->request->post()); $renderer->set('_environment', SILLA_ENVIRONMENT); return $renderer; }