reduce complexity of user settings main

This commit is contained in:
msquare 2016-11-11 17:00:51 +01:00
parent beb0db6852
commit 03c9d1ef5d
3 changed files with 37 additions and 32 deletions

View File

@ -163,6 +163,18 @@ function User_validate_Nick($nick) {
return preg_replace("/([^a-z0-9üöäß. _+*-]{1,})/ui", '', $nick); return preg_replace("/([^a-z0-9üöäß. _+*-]{1,})/ui", '', $nick);
} }
/**
* Validate user email address.
*
* @param string $mail
* The email address to validate
* @return ValidationResult
*/
function User_validate_mail($mail) {
$mail = strip_item($mail);
return new ValidationResult(check_email($mail), $mail);
}
/** /**
* Validate the planned arrival date * Validate the planned arrival date
* *

View File

@ -13,9 +13,10 @@ function settings_title() {
function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) { function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) {
$valid = true; $valid = true;
if (isset($_REQUEST['mail']) && strlen(strip_request_item('mail')) > 0) { if (isset($_REQUEST['mail'])) {
$user_source['email'] = strip_request_item('mail'); $result = User_validate_mail($_REQUEST['mail']);
if (! check_email($user_source['email'])) { $user_source['email'] = $result->getValue();
if (! $result->isValid()) {
$valid = false; $valid = false;
error(_("E-mail address is not correct.")); error(_("E-mail address is not correct."));
} }
@ -27,9 +28,10 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) {
$user_source['email_shiftinfo'] = isset($_REQUEST['email_shiftinfo']); $user_source['email_shiftinfo'] = isset($_REQUEST['email_shiftinfo']);
$user_source['email_by_human_allowed'] = isset($_REQUEST['email_by_human_allowed']); $user_source['email_by_human_allowed'] = isset($_REQUEST['email_by_human_allowed']);
if (isset($_REQUEST['jabber']) && strlen(strip_request_item('jabber')) > 0) { if (isset($_REQUEST['jabber'])) {
$user_source['jabber'] = strip_request_item('jabber'); $result = User_validate_mail($_REQUEST['jabber']);
if (! check_email($user_source['jabber'])) { $user_source['jabber'] = $result->getValue();
if (! $result->isValid()) {
$valid = false; $valid = false;
error(_("Please check your jabber account information.")); error(_("Please check your jabber account information."));
} }
@ -41,7 +43,8 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) {
$valid = false; $valid = false;
} }
if (isset($_REQUEST['planned_arrival_date']) && $tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date'])) { if (isset($_REQUEST['planned_arrival_date'])) {
$tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date']);
$result = User_validate_planned_arrival_date($tmp); $result = User_validate_planned_arrival_date($tmp);
$user_source['planned_arrival_date'] = $result->getValue(); $user_source['planned_arrival_date'] = $result->getValue();
if (! $result->isValid()) { if (! $result->isValid()) {
@ -50,7 +53,8 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) {
} }
} }
if (isset($_REQUEST['planned_departure_date']) && $tmp = parse_date("Y-m-d", $_REQUEST['planned_departure_date'])) { if (isset($_REQUEST['planned_departure_date'])) {
$tmp = parse_date("Y-m-d", $_REQUEST['planned_departure_date']);
$result = User_validate_planned_departure_date($user_source['planned_arrival_date'], $tmp); $result = User_validate_planned_departure_date($user_source['planned_arrival_date'], $tmp);
$user_source['planned_departure_date'] = $result->getValue(); $user_source['planned_departure_date'] = $result->getValue();
if (! $result->isValid()) { if (! $result->isValid()) {
@ -60,27 +64,13 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) {
} }
// Trivia // Trivia
if (isset($_REQUEST['lastname'])) { $user_source['Name'] = strip_request_item('lastname', $user_source['Name']);
$user_source['Name'] = strip_request_item('lastname'); $user_source['Vorname'] = strip_request_item('prename', $user_source['Vorname']);
} $user_source['Alter'] = strip_request_item('age', $user_source['Alter']);
if (isset($_REQUEST['prename'])) { $user_source['Telefon'] = strip_request_item('tel', $user_source['Telefon']);
$user_source['Vorname'] = strip_request_item('prename'); $user_source['DECT'] = strip_request_item('dect', $user_source['DECT']);
} $user_source['Handy'] = strip_request_item('mobile', $user_source['Handy']);
if (isset($_REQUEST['age']) && preg_match("/^[0-9]{0,4}$/", $_REQUEST['age'])) { $user_source['Hometown'] = strip_request_item('hometown', $user_source['Hometown']);
$user_source['Alter'] = strip_request_item('age');
}
if (isset($_REQUEST['tel'])) {
$user_source['Telefon'] = strip_request_item('tel');
}
if (isset($_REQUEST['dect'])) {
$user_source['DECT'] = strip_request_item('dect');
}
if (isset($_REQUEST['mobile'])) {
$user_source['Handy'] = strip_request_item('mobile');
}
if (isset($_REQUEST['hometown'])) {
$user_source['Hometown'] = strip_request_item('hometown');
}
if ($valid) { if ($valid) {
User_update($user_source); User_update($user_source);

View File

@ -141,10 +141,13 @@ function check_date($input, $error_message = null, $null_allowed = false) {
} }
/** /**
* Gibt den gefilterten REQUEST Wert ohne Zeilenumbrüche zurück * Returns REQUEST value filtered or default value (null) if not set.
*/ */
function strip_request_item($name) { function strip_request_item($name, $default_value = null) {
return strip_item($_REQUEST[$name]); if (isset($_REQUEST[$name])) {
return strip_item($_REQUEST[$name]);
}
return $default_value;
} }
/** /**