-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaccount.html
563 lines (496 loc) · 17.8 KB
/
account.html
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
<!DOCTYPE html>
<html lang="en">
<head>
<title>Subliminal</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="Resources/AbbstraktDog.ico">
<link rel="stylesheet" href="./styles.css">
<script src="./Other/component-registrar.js"></script>
<script src="./Other/account-options-template.js"></script>
<script src="./Other/header-template.js"></script>
<script src="./Other/login-template.js"></script>
<script src="./server.js"></script>
<script src="./account.js"></script>
<style>
body {
overflow-x: hidden;
overflow-y: scroll;
}
input, textarea {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
.role-grid {
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 8px;
}
.profile-title-container {
display: flex;
}
.profile-picture {
position: relative;
height: 200px;
width: 200px;
display: flex;
overflow: clip;
border-radius: 4px;
}
.profile-picture::before {
position: absolute;
content: "";
width: 100%;
height: 100%;
opacity: 0;
transition: .2s opacity;
background-color: rgba(0, 0, 0, 0.2);
}
.profile-picture:focus-within > button,
.profile-picture:hover > button,
.profile-picture:focus-within::before,
.profile-picture:hover::before {
opacity: 1;
}
.profile-picture > button {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: max-content;
text-align: center;
display: flex;
align-items: center;
transition: .2s opacity;
opacity: 0;
}
#profileName {
--contentWidth: 198px;
display: inline-block;
width: 198px;
}
#profileUsername {
opacity: 0.8;
font-weight: bold;
}
#profileBiography {
width: min(442px, 100%);
line-break: anywhere;
resize: none;
margin-top: 8px;
min-height: 72px;
}
#recentWorks {
display: flex;
flex-direction: column;
row-gap: 16px;
}
#followingAccounts {
width: 100%;
display: grid;
grid-template-columns: 50%;
grid-gap: 8px;
margin-bottom: 16px;
}
.profile-details {
display:flex;
column-gap:16px;
flex-direction:column;
margin-top:8px
}
.profile-aside {
flex-direction:column;
display: flex;
flex-wrap: wrap;
}
.editable {
position: relative;
background-color: transparent;
color: var(--text-colour);
border: none;
}
.editable:focus {
background-color: #001dff1c;
border: 1px solid gray;
outline: none;
border-radius: 4px;
}
.editable::after {
content: " ";
background-image: url("Resources/Edit.svg");
background-size: 16px;
position: absolute;
right: -16px;
top: -8px;
width: 16px;
height: 16px;
opacity: 0.2;
}
@media screen and (orientation:portrait) {
#followingAccounts {
grid-template-columns: 100%;
}
.profile-title-container {
flex-wrap: wrap;
}
}
</style>
</head>
<body class="headered-body">
<subliminal-header></subliminal-header>
<dialog id="profileRole" style="height: fit-content; width: 40%;" class="popup">
<h2>Your profile role:</h2>
<div class="role-grid">
<button type="button" class="popup-button" onclick="setProfileRole('writer');">Writer</button>
<button type="button" class="popup-button" onclick="setProfileRole('reader');">Reader</button>
<button type="button" class="popup-button" onclick="setProfileRole('listener');">Listener</button>
<button type="button" class="popup-button" onclick="setProfileRole('poet');">Poet</button>
<button type="button" class="popup-button" onclick="setProfileRole('critic');">Critic</button>
<button type="button" class="popup-button" onclick="setProfileRole('reviewer');">Reviewer</button>
<button type="button" class="popup-button" onclick="setProfileRole('analyser');">Analyser</button>
<button type="button" class="popup-button" onclick="setProfileRole('teacher');">Teacher</button>
<button type="button" class="popup-button" onclick="setProfileRole('student');">Student</button>
<button type="button" class="popup-button" onclick="setProfileRole('hobbyist');">Hobbyist</button>
<button type="button" class="popup-button" onclick="setProfileRole('casual');">Casual</button>
<button type="button" class="popup-button" onclick="setProfileRole('artist');">Artist</button>
</div>
<br>
<input type="text" class="popup-input" placeholder="Write your own!" maxlength="12" oninput="setProfileRole(value)">
<br>
<button type="button" class="popup-button" onclick="profileRole.close(); updateAccount('role', role)">Done</button>
<p style="opacity: 0.6;">These are for vanity purposes only, setting a certain role won't limit you from doing certain actions!</p>
</dialog>
<dialog id="accountEmail" style="height: fit-content; width: 30%;" class="popup flex-popup">
<h2>Enter your email:</h2>
<input id="accountEmailInput" type="text" class="popup-input" placeholder="example@example.com" maxlength="64" oninput="setProfileEmail(value)">
<br>
<button class="popup-button" onclick="accountEmail.close(); updateAccount('email', email)">Done</button>
</dialog>
<div class="div-centre">
<div class="profile-container">
<div class="profile-picture">
<img id="profileAvatar" src="https://user-images.githubusercontent.com/11250/39013954-f5091c3a-43e6-11e8-9cac-37cf8e8c8e4e.jpg" width="200" height="200"
ondragenter="
event.stopPropagation()
event.preventDefault()
" ondragover="
event.stopPropagation()
event.preventDefault()
this.style.outline = '4px solid var(--input-hilight)'
profilePictureButton.focus()
" ondrop="
event.stopPropagation()
event.preventDefault()
this.style.outline = 'initial'
const file = event.dataTransfer.files[0]
if (file && file.type.startsWith('image/')) updateProfilePicture(file)
" ondragleave="
event.stopPropagation()
event.preventDefault()
this.style.outline = 'initial'
">
<button type="button" id="profilePictureButton" onclick="profilePictureInput.click()">
<img src="./Resources/EditPhoto.svg" alt="Edit">
Click to change
</button>
<input type="file" id="profilePictureInput" accept="image/*" style="display: none;" onchange="
if (this.files[0]) {
updateProfilePicture(this.files[0])
}">
</div>
<div class="profile-aside">
<div class="profile-title-container">
<p class="profile-title">I'm </p>
<input id="profileName" type="text" class="profile-title editable" placeholder="Nickname"
maxlength="16" oninput="setProfileName(this.value)"
onblur="updateAccount('pen-name', profileName.value)" value="Nameless">
<p class="profile-title">, </p>
<p class="profile-title" id="profileRoleText" style="cursor: pointer;"
onmouseover="this.style.textDecoration = 'underline'" onmouseleave="this.style.textDecoration = 'none';"
onclick="profileRole.showModal()">a writer</p>
</div>
<span id="profileUsername">@username</span>
<textarea id="profileBiography" class="editable" placeholder="Click here to start writing your bio!"
maxlength="360" onblur="updateAccount('biography', profileBiography.value)"></textarea>
<div class="profile-details">
<div>🌍 <input id="profileLocation" type="text" class="editable"
onblur="updateAccount('location', profileLocation.value)"
placeholder="Planet of Earth, Milky Way" maxlength="36"></div>
<div>📌 <span id="profilePinned">Poem1, Poem2, Poem3, Poem4, Poem5</span></div>
</div>
<div id="profileBadges"></div>
</div>
</div>
<br><br>
<h2>Recent works:</h2>
<div id="recentWorks"></div>
<h2>Following:</h2>
<div id="followingAccounts"></div>
<h2>Private account info:</h2>
<hr>
<p>This stuff won't appear on your profile, it is for your eyes only!</p>
<button style="padding: 8px; margin: 4px; position: relative;" onclick="accountEmail.showModal()">
Change Email
<div class="button-tooltip">Change the primary email used for login, and allow us to notify you when a new poem is uploaded, your poem recieves some feedback, or other important updates</div>
</button>
<br><br>
<h2>Draft poems:</h2>
<div id="draftPoems">
<div class="poem-card">
<h4>London</h4>
<p class="poem-preview">I walk through each chartered street, near where the chartered thames do flow. And marks on every face I meet, marks of weakness, marks of woe.</p>
</div>
</div>
<br><br>
<hr>
<h2 style="cursor: pointer;" onclick="accountAgreement.style.display = accountAgreement.style.display == 'none' ? 'block' : 'none';">Account agreement +</h2>
<div id="accountAgreement" style="display: none;">
<h3>Privacy and Security:</h3>
<p>
Account security is a priority here. This site does not use tracking systems,
external cookies, or any methods that compromise your privacy. We never sell,
share, or process your personal information or account data with any third party.
If you believe your account has been compromised or someone else has gained access
to it, please report the issue immediately <a href="mailto:zekiahamoako@outlook.com">here</a>.
</p>
<h3>Terms of Service (TOS) and Guidelines:</h3>
<p>
This site aims to be a place for freedom of expression through the medium of poetry.
While we support and protect your creative freedom, we cannot take responsibility for
if you face penalties, legal action, or persecution from institutions, governments,
or individuals due to your work submitted here. However, we will strive to protect your
rights and works whenever possible. This includes:
</p>
<ul>
<li>Keeping your private information confidential and only accessible to you.</li>
<li>Minimizing the information at risk in the event of a data breach.</li>
<li>Enabling you to delete any data you've uploaded, in accordance with GDPR regulations.</li>
</ul>
<p>
If you use this site to publicly post illegal, NSFW (Not Safe For Work), or otherwise
morally objectionable content, your account may be suspended, and your IP address
blocked from submitting future content.
</p>
<p>
Please be aware that if you publicly post any personally identifying information on this
site, it could be used against you by others. We are not liable for any consequences that
may arise from such actions.
</p>
</div>
</div>
<a href="./contents" class="back"> <- Back</a>
</body>
<script>
let role = ""
let avatarUrl = ""
let number = ""
let email = ""
//TODO: Move all this to my custom profile template frame component
let stringToHtml = text => {
let htmlObject = document.createElement('temp')
htmlObject.innerHTML = text
return htmlObject.firstElementChild
}
function setProfileAvatar(newUrl) {
if (newUrl == null) return
avatarUrl = newUrl
profileAvatar.src = avatarUrl
}
function setProfileRole(newRole) {
if (newRole == null || newRole.length == 0) return
role = role.substring(0, 8)
role = newRole
profileRoleText.textContent = (["a", "e", "i", "o", "u"].indexOf(role[0].toLowerCase()) !== -1 ? "an " : "a ") + role
}
function setProfileEmail(newEmail) {
if (newEmail == null) return
if (!email) {
accountEmailInput.value = newEmail
}
email = newEmail
}
function setProfileName(value) {
profileName.value = value
if (value) {
profileName.style.width = "0"
profileName.style.minWidth = ""
requestAnimationFrame(() => {
profileName.style.setProperty("--contentWidth", profileName.scrollWidth + "px")
profileName.style.width = "var(--contentWidth)"
})
}
else {
// Placeholder min-width: 196px
profileName.style.minWidth = "198px"
}
}
// This method should produce:
// <div class="following-card">
// <img src="https://user-images.githubusercontent.com/11250/39013954-f5091c3a-43e6-11e8-9cac-37cf8e8c8e4e.jpg">
// <div>
// <h4>Zekiah</h4>
// <p class="poem-preview">✍️ I live in a society. This is one of the sites ever, and I write some of the poems ever. I also run this ship (to the bottom of the ocean).</p>
// </div>
// </div>
async function setProfileFollowing(newGuids) { // TODO: Move to component system
if (newGuids == null) return
while (followingAccounts.firstChild) {
followingAccounts.removeChild(followingAccounts.lastChild)
}
for (let guid of newGuids) {
let profile = await getPublicProfile(guid)
if (profile == null) continue
let el = document.createElement("div")
el.className = "following-card"
let profileImage = document.createElement("img")
profileImage.avatarUrl = profile.avatarUrl || "https://user-images.githubusercontent.com/11250/39013954-f5091c3a-43e6-11e8-9cac-37cf8e8c8e4e.jpg"
el.appendChild(profileImage)
let profileInfo = document.createElement("div")
let profileName = document.createElement("h4")
profileName.textContent = profile.penName || "Nameless"
profileInfo.appendChild(profileName)
let profileBio = document.createElement("p")
profileBio.className = "poem-preview"
profileBio.textContent = "✍️ " + profile.biography || "I have no biography, I am the unknown."
profileInfo.appendChild(profileBio)
el.appendChild(profileInfo)
followingAccounts.appendChild(el)
}
}
// This method should produce:
// <div class="poem-card">
// <h4>London</h4>
// <p class="poem-preview">I walk through each chartered street, near where the chartered thames do flow. And marks on every face I meet, marks of weakness, marks of woe.</p>
// </div>
async function setProfileRecent(newGuids) { // TODO: Move to component system
if (newGuids == null) return
while (recentWorks.firstChild) {
recentWorks.removeChild(recentWorks.lastChild)
}
for (let guid of newGuids) {
let poem = await (await fetch(serverBaseAddress + "/purgatory/" + guid)).json()
let el = document.createElement("div")
el.className = "poem-card"
let title = document.createElement("h4")
title.textContent = poem.poemName
el.appendChild(title)
let preview = document.createElement("p")
preview.textContent = poem.poemContent
el.appendChild(preview)
recentWorks.appendChild(el)
}
}
async function setProfileBadges(newBadges) {
if (newBadges == null) return
for (let badge of newBadges) {
let badgeName = Object.keys(badgeType)[badge]
let badgeElement = document.createElement("div")
badgeElement.className = "profile-badge"
let tooltip = document.createElement("div")
tooltip.className = "button-tooltip"
tooltip.textContent = getBadgeInfo(badge)
badgeElement.appendChild(tooltip)
let icon = stringToHtml(await (await fetch("./Resources/" + badgeName + "Badge.svg")).text())
icon.setAttribute("viewBox", "0 0 64 64")
icon.setAttribute("width", "32")
icon.setAttribute("height", "32")
badgeElement.appendChild(icon)
profileBadges.appendChild(badgeElement)
}
}
function confirmFail() {
if (confirm("Failed to load account profile data\nLogging out may fix such errors, proceed to logout?\nIf yes, press OK, else Cancel.")) {
localStorage.removeItem("accountCode")
localStorage.removeItem("accountGuid")
}
}
async function updateAccount(propertyPath, value) {
const response = await fetch(serverBaseAddress + "/accounts/me/" + propertyPath, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(value)
});
if (!response.ok) {
confirmFail()
return
}
}
// https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string
async function bufferToBase64(buffer) {
const base64url = await new Promise(resolve => {
const reader = new FileReader()
reader.onload = () => resolve(reader.result)
reader.readAsDataURL(new Blob([buffer]))
})
return base64url.slice(base64url.indexOf(',') + 1);
}
async function updateProfilePicture(file) {
let reader = new FileReader()
reader.onload = async function (event) {
const resultBytes = new Uint8Array(event.target.result)
let encodedResult = await bufferToBase64(resultBytes)
const res = await fetch(serverBaseAddress + "/accounts/me/avatar", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
mimeType: file.type,
data: encodedResult
})
})
if (res.ok) {
profileAvatar.src = imageUrl
}
else {
confirmFail("Failed to update profile avatar")
}
}
reader.readAsArrayBuffer(file)
const imageUrl = URL.createObjectURL(file)
}
async function initialise() {
if (!await isLoggedIn()) {
if (confirm("You don't seem to have an account here, or are not logged in. Log in now?")) {
window.location.href = window.location.origin + "/login?referrer=/account"
}
else {
history.back()
}
return
}
try {
const response = await fetch(serverBaseAddress + "/accounts/me", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
confirmFail()
return
}
const accountData = await response.json()
setProfileName(accountData.penName || "Nameless")
profileUsername.textContent = "@" + accountData.username
profileBiography.value = accountData.biography || "Click here to start writing your bio!"
profileLocation.value = accountData.location || "Planet Earth, Milky Way"
profilePinned.textContent = accountData.pinnedPoems?.length > 0 ? accountData.pinnedPoems : "Nothing pinned yet."
setProfileRole(accountData.role || "writer")
setProfileAvatar(accountData.avatarUrl
? serverBaseAddress + accountData.avatarUrl
: "https://user-images.githubusercontent.com/11250/39013954-f5091c3a-43e6-11e8-9cac-37cf8e8c8e4e.jpg")
setProfileBadges(accountData.badges || [])
setProfileFollowing(accountData.following || [])
setProfileRecent(accountData.poems || [])
}
catch (error) {
console.error("Sign-in failed:", error)
confirmFail()
}
}
initialise()
</script>
</html>