function install() { if ($this->config->is_loaded) { die("Oops, there's already a config.php file. You'll need to remove it to run this installer."); } $password_min_length = 5; $password_max_length = 72; $form = new \Leeflets\Form($this->config, $this->router, $this->settings, 'install-form', array('elements' => array('credentials' => array('type' => 'fieldset', 'elements' => array('username' => array('type' => 'email', 'placeholder' => 'Email Address', 'class' => 'input-block-level', 'required' => true), 'password1' => array('type' => 'password', 'placeholder' => 'Password', 'class' => 'input-block-level', 'required' => true, 'validation' => array(array('callback' => 'min_length', 'msg' => 'Sorry, your password must be at least ' . $password_min_length . ' characters in length.', 'args' => array($password_min_length)), array('callback' => 'max_length', 'msg' => 'Sorry, your password can be no longer than ' . $password_max_length . ' characters in length.', 'args' => array($password_max_length)))), 'password2' => array('type' => 'password', 'placeholder' => 'Confirm Password', 'class' => 'input-block-level', 'required' => true, 'validation' => array(array('callback' => array($this, 'matching_passwords'), 'msg' => 'Your passwords do not match. Please enter matching passwords.', 'args' => array($_POST['password2']))))))))); if (!$this->filesystem->have_direct_access()) { $elements['warning'] = array('type' => 'html', 'value' => $this->view->get_partial('ftp-warning')); $elements['connection'] = $this->filesystem->get_connection_fields(array($this, '_check_connection'), true); } $elements['buttons'] = array('type' => 'fieldset', 'elements' => array('submit' => array('type' => 'button', 'button-type' => 'submit', 'class' => 'btn btn-primary', 'value' => 'Install Leeflets'))); $form->add_elements($elements); if ($form->validate()) { $hasher = new \PasswordHash(8, false); $data = array('username' => $_POST['credentials']['username'], 'password' => $hasher->HashPassword($_POST['credentials']['password1'])); $this->config->write($this->filesystem, $data); $htaccess = new \Leeflets\Htaccess($this->filesystem, $this->router, $this->config); $htaccess->write(); if (isset($_POST['connection']['type'])) { $this->settings->save_connection_info($_POST, $this->filesystem); } \Leeflets\Router::redirect($this->router->admin_url('/user/login/')); exit; } $args = compact('form'); $args['page-title'] = 'Install'; $args['layout'] = 'logged-out'; return $args; }
function login() { $form = new \Leeflets\Form($this->config, $this->router, $this->settings, 'login-form', array('elements' => array('credentials' => array('type' => 'fieldset', 'elements' => array('username' => array('type' => 'email', 'placeholder' => 'Email Address', 'class' => 'input-block-level', 'required' => true, 'autofocus' => true, 'validation' => array(array('callback' => array($this, '_check_username'), 'msg' => 'Sorry, that is not the correct username.'))), 'password' => array('type' => 'password', 'placeholder' => 'Password', 'class' => 'input-block-level', 'required' => true, 'validation' => array(array('callback' => array($this, '_check_password'), 'msg' => 'Sorry, that is not the correct password.'))))), 'buttons' => array('type' => 'fieldset', 'elements' => array('submit' => array('type' => 'button', 'button-type' => 'submit', 'class' => 'btn btn-primary', 'value' => 'Login')))))); if ($form->validate()) { $this->user->set_cookie(); \Leeflets\Router::redirect($this->router->admin_url()); exit; } $args = compact('form'); $args['page-title'] = 'Login'; $args['layout'] = 'logged-out'; return $args; }
function edit() { if (isset($_POST['connection']['type'])) { if ('direct' == $_POST['connection']['type']) { $_POST['connection']['hostname'] = ''; $_POST['connection']['username'] = ''; $_POST['connection']['password'] = ''; } elseif ('' == $_POST['connection']['password']) { $_POST['connection']['password'] = $this->settings->get('connection', 'password'); } } $elements['site-meta'] = array('title' => 'Meta Information', 'description' => 'Inserted into the <head> tag of the site. Used by search engines.', 'type' => 'fieldset', 'elements' => array('author' => array('type' => 'text', 'label' => 'Site Author', 'autofocus' => true, 'class' => 'input-large'), 'title' => array('type' => 'text', 'label' => 'Site Title', 'class' => 'input-block-level'), 'description' => array('type' => 'text', 'label' => 'Site Description', 'class' => 'input-block-level', 'tip' => 'Keep it short and sweet'))); $elements['privacy'] = array('title' => 'Privacy Settings', 'type' => 'fieldset', 'elements' => array('visibility' => array('type' => 'radiolist', 'value' => '1', 'options' => array('1' => 'Allow search engines to index this site.', '2' => 'Don\'t allow search engines to index this site.')))); $elements['analytics'] = array('title' => 'Analytics Settings', 'type' => 'fieldset', 'elements' => array('code' => array('type' => 'textarea', 'label' => 'Tracking Code', 'class' => 'input-block-level', 'rows' => 5), 'placement' => array('type' => 'select', 'label' => 'Tracking Code Placement', 'options' => array('head' => 'Header', 'footer' => 'Footer')))); $elements['connection'] = $this->filesystem->get_connection_fields(array($this, '_check_connection'), false); $elements['connection']['title'] = 'Filesystem Settings'; $elements['connection']['elements']['hostname']['class'] = 'input-xlarge'; $elements['connection']['elements']['username']['class'] = 'input-xlarge'; $elements['connection']['elements']['password']['class'] = 'input-xlarge'; if ($this->config->debug) { $elements['debug'] = array('title' => 'Debug Options', 'description' => 'These settings only have an effect when in debug mode.', 'type' => 'fieldset', 'elements' => array('disable-overlays' => array('type' => 'checkbox', 'label' => 'Disable click-to-edit preview overlays'))); } // Need this button hidden with CSS so that // pressing 'Enter' in a textbox submits the form // Could use JS to detect the 'Enter' key, but apparently there's issues // with autocomplete and form fillers $elements['leeflets-hidden-submit-button'] = array('type' => 'fieldset', 'elements' => array('submit' => array('type' => 'button', 'button-type' => 'submit', 'value' => 'Save Changes', 'tabindex' => '-1'))); $form = new \Leeflets\Form($this->config, $this->router, $this->settings, 'settings-form', array('action' => $this->router->admin_url('settings/edit/'), 'elements' => $elements)); $error = ''; if ($form->validate()) { $values = $_POST; unset($values['submit']); unset($values['submission-settings-form']); if (!isset($values['debug'])) { $values['debug'] = array(); } $values = array_merge($this->settings->get_data(), $values); if (!$this->settings->write($values, $this->filesystem)) { $error = 'Error saving the settings.'; } } elseif ($form->is_submitted()) { $error = 'Please correct the errors below.'; } else { $form->set_values($this->settings->get_data()); } return compact('form', 'error'); }