protected function __construct() { $uri = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : $_SERVER['PATH_INFO']; $this->uri = self::clean_uri($uri); if ($match = moojon_routes::map($this->uri)) { $config = array_merge(moojon_config::get_data(), moojon_config::read(moojon_paths::get_project_config_environment_app_directory(ENVIRONMENT, $match->get('app')))); if (array_key_exists('secure', $config) && $config['secure'] === true && !moojon_security::authenticate()) { moojon_cache::disable(); $pattern = ':app/:controller/:action'; $match = new moojon_route_match($pattern, array_merge($match->get_params(), array('app' => $config['security_app'], 'controller' => $config['security_controller'], 'action' => $config['security_action'])), new moojon_route($pattern)); $this->uri = $config['security_app'] . '/' . $config['security_controller'] . '/' . $config['security_action']; } $this->match = $match; $this->data = $this->match->get_params(); $this->route = $this->match->get_route(); self::try_define('APP', $this->data['app']); self::try_define('CONTROLLER', $this->data['controller']); self::try_define('ACTION', $this->data['action']); } else { self::_404($this->uri); } }
public function logout() { moojon_security::destroy(); moojon_flash::set('notification', moojon_config::get('security_logout_message')); $this->redirect(moojon_config::get('index_file') . moojon_config::get('security_app') . '/' . moojon_config::get('security_controller') . '/' . moojon_config::get('security_action')); }
function login_form($authenticated = false, $message = null, $redirect = null, $attributes = array()) { if (!$authenticated) { $security_identity_label = moojon_config::get('security_identity_label'); $security_password_label = moojon_config::get('security_password_label'); $security_remember_label = moojon_config::get('security_remember_label'); $security_key = moojon_config::get('security_key'); $security_identity_key = moojon_config::get('security_identity_key'); $security_password_key = moojon_config::get('security_password_key'); $security_remember_key = moojon_config::get('security_remember_key'); if (moojon_security::login_attempt($security_key)) { $security = moojon_request::get($security_key); $security_identity_value = $security[$security_identity_key]; $security_password_value = $security[$security_password_key]; $security_remember_value = $security[$security_remember_key]; } else { $security_remember_value = null; $security_identity_value = null; $security_password_value = null; $security_checked_value = null; } $child = form_tag(null, array('action' => '#', 'method' => 'post')); if ($redirect) { $child->add_child(redirection_tag($redirect)); } if ($message) { $child->add_child(p_tag($message, array('class' => 'error'))); } $fieldset = fieldset_tag(); $fieldset->add_child(label_tag($security_identity_label, $security_identity_key)); $fieldset->add_child(text_input_tag(array('id' => $security_identity_key, 'name' => attribute_array_name($security_key, $security_identity_key), 'value' => $security_identity_value))); $fieldset->add_child(label_tag($security_password_label, $security_password_key)); $fieldset->add_child(password_input_tag(array('id' => $security_password_key, 'name' => attribute_array_name($security_key, $security_password_key), 'value' => $security_password_value))); $div = div_tag(null, array('class' => 'checkbox')); $div->add_child(hidden_input_tag(array('name' => attribute_array_name($security_key, $security_remember_key), 'value' => 0))); $remember_attributes = array('name' => attribute_array_name($security_key, $security_remember_key), 'value' => 1, 'id' => $security_remember_key); if ($security_remember_value) { $remember_attributes['checked'] = 'checked'; } $div->add_child(checkbox_input_tag($remember_attributes)); $div->add_child(label_tag($security_remember_label, $security_remember_key)); $fieldset->add_child($div); $child->add_child($fieldset); $child->add_child(submit_input_tag(array('name' => attribute_array_name($security_key, 'submit'), 'value' => 'Login'))); } else { $child = p_tag('You are logged in.'); } return div_tag($child, array('id' => 'login_div')); }