-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
profile.php
298 lines (286 loc) · 15.9 KB
/
profile.php
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
require_once 'includes/header.php';
?>
<script src="scripts/libs/sortable.min.js"></script>
<script src="scripts/libs/qrcode.min.js"></script>
<style>
.logo-preview:after {
content: '<?= translate('upload_logo', $i18n) ?>';
}
</style>
<section class="contain settings">
<section class="account-section">
<header>
<h2><?= translate('user_details', $i18n) ?></h2>
</header>
<form action="endpoints/user/saveuser.php" method="post" id="userForm" enctype="multipart/form-data">
<div class="user-form">
<div class="fields">
<div>
<div class="user-avatar">
<img src="<?= $userData['avatar'] ?>" alt="avatar" class="avatar" id="avatarImg"
onClick="toggleAvatarSelect()" />
<span class="edit-avatar" onClick="toggleAvatarSelect()" title="Change Avatar">
<i class="fa-solid fa-pencil"></i>
</span>
</div>
<input type="hidden" name="avatar" value="<?= $userData['avatar'] ?>" id="avatarUser" />
<div class="avatar-select" id="avatarSelect">
<div class="avatar-list">
<?php foreach (scandir('images/avatars') as $index => $image): ?>
<?php if (!str_starts_with($image, '.')): ?>
<img src="images/avatars/<?= $image ?>" alt="<?= $image ?>" class="avatar-option"
data-src="images/avatars/<?= $image ?>">
<?php endif ?>
<?php endforeach ?>
<?php foreach (scandir('images/uploads/logos/avatars') as $index => $image): ?>
<?php if (!str_starts_with($image, '.')): ?>
<div class="avatar-container" data-src="<?= $image ?>">
<img src="images/uploads/logos/avatars/<?= $image ?>" alt="<?= $image ?>"
class="avatar-option" data-src="images/uploads/logos/avatars/<?= $image ?>">
<div class="remove-avatar" onclick="deleteAvatar('<?= $image ?>')"
title="Delete avatar">
<i class="fa-solid fa-xmark"></i>
</div>
</div>
<?php endif ?>
<?php endforeach ?>
<label for="profile_pic" class="add-avatar"
title="<?= translate('upload_avatar', $i18n) ?>">
<i class="fa-solid fa-arrow-up-from-bracket"></i>
</label>
</div>
<input type="file" id="profile_pic" class="hidden-input" name="profile_pic"
accept="image/jpeg, image/png, image/gif, image/webp"
onChange="successfulUpload(this, '<?= addslashes(translate('file_type_error', $i18n)) ?>')" />
</div>
</div>
<div class="grow">
<div class="form-group">
<label for="username"><?= translate('username', $i18n) ?>:</label>
<input type="text" id="username" name="username" value="<?= $userData['username'] ?>"
disabled>
</div>
<div class="form-group">
<label for="email"><?= translate('email', $i18n) ?>:</label>
<input type="email" id="email" name="email" value="<?= $userData['email'] ?>" required>
</div>
<div class="form-group">
<label for="password"><?= translate('password', $i18n) ?>:</label>
<input type="password" id="password" name="password" <?= $demoMode ? 'disabled title="Not available on Demo Mode"' : '' ?>>
</div>
<div class="form-group">
<label for="confirm_password"><?= translate('confirm_password', $i18n) ?>:</label>
<input type="password" id="confirm_password" name="confirm_password" <?= $demoMode ? 'disabled title="Not available on Demo Mode"' : '' ?>>
</div>
<?php
$currencies = array();
$query = "SELECT * FROM currencies WHERE user_id = :userId";
$query = $db->prepare($query);
$query->bindValue(':userId', $userId, SQLITE3_INTEGER);
$result = $query->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$currencyId = $row['id'];
$currencies[$currencyId] = $row;
}
$userData['currency_symbol'] = "€";
?>
<div class="form-group">
<label for="currency"><?= translate('main_currency', $i18n) ?>:</label>
<select id="currency" name="main_currency" placeholder="Currency">
<?php
foreach ($currencies as $currency) {
$selected = "";
if ($currency['id'] == $userData['main_currency']) {
$selected = "selected";
$userData['currency_symbol'] = $currency['symbol'];
}
?>
<option value="<?= $currency['id'] ?>" <?= $selected ?>><?= $currency['name'] ?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label for="language"><?= translate('language', $i18n) ?>:</label>
<select id="language" name="language" placeholder="Language">
<?php
foreach ($languages as $code => $language) {
$selected = ($code === $lang) ? 'selected' : '';
?>
<option value="<?= $code ?>" <?= $selected ?>><?= $language['name'] ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="buttons">
<input type="submit" value="<?= translate('save', $i18n) ?>" id="userSubmit"
class="thin mobile-grow" />
</div>
</div>
</form>
</section>
<?php
$sql = "SELECT login_disabled FROM admin";
$stmt = $db->prepare($sql);
$result = $stmt->execute();
$row = $result->fetchArray(SQLITE3_ASSOC);
$loginDisabled = $row['login_disabled'];
$showTotpSection = true;
if ($loginDisabled && !$userData['totp_enabled']) {
$showTotpSection = false;
}
if ($showTotpSection) {
?>
<section class="account-section">
<header>
<h2><?= translate("two_factor_authentication", $i18n) ?></h2>
</header>
<div class="account-2fa">
<div class="buttons">
<?php
if (!$userData['totp_enabled']) {
?>
<input type="button" value="<?= translate('enable_two_factor_authentication', $i18n) ?>" id="enableTotp"
onClick="enableTotp()" class="button thin mobile-grow"/>
<div class="totp-popup" id="totp-popup">
<header>
<h3><?= translate('enable_two_factor_authentication', $i18n) ?></h3>
<span class="fa-solid fa-xmark close-form" onclick="closeTotpPopup()"></span>
</header>
<div class="totp-popup-content">
<div class="totp-setup" id="totp-setup">
<div class="totp-qrcode-container">
<div id="totp-qr-code"></div>
</div>
<p class="totp-secret" id="totp-secret-code"></p>
<div class="form-group-inline">
<input type="hidden" name="totp-secret" id="totp-secret" value="" />
<input type="text" id="totp" name="totp"
placeholder="<?= translate("totp_code", $i18n) ?>" />
<input type="button" value="<?= translate('enable', $i18n) ?>" id="enableTotpButton"
onClick="submitTotp()" />
</div>
</div>
<div class="totp-setup hide" id="totp-backup-codes">
<h4><?= translate('backup_codes', $i18n) ?></h4>
<ul class="totp-backup-codes" id="backup-codes"></ul>
<div class="form-group-inline wrap">
<input type="button" class="button secondary-button grow"
value="<?= translate('copy_to_clipboard', $i18n) ?>" id="copyBackupCodes"
onClick="copyBackupCodes()" />
<input type="button" class="grow"
value="<?= translate('download_backup_codes', $i18n) ?>" id="downloadBackupCodes"
onClick="downloadBackupCodes()" />
</div>
<div class="settings-notes">
<p>
<i class="fa-solid fa-circle-info"></i>
<?= translate('totp_backup_codes_info', $i18n) ?>
</p>
</div>
</div>
</div>
</div>
<?php
} else {
?>
<input type="button" class="button secondary-button thin mobile-grow"
value="<?= translate('disable_two_factor_authentication', $i18n) ?>" id="disableTotp"
onClick="disableTotp()" />
<div class="totp-popup" id="totp-disable-popup">
<header>
<h3><?= translate('disable_two_factor_authentication', $i18n) ?></h3>
<span class="fa-solid fa-xmark close-form" onclick="closeTotpDisablePopup()"></span>
</header>
<div class="totp-popup-content">
<div class="form-group-inline">
<input type="text" id="totp-disable" name="totp-disable" placeholder="totp" />
<input type="button" value="<?= translate('disable', $i18n) ?>" id="disableTotpButton"
onClick="submitDisableTotp()" />
</div>
</div>
</div>
<?php
}
?>
</div>
<div class="settings-notes">
<p>
<i class="fa-solid fa-circle-info"></i>
<?php
if (!$userData['totp_enabled']) {
echo translate('two_factor_info', $i18n);
} else {
echo translate('two_factor_enabled_info', $i18n);
}
?>
</p>
</div>
</div>
</section>
<?php
}
?>
<section class="account-section">
<header>
<h2><?= translate('api_key', $i18n) ?></h2>
</header>
<div class="account-api-key">
<div class="form-group-inline">
<input type="text" id="apikey" name="apikey" value="<?= $userData['api_key'] ?>" placeholder="API Key" readonly>
<input type="submit" value="<?= translate('regenerate', $i18n) ?>" id="regenerateApiKey" onClick="regenerateApiKey()" />
</div>
<div class="settings-notes">
<p>
<i class="fa-solid fa-circle-info"></i> <?= translate('api_key_info', $i18n) ?>
</p>
</div>
</div>
</section>
<section class="account-section">
<header>
<h2><?= translate('account', $i18n) ?></h2>
</header>
<div class="account-list">
<div>
<h3><?= translate('export_subscriptions', $i18n) ?></h3>
<div class="form-group-inline wrap">
<input type="button" value="<?= translate('export_as_json', $i18n) ?>" onClick="exportAsJson()"
class="secondary-button thin mobile-grow" id="export-json" <?= $demoMode ? 'disabled title="Not available on Demo Mode"' : '' ?>>
<input type="button" value="<?= translate('export_as_csv', $i18n) ?>" onClick="exportAsCsv()"
class="secondary-button thin mobile-grow" id="export-csv" <?= $demoMode ? 'disabled title="Not available on Demo Mode"' : '' ?>>
</div>
</div>
</div>
<div>
<?php
if ($userId != 1 && !$demoMode) {
?>
<h3><?= translate('danger_zone', $i18n) ?></h3>
<div class="form-group-inline">
<input type="button" value="<?= translate('delete_account', $i18n) ?>"
onClick="deleteAccount(<?= $userId ?>)" class="warning-button thin mobile-grow" id="delete-account">
</div>
<div class="settings-notes">
<p>
<i class="fa-solid fa-circle-info"></i>
<?= translate('delete_account_info', $i18n) ?>
</p>
</div>
<?php
}
?>
</div>
</section>
</section>
<script src="scripts/profile.js?<?= $version ?>"></script>
<script src="scripts/theme.js?<?= $version ?>"></script>
<script src="scripts/notifications.js?<?= $version ?>"></script>
<?php
require_once 'includes/footer.php';
?>