/** * Display the login form * * @param string $name Pre-fill the name field with this name */ protected function login_form() { // Build theme and login page template $this->setup_theme(); if (!$this->theme->template_exists('login')) { $this->theme = Themes::create('admin', 'RawPHPEngine', Site::get_dir('admin_theme', true)); $this->theme->assign('admin_page', 'login'); } // Build the login form $form = new FormUI('habari_login'); //$form->on_success( array( $this, 'loginform_success' ) ); $login_form_title = _t('<h1><a href="%1$s" title="%2$s"><img alt="%2$s" src="%3$s" style="height:1em;margin-right:10px;vertical-align:top;">%4$s</a></h1>', array(Site::get_url('site'), _t('Go to Site'), Site::get_url('habari', '/system/admin/images/habari.logo.png'), Options::get('title'))); $form->append(FormControlStatic::create('title')->set_static($login_form_title)); $form->append(FormControlStatic::create('reset_message')->set_static('<p id="reset_message" class="on_reset">' . _t('Please enter the username you wish to reset the password for. A unique password reset link will be emailed to that user.') . '</p>')); $form->append(FormControlLabel::wrap(_t('Name'), FormControlText::create('habari_username')->set_property('autofocus', 'autofocus'))->set_template('control.label.outsideleft')); $form->append(FormControlLabel::wrap(_t('Password'), FormControlPassword::create('habari_password', null, array('class' => 'off_reset')))->set_template('control.label.outsideleft')->set_properties(array('class' => 'off_reset'))); $form->append($drop_button = FormControlDropbutton::create('submit_button')->add_template_class('ul', 'off_reset')); $drop_button->append(FormControlSubmit::create('login')->on_success(array($this, 'loginform_do_login'))->set_caption(_t('Login'))); $form->append(FormControlStatic::create('reset_link')->set_static('<a href="#" class="off_reset reset_link">' . _t('Reset password') . '</a>')); $form->append(FormControlStatic::create('login_link')->set_static('<a href="#" class="on_reset reset_link">' . _t('Login') . '</a>')); $form->append(FormControlSubmit::create('reset_button')->set_caption(_t('Reset password'))->set_properties(array('class' => 'on_reset'))->on_success(array($this, 'loginform_do_reset'))); // Use the dropbutton's visualizer to select the primary action for form submission upon pressing enter $form->set_settings(array('prefix_html' => '<script>$(function(){$("body").on("keypress", "form[name=' . $form->input_name() . ']", function(e){if(e.which==13){$(this).find("#' . $form->submit_button->get_visualizer() . ' .primary").click();return e.preventDefault()&&false;}});})</script>')); // Let plugins alter this form Plugins::act('form_login', $form); // Assign login form and display the page $this->theme->form = $form; $this->display('login'); return true; }