Fixed error 500 when trying to view a non-existent profile.
This commit is contained in:
parent
bd683d8404
commit
81f4dfce19
3 changed files with 16 additions and 8 deletions
|
@ -14,26 +14,33 @@ $userId = !empty($_GET['u']) && is_string($_GET['u']) ? trim($_GET['u']) : 0;
|
|||
$profileMode = !empty($_GET['m']) && is_string($_GET['m']) ? (string)$_GET['m'] : '';
|
||||
$isEditing = !empty($_GET['edit']) && is_string($_GET['edit']) ? (bool)$_GET['edit'] : !empty($_POST) && is_array($_POST);
|
||||
|
||||
$currentUser = User::getCurrent();
|
||||
$viewingAsGuest = $currentUser === null;
|
||||
$currentUserId = $viewingAsGuest ? 0 : $currentUser->getId();
|
||||
|
||||
try {
|
||||
$profileUser = User::findForProfile($userId);
|
||||
} catch(RuntimeException $ex) {
|
||||
http_response_code(404);
|
||||
Template::render('profile.index');
|
||||
Template::render('profile.index', [
|
||||
'profile_is_guest' => $viewingAsGuest,
|
||||
'profile_is_deleted' => true,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if($profileUser->isDeleted()) {
|
||||
http_response_code(404);
|
||||
Template::render('profile.index');
|
||||
Template::render('profile.index', [
|
||||
'profile_is_guest' => $viewingAsGuest,
|
||||
'profile_is_deleted' => true,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$notices = [];
|
||||
|
||||
$profileFields = new ProfileFields($db);
|
||||
$currentUser = User::getCurrent();
|
||||
$viewingAsGuest = $currentUser === null;
|
||||
$currentUserId = $viewingAsGuest ? 0 : $currentUser->getId();
|
||||
$viewingOwnProfile = $currentUserId === $profileUser->getId();
|
||||
$isBanned = $profileUser->hasActiveWarning();
|
||||
$userPerms = perms_get_user($currentUserId)[MSZ_PERMS_USER];
|
||||
|
@ -443,5 +450,6 @@ if(!empty($template)) {
|
|||
'profile_is_editing' => $isEditing,
|
||||
'profile_is_banned' => $isBanned,
|
||||
'profile_is_guest' => $viewingAsGuest,
|
||||
'profile_is_deleted' => false,
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% from 'macros.twig' import avatar %}
|
||||
{% from '_layout/input.twig' import input_checkbox_raw %}
|
||||
|
||||
<div class="container profile__header" style="--accent-colour: {{ profile_user.colour }}">
|
||||
<div class="container profile__header"{% if profile_user is defined %} style="--accent-colour: {{ profile_user.colour }}"{% endif %}>
|
||||
<div class="profile__header__background"></div>
|
||||
|
||||
<div class="profile__header__details">
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
{% endif %}
|
||||
|
||||
<div class="profile__content">
|
||||
{% set show_profile_fields = not profile_is_guest and (profile_is_editing ? perms.edit_profile : profile_fields_display_values is not empty) %}
|
||||
{% set show_profile_fields = not profile_is_guest and (profile_is_editing ? perms.edit_profile : profile_fields_display_values|default([]) is not empty) %}
|
||||
{% set show_background_settings = profile_is_editing and perms.edit_background %}
|
||||
{% set show_birthdate = profile_is_editing and perms.edit_birthdate %}
|
||||
{% set show_active_forum_info = not profile_is_editing and (profile_active_category_info.forum_id|default(0) > 0 or profile_active_topic_info.topic_id|default(0) > 0) %}
|
||||
|
@ -102,7 +102,7 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if current_user is not defined %}
|
||||
{% if current_user is not defined and not profile_is_deleted %}
|
||||
<div class="container profile__container">
|
||||
<div class="profile__accounts__notice">
|
||||
You must <a href="{{ url('auth-login') }}" class="profile__accounts__link">log in</a> to view full profiles!
|
||||
|
|
Loading…
Reference in a new issue