Log messages without inline HTML

main
Igor Scheller 6 years ago committed by msquare
parent e7f10d846e
commit 4e709d0d23

@ -33,7 +33,7 @@ return [
], ],
// Link to documentation/help // Link to documentation/help
'documentation_url' => 'https://engelsystem.de/doc/', 'documentation_url' => 'https://engelsystem.de/doc/',
// Email config // Email config
'email' => [ 'email' => [

@ -62,7 +62,7 @@ function user_angeltypes_delete_all_controller()
if ($request->hasPostData('deny_all')) { if ($request->hasPostData('deny_all')) {
UserAngelTypes_delete_all($angeltype['id']); UserAngelTypes_delete_all($angeltype['id']);
engelsystem_log(sprintf('Denied all users for angeltype %s', AngelType_name_render($angeltype))); engelsystem_log(sprintf('Denied all users for angeltype %s', AngelType_name_render($angeltype, true)));
success(sprintf(__('Denied all users for angeltype %s.'), AngelType_name_render($angeltype))); success(sprintf(__('Denied all users for angeltype %s.'), AngelType_name_render($angeltype)));
redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]));
} }
@ -102,7 +102,7 @@ function user_angeltypes_confirm_all_controller()
if ($request->hasPostData('confirm_all')) { if ($request->hasPostData('confirm_all')) {
UserAngelTypes_confirm_all($angeltype['id'], $user->id); UserAngelTypes_confirm_all($angeltype['id'], $user->id);
engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype))); engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype, true)));
success(sprintf(__('Confirmed all users for angeltype %s.'), AngelType_name_render($angeltype))); success(sprintf(__('Confirmed all users for angeltype %s.'), AngelType_name_render($angeltype)));
redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]));
} }
@ -156,8 +156,8 @@ function user_angeltype_confirm_controller()
engelsystem_log(sprintf( engelsystem_log(sprintf(
'%s confirmed for angeltype %s', '%s confirmed for angeltype %s',
User_Nick_render($user_source), User_Nick_render($user_source, true),
AngelType_name_render($angeltype) AngelType_name_render($angeltype, true)
)); ));
success(sprintf( success(sprintf(
__('%s confirmed for angeltype %s.'), __('%s confirmed for angeltype %s.'),
@ -214,9 +214,8 @@ function user_angeltype_delete_controller()
if ($request->hasPostData('delete')) { if ($request->hasPostData('delete')) {
UserAngelType_delete($user_angeltype); UserAngelType_delete($user_angeltype);
$success_message = sprintf(__('User %s removed from %s.'), User_Nick_render($user_source), $angeltype['name']); engelsystem_log(sprintf('User %s removed from %s.', User_Nick_render($user_source, true), $angeltype['name']));
engelsystem_log($success_message); success(sprintf(__('User %s removed from %s.'), User_Nick_render($user_source), $angeltype['name']));
success($success_message);
redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]));
} }
@ -275,15 +274,19 @@ function user_angeltype_update_controller()
if ($request->hasPostData('submit')) { if ($request->hasPostData('submit')) {
UserAngelType_update($user_angeltype['id'], $supporter); UserAngelType_update($user_angeltype['id'], $supporter);
$success_message = sprintf( $msg = $supporter
$supporter ? __('Added supporter rights for %s to %s.')
? __('Added supporter rights for %s to %s.') : __('Removed supporter rights for %s from %s.');
: __('Removed supporter rights for %s from %s.'), engelsystem_log(sprintf(
$msg,
AngelType_name_render($angeltype, true),
User_Nick_render($user_source, true)
));
success(sprintf(
$msg,
AngelType_name_render($angeltype), AngelType_name_render($angeltype),
User_Nick_render($user_source) User_Nick_render($user_source)
); ));
engelsystem_log($success_message);
success($success_message);
redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]));
} }
@ -324,8 +327,8 @@ function user_angeltype_add_controller()
engelsystem_log(sprintf( engelsystem_log(sprintf(
'User %s added to %s.', 'User %s added to %s.',
User_Nick_render($user_source), User_Nick_render($user_source, true),
AngelType_name_render($angeltype) AngelType_name_render($angeltype, true)
)); ));
success(sprintf( success(sprintf(
__('User %s added to %s.'), __('User %s added to %s.'),
@ -336,8 +339,8 @@ function user_angeltype_add_controller()
UserAngelType_confirm($user_angeltype_id, $user_source->id); UserAngelType_confirm($user_angeltype_id, $user_source->id);
engelsystem_log(sprintf( engelsystem_log(sprintf(
'User %s confirmed as %s.', 'User %s confirmed as %s.',
User_Nick_render($user_source), User_Nick_render($user_source, true),
AngelType_name_render($angeltype) AngelType_name_render($angeltype, true)
)); ));
redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]));
@ -372,8 +375,8 @@ function user_angeltype_join_controller($angeltype)
$success_message = sprintf(__('You joined %s.'), $angeltype['name']); $success_message = sprintf(__('You joined %s.'), $angeltype['name']);
engelsystem_log(sprintf( engelsystem_log(sprintf(
'User %s joined %s.', 'User %s joined %s.',
User_Nick_render($user), User_Nick_render($user, true),
AngelType_name_render($angeltype) AngelType_name_render($angeltype, true)
)); ));
success($success_message); success($success_message);
@ -381,8 +384,8 @@ function user_angeltype_join_controller($angeltype)
UserAngelType_confirm($user_angeltype_id, $user->id); UserAngelType_confirm($user_angeltype_id, $user->id);
engelsystem_log(sprintf( engelsystem_log(sprintf(
'User %s confirmed as %s.', 'User %s confirmed as %s.',
User_Nick_render($user), User_Nick_render($user, true),
AngelType_name_render($angeltype) AngelType_name_render($angeltype, true)
)); ));
} }

