From 16ed2ae68381362cbfe66d10226b9dedbfaacba5 Mon Sep 17 00:00:00 2001 From: msquare Date: Mon, 14 Nov 2016 19:10:29 +0100 Subject: [PATCH] fixed settings validation --- includes/model/User_model.php | 16 ++++++++++ includes/pages/user_settings.php | 14 ++++++--- includes/sys_menu.php | 54 ++++++++++++++++++-------------- 3 files changed, 57 insertions(+), 27 deletions(-) diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 66aa52e5..6d38a224 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -175,6 +175,22 @@ function User_validate_mail($mail) { return new ValidationResult(check_email($mail), $mail); } +/** + * Validate user jabber address + * + * @param string $jabber + * Jabber-ID to validate + * @return ValidationResult + */ +function User_validate_jabber($jabber) { + $jabber = strip_item($jabber); + if ($jabber == '') { + // Empty is ok + return new ValidationResult(true, ''); + } + return new ValidationResult(check_email($jabber), $jabber); +} + /** * Validate the planned arrival date * diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php index 0a6d8c71..02c61a20 100644 --- a/includes/pages/user_settings.php +++ b/includes/pages/user_settings.php @@ -29,7 +29,7 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) { $user_source['email_by_human_allowed'] = isset($_REQUEST['email_by_human_allowed']); if (isset($_REQUEST['jabber'])) { - $result = User_validate_mail($_REQUEST['jabber']); + $result = User_validate_jabber($_REQUEST['jabber']); $user_source['jabber'] = $result->getValue(); if (! $result->isValid()) { $valid = false; @@ -77,6 +77,8 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) { success(_("Settings saved.")); redirect(page_link_to('user_settings')); } + + return $user_source; } /** @@ -123,6 +125,8 @@ function user_settings_theme($user_source, $themes) { success(_("Theme changed.")); redirect(page_link_to('user_settings')); } + + return $user_source; } /** @@ -149,6 +153,8 @@ function user_settings_locale($user_source, $locales) { success("Language changed."); redirect(page_link_to('user_settings')); } + + return $user_source; } /** @@ -173,13 +179,13 @@ function user_settings() { $user_source = $user; if (isset($_REQUEST['submit'])) { - user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes); + $user_source = user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes); } elseif (isset($_REQUEST['submit_password'])) { user_settings_password($user_source); } elseif (isset($_REQUEST['submit_theme'])) { - user_settings_theme($user_source, $themes); + $user_source = user_settings_theme($user_source, $themes); } elseif (isset($_REQUEST['submit_language'])) { - user_settings_locale($user_source, $locales); + $user_source = user_settings_locale($user_source, $locales); } return User_settings_view($user_source, $locales, $themes, $buildup_start_date, $teardown_end_date, $enable_tshirt_size, $tshirt_sizes); diff --git a/includes/sys_menu.php b/includes/sys_menu.php index 9d70cf10..d8a81324 100644 --- a/includes/sys_menu.php +++ b/includes/sys_menu.php @@ -12,29 +12,9 @@ function page_link_to_absolute($page) { } /** - * Renders the header toolbar containing search, login/logout, user and settings links. + * Render the user hints */ -function header_toolbar() { - global $page, $privileges, $user, $enable_tshirt_size, $max_freeloadable_shifts; - - $toolbar_items = []; - - if (isset($user)) { - $toolbar_items[] = toolbar_item_link(page_link_to('shifts') . '&action=next', 'time', User_shift_state_render($user)); - } - - if (! isset($user) && in_array('register', $privileges)) { - $toolbar_items[] = toolbar_item_link(page_link_to('register'), 'plus', register_title(), $page == 'register'); - } - - if (in_array('login', $privileges)) { - $toolbar_items[] = toolbar_item_link(page_link_to('login'), 'log-in', login_title(), $page == 'login'); - } - - if (isset($user) && in_array('user_messages', $privileges)) { - $toolbar_items[] = toolbar_item_link(page_link_to('user_messages'), 'envelope', user_unread_messages()); - } - +function header_render_hints($user, $page, $enable_tshirt_size) { $hints = []; if (isset($user)) { $hint_class = 'info'; @@ -87,8 +67,36 @@ function header_toolbar() { } } if (count($hints) > 0) { - $toolbar_items[] = toolbar_popover($glyphicon . ' text-' . $hint_class, '', $hints, 'bg-' . $hint_class); + return toolbar_popover($glyphicon . ' text-' . $hint_class, '', $hints, 'bg-' . $hint_class); } + return ''; +} + +/** + * Renders the header toolbar containing search, login/logout, user and settings links. + */ +function header_toolbar() { + global $page, $privileges, $user, $enable_tshirt_size, $max_freeloadable_shifts; + + $toolbar_items = []; + + if (isset($user)) { + $toolbar_items[] = toolbar_item_link(page_link_to('shifts') . '&action=next', 'time', User_shift_state_render($user)); + } + + if (! isset($user) && in_array('register', $privileges)) { + $toolbar_items[] = toolbar_item_link(page_link_to('register'), 'plus', register_title(), $page == 'register'); + } + + if (in_array('login', $privileges)) { + $toolbar_items[] = toolbar_item_link(page_link_to('login'), 'log-in', login_title(), $page == 'login'); + } + + if (isset($user) && in_array('user_messages', $privileges)) { + $toolbar_items[] = toolbar_item_link(page_link_to('user_messages'), 'envelope', user_unread_messages()); + } + + $toolbar_items[] = header_render_hints($user, $page, $enable_tshirt_size); $user_submenu = make_langselect(); $user_submenu[] = toolbar_item_divider();