summaryrefslogtreecommitdiff
path: root/src/application/templates/old/view_user.twig
blob: 311dfb1d25f1d38e7e73f2f0d90927afa00aba12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
{% set canEdit =
    currentUser is not null
    and (
        (
            ctx.user.id == currentUser.id
            and currentUser.hasPermission(permission("EDIT_OWN_USER"))
        )
        or currentUser.hasPermission(permission("EDIT_OTHER_USER"))
    ) %}

{% set isOwnProfile =
    currentUser is not null
    and currentUser.id == ctx.user.id %}

{% set sUserPossessive = isOwnProfile ? "Your posts" : "%display_name%'s posts" %}

{% set emailPending = isOwnProfile and ctx.user.pendingEmail is not null %}

{% set title = ctx.user.displayName %}

{% extends "base.twig" %}

{% block content %}

<div class="clearfix">
    <img class="pull-left m-r-lg" src="?_action=profilepicture&amp;user={{ ctx.user.id|url_encode }}" alt="{{ __("Profile picture") }}" width="64" height="64">
    <span class="h1">{{ ctx.user.displayName }}</span>
    {% if isOwnProfile %}
        <font color="red">[{{ __("You") }}]</font>
    {% endif %}<br>
    @{{ ctx.user.name }}<br>
    <font color="gray">{{ __("Member since %join_date%", {
        "join_date": '<span class="_date">' ~ (ctx.dateJoined.format("c")|e("html")) ~ '</span>',
    }) }}</font>
</div>
<hr color="silver" noshade>

{% if canEdit %}
<table>
<tr>
<td valign="top" width="100%">
{% endif %}

<h3>{{ __(sUserPossessive, {
    "display_name": ctx.user.displayName|e("html"),
}) }}</h3>

{% if ctx.posts|length > 0 %}
    <table border="1" width="100%" cellspacing="0" cellpadding="4" bordercolor="silver">
        {% for post in ctx.posts %}
            <tr>
                <td>
                    {% set hasAttachments = ctx.attachments[post.id] is defined and ctx.attachments[post.id]|length > 0 %}
                    {% if hasAttachments %}
                        <img src="/ui/theme-files/old/paperclip_small.gif" class="inline-icon" width="10" height="10" draggable="false" alt="">
                    {% endif %}
                    <a href="?_action=viewtopic&amp;topic={{ post.topicId|url_encode }}#post-{{ post.id|url_encode }}">{{ renderPostSummary(post.content) }}</a>
                    <br>
                    {{ __("posted on %post_date% in %topic%", {
                        "post_date": '<span class="_time">' ~ post.postDate.format("c")|e("html") ~ '</span>',
                        "topic": '<br><font color="green">'
                            ~ (ctx.topics[post.topicId].isLocked ? ('<img src="/ui/theme-files/old/lock_small.gif" class="inline-icon" width="10" height="10" draggable="false" alt="' ~ __("This topic has been locked") ~ '"> ') : '')
                            ~ (ctx.topics[post.topicId] ? ctx.topics[post.topicId].title : null)|default(__("unknown"))|e("html") ~ '</font>',
                    }) }}
                </td>
            </tr>
        {% endfor %}
    </table>
{% else %}
    {% include "components/alert_info.twig" with { message: __("This user has not posted anything yet") } %}
{% endif %}