@ -85,7 +85,7 @@ function user_delete_controller()
mail_user_delete($user_source); mail_user_delete($user_source);
success(__('User deleted.')); success(__('User deleted.'));
engelsystem_log(sprintf('Deleted %s', User_Nick_render($user_source))); engelsystem_log(sprintf('Deleted %s', User_Nick_render($user_source, true)));
redirect(users_link()); redirect(users_link());
} }
@ -170,7 +170,7 @@ function user_edit_vouchers_controller()
$user_source->state->save(); $user_source->state->save();
success(__('Saved the number of vouchers.')); success(__('Saved the number of vouchers.'));
engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf('Got %s vouchers', engelsystem_log(User_Nick_render($user_source, true) . ': ' . sprintf('Got %s vouchers',
$user_source->state->got_voucher)); $user_source->state->got_voucher));
redirect(user_link($user_source->id)); redirect(user_link($user_source->id));

@ -48,7 +48,7 @@ function AngelType_delete($angeltype)
WHERE `id`=? WHERE `id`=?
LIMIT 1 LIMIT 1
', [$angeltype['id']]); ', [$angeltype['id']]);
engelsystem_log('Deleted angeltype: ' . AngelType_name_render($angeltype)); engelsystem_log('Deleted angeltype: ' . AngelType_name_render($angeltype, true));
} }
/** /**

@ -94,7 +94,7 @@ function ShiftEntry_create($shift_entry)
] ]
); );
engelsystem_log( engelsystem_log(
'User ' . User_Nick_render($user) 'User ' . User_Nick_render($user, true)
. ' signed up for shift ' . $shift['name'] . ' signed up for shift ' . $shift['name']
. ' from ' . date('Y-m-d H:i', $shift['start']) . ' from ' . date('Y-m-d H:i', $shift['start'])
. ' to ' . date('Y-m-d H:i', $shift['end']) . ' to ' . date('Y-m-d H:i', $shift['end'])
@ -156,7 +156,7 @@ function ShiftEntry_delete($shiftEntry)
$angeltype = AngelType($shiftEntry['TID']); $angeltype = AngelType($shiftEntry['TID']);
engelsystem_log( engelsystem_log(
'Shift signout: ' . User_Nick_render($signout_user) . ' from shift ' . $shifttype['name'] 'Shift signout: ' . User_Nick_render($signout_user, true) . ' from shift ' . $shifttype['name']
. ' at ' . $room['Name'] . ' at ' . $room['Name']
. ' from ' . date('Y-m-d H:i', $shift['start']) . ' from ' . date('Y-m-d H:i', $shift['start'])
. ' to ' . date('Y-m-d H:i', $shift['end']) . ' to ' . date('Y-m-d H:i', $shift['end'])

@ -47,7 +47,7 @@ function UserWorkLog_delete($userWorkLog)
engelsystem_log(sprintf( engelsystem_log(sprintf(
'Delete work log for %s, %s hours, %s', 'Delete work log for %s, %s hours, %s',
User_Nick_render($user_source), User_Nick_render($user_source, true),
$userWorkLog['work_hours'], $userWorkLog['work_hours'],
$userWorkLog['comment'] $userWorkLog['comment']
)); ));
@ -78,7 +78,7 @@ function UserWorkLog_update($userWorkLog)
engelsystem_log(sprintf( engelsystem_log(sprintf(
'Updated work log for %s, %s hours, %s', 'Updated work log for %s, %s hours, %s',
User_Nick_render($user_source), User_Nick_render($user_source, true),
$userWorkLog['work_hours'], $userWorkLog['work_hours'],
$userWorkLog['comment']) $userWorkLog['comment'])
); );
@ -115,7 +115,7 @@ function UserWorkLog_create($userWorkLog)
time() time()
]); ]);
engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s', User_Nick_render($user_source), engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s', User_Nick_render($user_source, true),
$userWorkLog['work_hours'], $userWorkLog['comment'])); $userWorkLog['work_hours'], $userWorkLog['comment']));
return $result; return $result;

@ -5,6 +5,7 @@ use Engelsystem\Database\DB;
use Engelsystem\Models\User\PasswordReset; use Engelsystem\Models\User\PasswordReset;
use Engelsystem\Models\User\User; use Engelsystem\Models\User\User;
use Engelsystem\ValidationResult; use Engelsystem\ValidationResult;
use Illuminate\Database\Query\JoinClause;
/** /**
* User model * User model
@ -118,10 +119,10 @@ function User_validate_Nick($nick)
{ {
$nick = trim($nick); $nick = trim($nick);
if(strlen($nick) == 0 || strlen($nick) > 23) { if (strlen($nick) == 0 || strlen($nick) > 23) {
return new ValidationResult(false, $nick); return new ValidationResult(false, $nick);
} }
if(preg_match('/([^\p{L}\p{N}\-_. ]+)/ui', $nick)) { if (preg_match('/([^\p{L}\p{N}\-_. ]+)/ui', $nick)) {
return new ValidationResult(false, $nick); return new ValidationResult(false, $nick);
} }
@ -222,7 +223,7 @@ function User_reset_api_key($user, $log = true)
$user->save(); $user->save();
if ($log) { if ($log) {
engelsystem_log(sprintf('API key resetted (%s).', User_Nick_render($user))); engelsystem_log(sprintf('API key resetted (%s).', User_Nick_render($user, true)));
} }
} }
@ -239,7 +240,7 @@ function User_generate_password_recovery_token($user)
$reset->token = md5($user->name . time() . rand()); $reset->token = md5($user->name . time() . rand());
$reset->save(); $reset->save();
engelsystem_log('Password recovery for ' . User_Nick_render($user) . ' started.'); engelsystem_log('Password recovery for ' . User_Nick_render($user, true) . ' started.');
return $reset->token; return $reset->token;
} }

@ -86,7 +86,7 @@ function admin_active()
foreach ($users as $usr) { foreach ($users as $usr) {
$usr->state->active = true; $usr->state->active = true;
$usr->state->save(); $usr->state->save();
$user_nicks[] = User_Nick_render($usr); $user_nicks[] = User_Nick_render($usr, true);
} }
State::whereForceActive(true)->update(['active' => true]); State::whereForceActive(true)->update(['active' => true]);
@ -108,7 +108,7 @@ function admin_active()
if ($user_source) { if ($user_source) {
$user_source->state->active = true; $user_source->state->active = true;
$user_source->state->save(); $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' is active now.'); engelsystem_log('User ' . User_Nick_render($user_source, true) . ' is active now.');
$msg = success(__('Angel has been marked as active.'), true); $msg = success(__('Angel has been marked as active.'), true);
} else { } else {
$msg = error(__('Angel not found.'), true); $msg = error(__('Angel not found.'), true);
@ -119,7 +119,7 @@ function admin_active()
if ($user_source) { if ($user_source) {
$user_source->state->active = false; $user_source->state->active = false;
$user_source->state->save(); $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' is NOT active now.'); engelsystem_log('User ' . User_Nick_render($user_source, true) . ' is NOT active now.');
$msg = success(__('Angel has been marked as not active.'), true); $msg = success(__('Angel has been marked as not active.'), true);
} else { } else {
$msg = error(__('Angel not found.'), true); $msg = error(__('Angel not found.'), true);
@ -130,7 +130,7 @@ function admin_active()
if ($user_source) { if ($user_source) {
$user_source->state->got_shirt = true; $user_source->state->got_shirt = true;
$user_source->state->save(); $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' has tshirt now.'); engelsystem_log('User ' . User_Nick_render($user_source, true) . ' has tshirt now.');
$msg = success(__('Angel has got a t-shirt.'), true); $msg = success(__('Angel has got a t-shirt.'), true);
} else { } else {
$msg = error('Angel not found.', true); $msg = error('Angel not found.', true);
@ -141,7 +141,7 @@ function admin_active()
if ($user_source) { if ($user_source) {
$user_source->state->got_shirt = false; $user_source->state->got_shirt = false;
$user_source->state->save(); $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' has NO tshirt.'); engelsystem_log('User ' . User_Nick_render($user_source, true) . ' has NO tshirt.');
$msg = success(__('Angel has got no t-shirt.'), true); $msg = success(__('Angel has got no t-shirt.'), true);
} else { } else {
$msg = error(__('Angel not found.'), true); $msg = error(__('Angel not found.'), true);

@ -37,7 +37,7 @@ function admin_arrive()
$user_source->state->arrival_date = null; $user_source->state->arrival_date = null;
$user_source->state->save(); $user_source->state->save();
engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source)); engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source, true));
success(__('Reset done. Angel has not arrived.')); success(__('Reset done. Angel has not arrived.'));
redirect(user_link($user_source->id)); redirect(user_link($user_source->id));
} else { } else {
@ -55,7 +55,7 @@ function admin_arrive()
$user_source->state->arrival_date = new Carbon\Carbon(); $user_source->state->arrival_date = new Carbon\Carbon();
$user_source->state->save(); $user_source->state->save();
engelsystem_log('User set has arrived: ' . User_Nick_render($user_source)); engelsystem_log('User set has arrived: ' . User_Nick_render($user_source, true));
success(__('Angel has been marked as arrived.')); success(__('Angel has been marked as arrived.'));
redirect(user_link($user_source->id)); redirect(user_link($user_source->id));
} else { } else {

@ -130,9 +130,9 @@ function admin_questions()
); );
engelsystem_log( engelsystem_log(
'Question ' 'Question '
. htmlspecialchars($question['Question']) . $question['Question']
. ' answered: ' . ' answered: '
. htmlspecialchars($answer) . $answer
); );
redirect(page_link_to('admin_questions')); redirect(page_link_to('admin_questions'));
} else { } else {
@ -159,7 +159,7 @@ function admin_questions()
); );
if (!empty($question)) { if (!empty($question)) {
DB::delete('DELETE FROM `Questions` WHERE `QID`=? LIMIT 1', [$question_id]); DB::delete('DELETE FROM `Questions` WHERE `QID`=? LIMIT 1', [$question_id]);
engelsystem_log('Question deleted: ' . htmlspecialchars($question['Question'])); engelsystem_log('Question deleted: ' . $question['Question']);
redirect(page_link_to('admin_questions')); redirect(page_link_to('admin_questions'));
} else { } else {
return error('No question found.', true); return error('No question found.', true);

@ -240,7 +240,7 @@ function admin_user()
} }
$user_source = User::find($user_id); $user_source = User::find($user_id);
engelsystem_log( engelsystem_log(
'Set groups of ' . User_Nick_render($user_source) . ' to: ' 'Set groups of ' . User_Nick_render($user_source, true) . ' to: '
. join(', ', $user_groups_info) . join(', ', $user_groups_info)
); );
$html .= success('Benutzergruppen gespeichert.', true); $html .= success('Benutzergruppen gespeichert.', true);
@ -293,7 +293,7 @@ function admin_user()
) { ) {
set_password($user_id, $request->postData('new_pw')); set_password($user_id, $request->postData('new_pw'));
$user_source = User::find($user_id); $user_source = User::find($user_id);
engelsystem_log('Set new password for ' . User_Nick_render($user_source)); engelsystem_log('Set new password for ' . User_Nick_render($user_source, true));
$html .= success('Passwort neu gesetzt.', true); $html .= success('Passwort neu gesetzt.', true);
} else { } else {
$html .= error( $html .= error(

@ -87,9 +87,10 @@ function guest_register()
$nickValidation = User_validate_Nick($request->input('nick')); $nickValidation = User_validate_Nick($request->input('nick'));
$nick = $nickValidation->getValue(); $nick = $nickValidation->getValue();
if(!$nickValidation->isValid()) { if (!$nickValidation->isValid()) {
$valid = false; $valid = false;
$msg .= error(sprintf(__('Please enter a valid nick.') . ' ' . __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.'), $nick), true); $msg .= error(sprintf(__('Please enter a valid nick.') . ' ' . __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.'),
$nick), true);
} }
if (User::whereName($nick)->count() > 0) { if (User::whereName($nick)->count() > 0) {
$valid = false; $valid = false;
@ -246,7 +247,7 @@ function guest_register()
} }
engelsystem_log( engelsystem_log(
'User ' . User_Nick_render($user) 'User ' . User_Nick_render($user, true)
. ' signed up as: ' . join(', ', $user_angel_types_info) . ' signed up as: ' . join(', ', $user_angel_types_info)
); );
success(__('Angel registration successful!')); success(__('Angel registration successful!'));
@ -287,7 +288,8 @@ function guest_register()
div('row', [ div('row', [
div('col-sm-4', [ div('col-sm-4', [
form_text('nick', __('Nick') . ' ' . entry_required(), $nick), form_text('nick', __('Nick') . ' ' . entry_required(), $nick),
form_info('', __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.')) form_info('',
__('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.'))
]), ]),
div('col-sm-8', [ div('col-sm-8', [
form_email('mail', __('E-Mail') . ' ' . entry_required(), $mail), form_email('mail', __('E-Mail') . ' ' . entry_required(), $mail),

@ -99,7 +99,7 @@ function user_myshifts()
]); ]);
engelsystem_log( engelsystem_log(
'Updated ' . User_Nick_render($user_source) . '\'s shift ' . $shift['name'] 'Updated ' . User_Nick_render($user_source, true) . '\'s shift ' . $shift['name']
. ' from ' . date('Y-m-d H:i', $shift['start']) . ' from ' . date('Y-m-d H:i', $shift['start'])
. ' to ' . date('Y-m-d H:i', $shift['end']) . ' to ' . date('Y-m-d H:i', $shift['end'])
. ' with comment ' . $comment . ' with comment ' . $comment

@ -156,7 +156,7 @@ function user_news_comments()
] ]
); );
engelsystem_log('Created news_comment: ' . htmlspecialchars($text)); engelsystem_log('Created news_comment: ' . $text);
$html .= success(__('Entry saved.'), true); $html .= success(__('Entry saved.'), true);
} }

@ -18,7 +18,7 @@ function engelsystem_log($message, $level = LogLevel::INFO)
$user = auth()->user(); $user = auth()->user();
if ($user) { if ($user) {
$nick = User_Nick_render($user); $nick = User_Nick_render($user, true);
} }
$logger->log($level, '{nick}: {message}', ['nick' => $nick, 'message' => $message]); $logger->log($level, '{nick}: {message}', ['nick' => $nick, 'message' => $message]);

@ -12,10 +12,15 @@ use Engelsystem\ShiftsFilterRenderer;
* Renders the angeltypes name as link. * Renders the angeltypes name as link.
* *
* @param array $angeltype * @param array $angeltype
* @param bool $plain
* @return string * @return string
*/ */
function AngelType_name_render($angeltype) function AngelType_name_render($angeltype, $plain = false)
{ {
if ($plain) {
return sprintf('%s (%u)', $angeltype['name'], $angeltype['id']);
}
return '<a href="' . angeltype_link($angeltype['id']) . '">' return '<a href="' . angeltype_link($angeltype['id']) . '">'
. ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name'] . ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name']
. '</a>'; . '</a>';

@ -36,7 +36,10 @@ function User_settings_view(
form_info('', __('Here you can change your user details.')), form_info('', __('Here you can change your user details.')),
form_info(entry_required() . ' = ' . __('Entry required!')), form_info(entry_required() . ' = ' . __('Entry required!')),
form_text('nick', __('Nick'), $user_source->name, true), form_text('nick', __('Nick'), $user_source->name, true),
form_info('', __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.')), form_info(
'',
__('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.')
),
form_text('lastname', __('Last name'), $personalData->last_name), form_text('lastname', __('Last name'), $personalData->last_name),
form_text('prename', __('First name'), $personalData->first_name), form_text('prename', __('First name'), $personalData->first_name),
$enable_planned_arrival ? form_date( $enable_planned_arrival ? form_date(
@ -856,14 +859,19 @@ function User_groups_render($user_groups)
* Render a user nickname. * Render a user nickname.
* *
* @param array|User $user * @param array|User $user
* @param bool $plain
* @return string * @return string
*/ */
function User_Nick_render($user) function User_Nick_render($user, $plain = false)
{ {
if (is_array($user)) { if (is_array($user)) {
$user = (new User())->forceFill($user); $user = (new User())->forceFill($user);
} }
if ($plain) {
return sprintf('%s (%u)', $user->name, $user->id);
}
return render_profile_link( return render_profile_link(
'<span class="icon-icon_angel"></span> ' . htmlspecialchars($user->name) . '</a>', '<span class="icon-icon_angel"></span> ' . htmlspecialchars($user->name) . '</a>',
$user->id, $user->id,

Loading…
Cancel
Save