/** * 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; }
public function __construct() { $self = $this; FormUI::register('add_user', function (FormUI $form, $name) use($self) { $form->set_settings(array('use_session_errors' => true)); $form->append(FormControlText::create('username')->set_properties(array('class' => 'columns three', 'placeholder' => _t('Username')))->add_validator('validate_username')->add_validator('validate_required')); $form->append(FormControlText::create('email')->set_properties(array('class' => 'columns four', 'placeholder' => _t('E-Mail')))->add_validator('validate_email')->add_validator('validate_required')); $password = FormControlPassword::create('password')->set_properties(array('class' => 'columns three', 'placeholder' => _t('Password')))->add_validator('validate_required'); $form->append($password); $form->append(FormControlPassword::create('password_again')->set_properties(array('class' => 'columns three', 'placeholder' => _t('Password Again')))->add_validator('validate_same', $password)); $form->append(FormControlSubmit::create('newuser')->set_caption('Add User')); $form->add_validator(array($self, 'validate_add_user')); $form->on_success(array($self, 'do_add_user')); }); FormUI::register('delete_users', function (FormUI $form, $name) use($self) { $form->set_settings(array('use_session_errors' => true)); $form->append(FormControlAggregate::create('deletion_queue')->set_selector('.select_user')->label('Select All')); $author_list = Users::get_all(); $authors[0] = _t('nobody'); foreach ($author_list as $author) { $authors[$author->id] = $author->displayname; } $form->append(FormControlSelect::create('reassign')->set_options($authors)); $form->append(FormControlSubmit::create('delete_selected')->set_caption(_t('Delete Selected'))); $form->add_validator(array($self, 'validate_delete_users')); $form->on_success(array($self, 'do_delete_users')); }); FormUI::register('edit_user', function (FormUI $form, $name, $form_type, $data) use($self) { $form->set_settings(array('use_session_errors' => true)); $edit_user = $data['edit_user']; $field_sections = array('user_info' => _t('User Information'), 'change_password' => _t('Change Password'), 'regional_settings' => _t('Regional Settings'), 'dashboard' => _t('Dashboard')); // Create a tracker for who we are dealing with $form->append(FormControlData::create('edit_user')->set_value($edit_user->id)); // Generate sections foreach ($field_sections as $key => $name) { $fieldset = $form->append('wrapper', $key, $name); $fieldset->add_class('container main settings'); $fieldset->append(FormControlStatic::create($key)->set_static('<h2 class="lead">' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>')); } // User Info $displayname = FormControlText::create('displayname')->set_value($edit_user->displayname); $form->user_info->append(FormControlLabel::wrap(_t('Display Name'), $displayname)); $username = FormControlText::create('username')->add_validator('validate_username', $edit_user->username)->set_value($edit_user->username); $form->user_info->append(FormControlLabel::wrap(_t('User Name'), $username)); $email = FormControlText::create('email')->add_validator('validate_email')->set_value($edit_user->email); $form->user_info->append(FormControlLabel::wrap(_t('Email'), $email)); $imageurl = FormControlText::create('imageurl')->set_value($edit_user->info->imageurl); $form->user_info->append(FormControlLabel::wrap(_t('Portrait URL'), $imageurl)); // Change Password $password1 = FormControlPassword::create('password1', null, array('autocomplete' => 'off'))->set_value(''); $form->change_password->append(FormControlLabel::wrap(_t('New Password'), $password1)); $password2 = FormControlPassword::create('password2', null, array('autocomplete' => 'off'))->set_value(''); $form->change_password->append(FormControlLabel::wrap(_t('New Password Again'), $password2)); $delete = $self->handler_vars->filter_keys('delete'); // don't validate password match if action is delete if (!isset($delete['delete'])) { $password2->add_validator('validate_same', $password1, _t('Passwords must match.')); } // Regional settings $timezones = \DateTimeZone::listIdentifiers(); $timezones = array_merge(array_combine(array_values($timezones), array_values($timezones))); $locale_tz = FormControlSelect::create('locale_tz', null, array('multiple' => false))->set_options($timezones)->set_value($edit_user->info->locale_tz); $form->regional_settings->append(FormControlLabel::wrap(_t('Timezone'), $locale_tz)); $locale_date_format = FormControlText::create('locale_date_format')->set_value($edit_user->info->locale_date_format); $form->regional_settings->append(FormControlLabel::wrap(_t('Date Format'), $locale_date_format)); $edit_user_info = $edit_user->info; if (isset($edit_user_info->locale_date_format) && $edit_user_info->locale_date_format != '') { $current = DateTime::create()->get($edit_user_info->locale_date_format); } else { $current = DateTime::create()->date; } $locale_date_format->set_helptext(_t('See <a href="%s">php.net/date</a> for details. Current format: %s', array('http://php.net/date', $current))); $locale_time_format = FormControlText::create('locale_time_format')->set_value($edit_user_info->locale_time_format); $form->regional_settings->append(FormControlLabel::wrap(_t('Time Format'), $locale_time_format)); if (isset($edit_user_info->locale_time_format) && $edit_user_info->locale_time_format != '') { $current = DateTime::create()->get($edit_user_info->locale_time_format); } else { $current = DateTime::create()->time; } $locale_time_format->set_helptext(_t('See <a href="%s">php.net/date</a> for details. Current format: %s', array('http://php.net/date', $current))); $locales = array_merge(array('' => _t('System default') . ' (' . Options::get('locale', 'en-us') . ')'), array_combine(Locale::list_all(), Locale::list_all())); $locale_lang = FormcontrolSelect::create('locale_lang', null, array('multiple' => false))->set_options($locales)->set_value($edit_user_info->locale_lang); $form->regional_settings->append(FormControlLabel::wrap(_t(' Language'), $locale_lang)); $spam_count = FormControlCheckbox::create('dashboard_hide_spam_count')->set_helptext(_t('Hide the number of SPAM comments on your dashboard.'))->set_value($edit_user_info->dashboard_hide_spam_count); $form->dashboard->append(FormControlLabel::wrap(_t('Hide Spam Count'), $spam_count)); // Groups if (User::identify()->can('manage_groups')) { $fieldset = $form->append(FormControlWrapper::create('groups')); $fieldset->add_class('container main settings'); $fieldset->append(FormControlStatic::create('groups_title')->set_static('<h2 class="lead">' . htmlentities(_t('Groups'), ENT_COMPAT, 'UTF-8') . '</h2>')); $fieldset->append(FormControlCheckboxes::create('user_group_membership')->set_options(Utils::array_map_field(UserGroups::get_all(), 'name', 'id'))->set_value($edit_user->groups)); } // Controls $controls = $form->append(FormControlWrapper::create('page_controls')->add_class('container controls transparent')); $apply = $controls->append(FormControlSubmit::create('apply')->set_caption(_t('Apply'))); // Get author list $author_list = Users::get_all(); $authors[0] = _t('nobody'); foreach ($author_list as $author) { $authors[$author->id] = $author->displayname; } unset($authors[$edit_user->id]); // We can't reassign this user's posts to themselves if we're deleting them $reassign = FormControlSelect::create('reassign')->set_options($authors); $reassign_label = FormControlLabel::wrap(_t('Reassign posts to:'), $reassign)->set_settings(array('wrap' => '<span class="reassigntext">%s</span>')); $controls->append($reassign_label); $controls->append(FormControlStatic::create('conjunction')->set_static(_t('and'))->set_settings(array('wrap' => '<span class="conjunction">%s</span>'))); $delete = $controls->append(FormControlSubmit::create('delete')->set_caption(_t('Delete'))->set_settings(array('wrap' => '<span>%s</span>'))->add_class('button')); $delete->on_success(array($self, 'edit_user_delete')); $delete->add_validator(array($self, 'validate_delete_user')); $apply->on_success(array($self, 'edit_user_apply')); $apply->add_validator(array($self, 'validate_edit_user')); }); parent::__construct(); }