{% if canEdit %}
</td>
<td width="250" valign="top">
    <h3>{{ __("Edit profile") }}</h3>
    {% set formId = "update_profile" %}
    {% set formError = getAndClearFormError(formId) %}
    {% if formError %}
        {% include "components/alert_error.twig" with { message: formError } %}
    {% endif %}
    <form action="{{ g.server.REQUEST_URI }}" method="post" enctype="multipart/form-data">
        <input type="hidden" name="form_id" value="{{ formId }}">
        
        <label for="i_display_name">{{ __("Display name:") }}</label><br>
        <input required type="text" name="display_name" id="i_display_name" value="{{ ctx.user.displayName }}"><br>
        <br>
        
        <label for="i_name">{{ __("Username:") }}</label><br>
        {% if ctx.lastNameChangeTooRecent %}
            <input type="text" id="i_name" value="{{ ctx.user.name }}" disabled><br>
            <font color="red"><small><strong>{{ __("You can only change your username every 30 days!") }}</strong></small></font><br>
        {% else %}
            <input required type="text" name="name" id="i_name" value="{{ ctx.user.name }}"><br>
        {% endif %}
        <br>
        
        <label for="i_email">{{ __("Email address:") }}</label><br>
        {% if emailPending %}
            <input type="email" id="i_email" value="{{ ctx.user.email }}" disabled><br>
        {% else %}
            <input required type="email" id="i_email" name="email" value="{{ ctx.user.email }}"><br>
        {% endif %}

        
        <label>{{ __("Profile picture:") }}</label><br>
        <div class="radio margin-top-0 {{ ctx.user.profilePicture is empty ? " disabled text-muted" }}">
            <label>
                <input type="radio" name="pfp_action" id="pfp_action_1" value="keep"{{ ctx.user.profilePicture is not empty ? ' checked' : ' disabled' }}>
                {{ __("Keep current profile picture") }}
            </label>
        </div>
        <div class="radio">
            <label>
                <input type="radio" name="pfp_action" id="pfp_action_2" value="remove"{{ ctx.user.profilePicture is empty ? ' checked' : '' }}>
                {% if ctx.user.profilePicture is empty %}
                    {{ __("No profile picture") }}
                {% else %}
                    {{ __("Remove profile picture") }}
                {% endif %}
            </label>
        </div>
        <div class="radio">
            <label>
                <input type="radio" name="pfp_action" value="replace" id="pfp_action_3">
                {{ __("Upload new profile picture") }}
            </label>
        </div>
        <input type="file" name="pfp" id="i_pfp" accept="image/png,image/jpeg" class="m-l-lg" style="width:180px"><br>
        <br>
        
        <button type="submit">{{ __("Save changes") }}</button><br>
    </form>
    {% if isOwnProfile %}
        <hr color="silver" noshade>
        <h3>{{ __("Change password") }}</h3>
        {% set formId = "update_password" %}
        {% set formError = getAndClearFormError(formId) %}
        {% if formError %}
            {% include "components/alert_error.twig" with { message: formError } %}
        {% endif %}
        <form action="{{ g.server.REQUEST_URI }}" method="post">
            <input type="hidden" name="form_id" value="{{ formId }}">
            
            <label for="i_current_password">{{ __("Current password:") }}</label><br>
            <input autocomplete="current-password" required class="form-control" type="password" name="current_password" id="i_current_password" required><br>
            <br>

            <label for="i_new_password">{{ __("New password:") }}</label><br>
            <input autocomplete="new-password" required class="form-control" type="password" name="new_password" id="i_new_password" required><br>
            <br>
            
            <label for="i_retype_password">{{ __("Retype password:") }}</label><br>
            <input autocomplete="new-password" required class="form-control" type="password" name="retype_password" id="i_retype_password" required><br>
            <br>
            
            <button type="submit">{{ __("Change password") }}</button>
        </form>
    {% endif %}
</td>
</tr>
</table>
{% endif %}

<script>
$(function() {
    $(".post-container").each(function(i, e) {
        if ($(e).height() > 900) { // more than 800 so it doesn't collapse just a few pixels
            $(e).addClass("collapsed");
        }
        $(e).find(".post-container-controls button").click(function() {
            $(e).removeClass("collapsed");
        });
    });
});
{% if canEdit %}
$(function() {
    function _hide() {
        $("#i_pfp").hide().prop("disabled", true).prop("required", false);
        $("#i_pfp + .file-input-group").hide().find("button").prop("disabled", true);
    }
    _hide();
    setTimeout(_hide, 10);
    $("[name='pfp_action']").on("change input check click", function() {
        if ($("#pfp_action_3").is(":checked")) {
            $("#i_pfp").show().prop("disabled", false).prop("required", true);
            $("#i_pfp + .file-input-group").show().find("button").prop("disabled", false);
        } else {
            _hide();
        }
    })
});
{% endif %}
</script>

{% endblock %}