-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsignup.html
More file actions
1032 lines (945 loc) · 45.7 KB
/
signup.html
File metadata and controls
1032 lines (945 loc) · 45.7 KB
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>4SP - SIGNUP</title>
<link rel="stylesheet" href="css/style.css">
<script src="https://www.gstatic.com/firebasejs/9.6.10/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.6.10/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.6.10/firebase-firestore-compat.js"></script>
<script src="firebase-config.js"></script>
<script src="panic-key.js"></script>
<script src="url-changer.js"></script>
<style>
.auth-split-container {
background-color: #fff;
border-radius: 16px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
border: 1px solid #e0e0e0;
display: flex;
flex-wrap: wrap;
max-width: 900px;
margin: 50px auto;
overflow: hidden;
min-height: 650px;
}
.auth-col {
flex: 1;
padding: 40px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-sizing: border-box;
}
.auth-col.left-col {
position: relative;
background-color: #f8f9fa;
border-right: 1px solid #eee;
min-width: 300px;
}
.auth-col.right-col {
background-color: #fff;
}
.auth-col h2 {
font-family: 'PrimaryFont', sans-serif;
font-size: 2.2em;
color: #333;
margin-bottom: 25px;
text-align: center;
width: 100%;
}
.auth-col p {
font-family: 'SecondaryFont', sans-serif;
font-size: 1.1em;
color: #555;
line-height: 1.6;
text-align: center;
}
.auth-col form {
width: 100%;
max-width: 350px;
}
/* --- ANIMATION STYLES START --- */
.signup-step, .right-panel-content {
width: 100%;
opacity: 0;
display: none;
transition: opacity 0.4s ease-in-out;
}
.signup-step.active, .right-panel-content.active {
display: block;
opacity: 1;
}
/* --- ANIMATION STYLES END --- */
.auth-col .input-group {
margin-bottom: 20px;
}
.auth-col .input-group label {
display: block;
margin-bottom: 8px;
font-family: 'SecondaryFont', sans-serif;
color: #555;
font-size: 0.95em;
text-align: left;
}
.input-wrapper {
position: relative;
display: flex;
align-items: center;
}
.auth-col .input-group input {
width: 100%;
padding: 12px 45px 12px 15px;
border: 1px solid #ddd;
border-radius: 8px;
font-family: 'SecondaryFont', sans-serif;
font-size: 1em;
color: #333;
transition: border-color 0.3s ease;
}
.auth-col .input-group input[type="email"],
.auth-col .input-group input[type="text"] {
padding-right: 15px;
}
.auth-col .input-group input:focus {
border-color: #6720bd;
outline: none;
}
.password-toggle-btn {
position: absolute;
right: 5px;
top: 50%;
transform: translateY(-50%);
width: 32px;
height: 32px;
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 8px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
transition: background-color 0.2s;
}
.password-toggle-btn:hover {
background-color: #e0e0e0;
}
.password-toggle-btn svg {
width: 20px;
height: 20px;
color: #555;
}
.auth-col .btn-primary {
width: 100%;
max-width: 350px;
padding: 14px;
background-color: #6720bd;
color: #fff;
border: none;
border-radius: 8px;
font-family: 'PrimaryFont', sans-serif;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease, opacity 0.3s ease;
margin-top: 10px;
text-decoration: none;
display: inline-block;
text-align: center;
}
.auth-col .btn-primary:not(.btn-disabled):hover {
background-color: #5a1aa8;
transform: translateY(-2px);
}
.auth-col .btn-google {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
max-width: 350px;
padding: 12px;
background-color: #fff;
color: #333;
border: 1px solid #ccc;
border-radius: 8px;
font-family: 'PrimaryFont', sans-serif;
font-size: 1em;
cursor: pointer;
transition: background-color 0.3s ease, border-color 0.3s ease, opacity 0.3s ease;
margin-bottom: 10px;
}
.auth-col .btn-google img {
width: 20px;
height: 20px;
margin-right: 10px;
}
.auth-col .btn-google:not(.btn-disabled):hover {
background-color: #f5f5f5;
border-color: #aaa;
}
.auth-col .switch-link {
width: 100%;
max-width: 350px;
margin-top: 25px;
font-family: 'SecondaryFont', sans-serif;
color: #555;
text-align: center;
font-size: 1em;
}
.auth-col .switch-link a {
color: #6720bd;
text-decoration: none;
font-weight: bold;
transition: color 0.3s ease;
}
.auth-col .switch-link a:hover {
color: #5a1aa8;
}
.auth-col .message-area {
width: 100%;
max-width: 350px;
margin-top: 15px;
min-height: 40px;
text-align: center;
font-size: 0.9em;
}
.auth-col .error-message { color: #d9534f; }
.agreement-text {
font-family: 'SecondaryFont', sans-serif;
font-size: 0.85em !important;
color: #666;
text-align: center;
max-width: 350px;
margin-top: 5px;
margin-bottom: 15px;
line-height: 1.5 !important;
}
.agreement-text a {
color: #6720bd;
text-decoration: none;
}
.agreement-text a:hover {
text-decoration: underline;
}
.oauth-agreement-text {
font-family: 'SecondaryFont', sans-serif;
font-size: 0.8em !important;
font-style: italic;
color: #666;
text-align: center;
max-width: 350px;
margin-top: 15px;
line-height: 1.5 !important;
}
.oauth-agreement-text a {
color: #6720bd;
text-decoration: none;
}
.oauth-agreement-text a:hover {
text-decoration: underline;
}
.email-provider-warning {
font-family: 'SecondaryFont', sans-serif;
font-size: 0.8em !important;
color: #888;
text-align: left;
width: 100%;
max-width: 350px;
margin: -12px auto 15px auto;
line-height: 1.4 !important;
}
.btn-disabled {
opacity: 0.6;
cursor: not-allowed !important;
}
.back-button {
position: absolute;
top: 20px;
left: 20px;
width: 28px;
height: 28px;
background: none;
border: none;
padding: 0;
cursor: pointer;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s ease, transform 0.3s ease;
z-index: 10;
}
.back-button.visible {
opacity: 1;
visibility: visible;
}
.back-button img {
width: 100%;
height: 100%;
filter: brightness(0) invert(7%);
transition: filter 0.3s ease;
}
.back-button:hover {
transform: scale(1.1);
}
.user-stats-container {
width: 100%;
max-width: 400px;
margin-top: 20px;
text-align: left;
}
.stats-list {
list-style: none;
padding: 0;
margin: 0;
}
.stats-list li {
margin-bottom: 15px;
font-size: 1em;
color: #333;
display: flex;
align-items: center;
font-family: 'SecondaryFont', sans-serif;
border-bottom: 1px solid #f0f0f0;
padding-bottom: 15px;
}
.stats-list li:last-child {
margin-bottom: 0;
border-bottom: none;
padding-bottom: 0;
}
.stats-list li strong {
color: #6720bd;
width: 140px;
flex-shrink: 0;
}
.stats-list li span {
word-break: break-all;
color: #555;
}
.provider-success-info {
display: flex;
align-items: center;
justify-content: center;
margin: 20px auto;
padding: 15px 25px;
background-color: #f8f9fa;
border: 1px solid #eee;
border-radius: 12px;
width: 100%;
max-width: 350px;
}
.provider-success-info img {
width: 28px;
height: 28px;
margin-right: 15px;
}
.provider-success-info span {
font-family: 'SecondaryFont', sans-serif;
font-size: 1.1em;
color: #333;
font-weight: bold;
}
@media (max-width: 768px) {
.auth-split-container {
flex-direction: column;
margin: 20px;
}
.auth-col.left-col {
border-right: none;
border-bottom: 1px solid #eee;
}
}
.btn-loading {
position: relative;
color: transparent !important;
}
.btn-loading::after {
content: "";
position: absolute;
width: 16px;
height: 16px;
top: 50%;
left: 50%;
margin-left: -8px;
margin-top: -8px;
border: 2px solid #ffffff;
border-radius: 50%;
border-top-color: transparent;
animation: spin 1s linear infinite;
}
.btn-google.btn-loading::after {
border: 2px solid #555555;
border-top-color: transparent;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
</style>
</head>
<body>
<section class="hero-section dark-bg">
<div class="container">
<h1>SIGN UP FOR 4SP</h1>
</div>
</section>
<header class="main-header light-bg">
<div class="container">
<div class="logo">
<a href="index.html"><img src="images/logo-dark.png" alt="4SP Logo"></a>
</div>
<nav class="main-nav">
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="login.html">LOGIN</a></li>
</ul>
</nav>
<div class="auth-buttons">
<a href="login.html" class="btn btn-login">LOGIN</a>
<a href="signup.html" class="btn btn-signup">SIGN UP</a>
</div>
</div>
</header>
<div class="auth-split-container" id="authContainer">
<div class="auth-col left-col" id="leftCol">
<button type="button" id="backBtn" class="back-button" aria-label="Go back">
<img src="images/cross-white.png" alt="Go back">
</button>
<form id="signupForm" novalidate>
<div id="step1" class="signup-step">
<h2>Choose a Username</h2>
<div class="input-group">
<label for="signupUsername">Username</label>
<div class="input-wrapper">
<input type="text" id="signupUsername" placeholder="4-16 allowed characters" required
minlength="4" maxlength="16"
pattern="^[a-zA-Z0-9?!@#$%&\*\\-]+$"
title="Only letters, numbers, and ?!@#$%&*- are allowed.">
</div>
</div>
<button type="button" class="btn-primary" id="nextBtn">Next</button>
</div>
<div id="step2" class="signup-step">
<h2>Secure Your Account</h2>
<div class="input-group">
<label for="signupEmail">Email</label>
<div class="input-wrapper">
<input type="email" id="signupEmail" placeholder="Enter your email address" required>
</div>
</div>
<p class="email-provider-warning">
Note: Using providers other than Gmail may result in issues with email verification.
</p>
<div class="input-group">
<label for="signupPassword">Password</label>
<div class="input-wrapper">
<input type="password" id="signupPassword" placeholder="6-36 chars, A-Z, 0-9, symbol" required
minlength="6" maxlength="36"
pattern="^(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z0-9]).{6,36}$"
title="Must be 6-36 characters and include at least one uppercase letter, one number, and one special character.">
<button type="button" id="togglePassword" class="password-toggle-btn" aria-label="Toggle password visibility">
<svg class="eye-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"></path><circle cx="12" cy="12" r="3"></circle></svg>
<svg class="eye-off-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg>
</button>
</div>
</div>
<div class="input-group">
<label for="verifyPassword">Verify Password</label>
<div class="input-wrapper">
<input type="password" id="verifyPassword" placeholder="Re-enter your password" required minlength="6" maxlength="36">
<button type="button" id="toggleVerifyPassword" class="password-toggle-btn" aria-label="Toggle password visibility">
<svg class="eye-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"></path><circle cx="12" cy="12" r="3"></circle></svg>
<svg class="eye-off-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg>
</button>
</div>
</div>
<p class="agreement-text">
By creating an account, you agree to our
<a href="legal.html" target="_blank">Terms of Service</a> and
<a href="legal.html" target="_blank">Privacy Policy</a>.
</p>
<button type="submit" class="btn-primary" id="emailSignupBtn">Create Account</button>
</div>
<div id="signupMessage" class="message-area"></div>
</form>
<p class="switch-link">Already have an account? <a href="login.html">Login here</a></p>
</div>
<div class="auth-col right-col" id="rightCol">
<div id="right-panel-step1" class="right-panel-content">
<h2>Other ways to join</h2>
<p style="text-align: center; margin-bottom: 25px;">Use a trusted provider to sign up quickly.</p>
<button id="googleSignupBtn" class="btn-google">
<img src="images/google-icon.png" alt="Google Icon"> Sign up with Google
</button>
<button id="githubSignupBtn" class="btn-google">
<img src="images/github-mark.png" alt="GitHub Icon"> Sign up with GitHub
</button>
<button id="microsoftSignupBtn" class="btn-google">
<img src="images/microsoft.png" alt="Microsoft Icon"> Sign up with Microsoft
</button>
<p class="oauth-agreement-text">
By signing up with third-party providers you agree to this website's
<a href="legal.html" target="_blank">Terms of Service</a> and
<a href="legal.html" target="_blank">Privacy Policy</a>.
</p>
</div>
<div id="right-panel-step2" class="right-panel-content">
<h2>Almost There!</h2>
<p style="text-align: center;">We recommend using a trusted email provider like Gmail. Due to technical limitations with our hosting, some other providers may block our verification emails.</p>
<p style="text-align: center; margin-top: 20px;">Your password must be strong and secure to protect your account.</p>
</div>
</div>
</div>
<footer>
<div class="container">
<p>© 2025 4SP. All rights reserved.</p>
</div>
</footer>
<script>
document.addEventListener('DOMContentLoaded', () => {
const db = firebase.firestore();
const auth = firebase.auth();
const authContainer = document.getElementById('authContainer');
const leftCol = document.getElementById('leftCol');
const rightCol = document.getElementById('rightCol');
const step1 = document.getElementById('step1');
const step2 = document.getElementById('step2');
const rightPanelStep1 = document.getElementById('right-panel-step1');
const rightPanelStep2 = document.getElementById('right-panel-step2');
const backBtn = document.getElementById('backBtn');
const nextBtn = document.getElementById('nextBtn');
const emailSignupBtn = document.getElementById('emailSignupBtn');
const googleSignupBtn = document.getElementById('googleSignupBtn');
const githubSignupBtn = document.getElementById('githubSignupBtn');
const microsoftSignupBtn = document.getElementById('microsoftSignupBtn'); // New button reference
const signupForm = document.getElementById('signupForm');
const signupMessageDiv = document.getElementById('signupMessage');
const signupPasswordInput = document.getElementById('signupPassword');
const verifyPasswordInput = document.getElementById('verifyPassword');
const togglePasswordBtn = document.getElementById('togglePassword');
const toggleVerifyPasswordBtn = document.getElementById('toggleVerifyPassword');
let currentUsername = '';
const actionCodeSettings = {
url: `${window.location.protocol}//${window.location.hostname}${(window.location.port ? ':' + window.location.port: '')}/verify.html`,
handleCodeInApp: true
};
const showMessage = (text, isError = true) => {
signupMessageDiv.textContent = text;
signupMessageDiv.className = isError ? 'message-area error-message' : 'message-area success-message';
};
const setButtonLoading = (button, isLoading) => {
if (isLoading) {
button.classList.add('btn-loading');
button.disabled = true;
} else {
button.classList.remove('btn-loading');
button.disabled = false;
}
};
const setupPasswordToggle = (button, input) => {
button.addEventListener('click', () => {
const isPassword = input.type === 'password';
input.type = isPassword ? 'text' : 'password';
button.querySelector('.eye-icon').style.display = isPassword ? 'none' : 'inline';
button.querySelector('.eye-off-icon').style.display = isPassword ? 'inline' : 'none';
});
};
const checkProfanity = async (text) => {
if (!text || !text.trim()) return false;
try {
const response = await fetch(`https://www.purgomalum.com/service/containsprofanity?text=${encodeURIComponent(text)}`);
if (!response.ok) throw new Error('API request failed');
const result = await response.text();
return result.toLowerCase() === 'true';
} catch (error) {
console.error('Error calling profanity API:', error);
return false;
}
};
const isEmailBanned = async (email) => {
if (!email) return false;
try {
const doc = await db.collection('bannedEmails').doc(email.toLowerCase()).get();
return doc.exists;
} catch (error) {
console.error("Error checking for banned email:", error);
showMessage("Could not verify email. Please try again later.");
return true;
}
};
const createUserDocument = async (user, authMethod, username, explicitEmail = null) => {
const emailToStore = explicitEmail || (user && user.email) || null;
// UPDATED: Include microsoft.com as a provider with verified email
const isVerified = (authMethod === 'google' || authMethod === 'github' || authMethod === 'microsoft')
? true
: !!(user && user.emailVerified);
try {
await db.collection('users').doc(user.uid).set({
email: emailToStore,
authMethod: authMethod,
createdAt: firebase.firestore.FieldValue.serverTimestamp(),
username: username,
emailVerified: isVerified // Use the determined status
});
return true;
} catch (error) {
console.error("Error creating user document:", error);
return false;
}
};
const isUsernameTaken = async (username) => {
try {
const querySnapshot = await db.collection('users').where('username', '==', username).limit(1).get();
return !querySnapshot.empty;
} catch (error) {
console.error("Error checking username uniqueness:", error);
return true;
}
};
const goToStep = (step, isBack = false) => {
const currentStep = isBack ? 2 : 1;
const nextStep = isBack ? 1 : 2;
const currentStepEl = document.getElementById(`step${currentStep}`);
const nextStepEl = document.getElementById(`step${nextStep}`);
const currentRightPanel = document.getElementById(`right-panel-step${currentStep}`);
const nextRightPanel = document.getElementById(`right-panel-step${nextStep}`);
currentStepEl.classList.remove('active');
currentRightPanel.classList.remove('active');
setTimeout(() => {
currentStepEl.style.display = 'none';
currentRightPanel.style.display = 'none';
nextStepEl.style.display = 'block';
nextRightPanel.style.display = 'block';
setTimeout(() => {
nextStepEl.classList.add('active');
nextRightPanel.classList.add('active');
}, 20);
}, 400);
if (step === 2) {
backBtn.classList.add('visible');
} else {
backBtn.classList.remove('visible');
}
};
const showSuccessScreen = (username, email) => {
const now = new Date();
const creationDate = now.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
const creationTime = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', timeZoneName: 'short' });
const successHtmlLeft = `
<h2>Account Created!</h2>
<div class="user-stats-container">
<ul class="stats-list">
<li><strong>Username:</strong> <span>${username}</span></li>
<li><strong>Email:</strong> <span>${email}</span></li>
<li><strong>Creation Date:</strong> <span>${creationDate}</span></li>
<li><strong>Creation Time:</strong> <span>${creationTime}</span></li>
</ul>
</div>
<a href="login.html" class="btn-primary">Proceed to Login</a>`;
const successHtmlRight = `
<h2>What's Next?</h2>
<p>A verification link has been sent to your email address.</p>
<p>Please click the link in that email to activate your account. You will not be able to log in until your email is verified.</p>
<p style="margin-top: 20px; font-size: 0.9em; color: #888;">(Be sure to check your spam or junk folder if you don't see it.)</p>`;
leftCol.style.transition = 'opacity 0.4s ease-in-out';
rightCol.style.transition = 'opacity 0.4s ease-in-out';
leftCol.style.opacity = '0';
rightCol.style.opacity = '0';
setTimeout(() => {
leftCol.innerHTML = successHtmlLeft;
rightCol.innerHTML = successHtmlRight;
leftCol.style.opacity = '1';
rightCol.style.opacity = '1';
}, 400);
};
const showOAuthSuccessScreen = (username, email, providerName) => {
// Updated to include Microsoft icon path
let iconPath;
switch (providerName.toLowerCase()) {
case 'google':
iconPath = 'images/google-icon.png';
break;
case 'github':
iconPath = 'images/github-mark.png';
break;
case 'microsoft':
iconPath = 'images/microsoft.png';
break;
default:
iconPath = ''; // Fallback
}
const successHtml = `
<div class="auth-col" style="flex: 1 1 100%; text-align: center;">
<h2>Account Created Successfully!</h2>
<p style="margin-bottom: 25px;">Welcome to 4SP! Your account, linked via ${providerName}, is ready.</p>
<div class="provider-success-info">
<img src="${iconPath}" alt="${providerName} Icon">
<span>${email}</span>
</div>
<p style="margin-top: 25px;">Your username is: <strong>${username}</strong></p>
<a href="login.html" class="btn-primary" style="max-width: 400px; margin-top: 30px; padding: 18px;">Proceed to Login</a>
</div>
`;
authContainer.style.transition = 'opacity 0.4s ease-in-out';
authContainer.style.opacity = '0';
setTimeout(() => {
authContainer.innerHTML = successHtml;
authContainer.style.flexDirection = 'column';
authContainer.style.opacity = '1';
}, 400);
};
const cleanupFailedUser = async (user) => {
try {
if (user) { await user.delete(); }
await auth.signOut();
} catch (error) {
console.error('Error cleaning up failed user:', error);
try { await auth.signOut(); } catch (signOutError) { console.error('Error signing out:', signOutError); }
}
};
setupPasswordToggle(togglePasswordBtn, signupPasswordInput);
setupPasswordToggle(toggleVerifyPasswordBtn, verifyPasswordInput);
backBtn.addEventListener('click', () => { goToStep(1, true); });
nextBtn.addEventListener('click', () => {
showMessage('', false);
const usernameInput = document.getElementById('signupUsername');
const username = usernameInput.value.trim();
const usernameRegex = /^[a-zA-Z0-9?!@#$%&\*\\-]+$/;
if (username.length < 4 || username.length > 16) { showMessage('Username must be between 4 and 16 characters.'); return; }
if (!usernameRegex.test(username)) { showMessage('Username contains invalid characters.'); return; }
currentUsername = username;
goToStep(2);
const validateUsernameInBackground = async () => {
setButtonLoading(nextBtn, true);
try {
if (await checkProfanity(username)) { showMessage('Username contains inappropriate language.'); goToStep(1, true); return; }
if (await isUsernameTaken(username)) { showMessage('Username is already taken.'); goToStep(1, true); return; }
} catch (error) {
console.error('Error validating username:', error);
showMessage('Error validating username. Please try again.');
goToStep(1, true);
} finally {
setButtonLoading(nextBtn, false);
}
};
validateUsernameInBackground();
});
signupForm.addEventListener('submit', async (e) => {
e.preventDefault();
if (!step2.classList.contains('active')) return;
showMessage('', false);
const email = document.getElementById('signupEmail').value.trim();
const password = signupPasswordInput.value;
const verifyPassword = verifyPasswordInput.value;
if (password !== verifyPassword) { showMessage('Passwords do not match.'); return; }
const passwordRegex = /^(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z0-9]).{6,36}$/;
if (!passwordRegex.test(password)) { showMessage('Password must be 6-36 characters and include an uppercase letter, a number, and a special character.'); return; }
setButtonLoading(emailSignupBtn, true);
try {
if (await isEmailBanned(email)) { showMessage('This email address is not allowed to register.'); return; }
const userCredential = await auth.createUserWithEmailAndPassword(email, password);
const user = userCredential.user;
try {
await user.sendEmailVerification(actionCodeSettings);
const documentCreated = await createUserDocument(user, 'password', currentUsername, email);
if (!documentCreated) { throw new Error('Failed to create user document'); }
showSuccessScreen(currentUsername, email);
} catch (error) {
console.error('Error in post-creation steps:', error);
await cleanupFailedUser(user);
throw error;
}
} catch (error) {
console.error('Sign-up error:', error);
let message = 'Sign-up failed. Please try again.';
if (error.code === 'auth/email-already-in-use') { message = 'This email address is already in use.'; }
else if (error.code === 'auth/weak-password') { message = 'Password is too weak.'; }
else if (error.code === 'auth/invalid-email') { message = 'Please enter a valid email address.'; }
showMessage(message);
} finally {
setButtonLoading(emailSignupBtn, false);
}
});
const processOAuthResult = async (result, providerName) => {
if (!result || !result.user) {
showMessage('Authentication failed. Please try again.');
return;
}
const user = result.user;
let userEmail = user.email ||
(result.additionalUserInfo && result.additionalUserInfo.profile && (result.additionalUserInfo.profile.email || result.additionalUserInfo.profile.emailAddress));
if (!userEmail && result.credential && result.credential.accessToken && providerName === 'Google') {
try {
const accessToken = result.credential.accessToken;
const r = await fetch(`https://www.googleapis.com/oauth2/v3/userinfo?access_token=${encodeURIComponent(accessToken)}`);
if (r.ok) {
const profile = await r.json();
userEmail = profile.email || userEmail;
}
} catch (err) {
console.error('Error fetching google userinfo', err);
}
}
if (!userEmail && result.credential && result.credential.accessToken && providerName === 'GitHub') {
try {
const token = result.credential.accessToken;
const r = await fetch('https://api.github.com/user/emails', {
headers: { Authorization: 'token ' + token, Accept: 'application/vnd.github.v3+json' }
});
if (r.ok) {
const emails = await r.json();
const primary = Array.isArray(emails) && emails.find(e => e.primary && e.verified) || emails[0];
if (primary && primary.email) userEmail = primary.email;
}
} catch (err) {
console.error('Error fetching github emails', err);
}
}
if (!userEmail) {
try { await auth.signOut(); } catch(e){ /* ignore */ }
showMessage(`Could not retrieve email from ${providerName}. Please ensure you grant email permission and allow popups/cookies.`, true);
return;
}
if (await isEmailBanned(userEmail)) { await cleanupFailedUser(user); showMessage('This email address is not allowed to register.'); return; }
const isNewUser = result.additionalUserInfo && result.additionalUserInfo.isNewUser;
if (isNewUser) {
try {
let proposedUsername = user.displayName || userEmail.split('@')[0] || 'User';
proposedUsername = proposedUsername.replace(/[^a-zA-Z0-9?!@#$%&\*\\-]/g, '');
if (proposedUsername.length < 4) { proposedUsername = `User${user.uid.substring(0, 8)}`; }
else if (proposedUsername.length > 16) { proposedUsername = proposedUsername.substring(0, 16); }
if (await checkProfanity(proposedUsername)) { proposedUsername = `User${user.uid.substring(0, 8)}`; }
let finalUsername = proposedUsername;
let counter = 1;
while (await isUsernameTaken(finalUsername)) {
const suffix = `_${counter}`;
const maxBaseLength = 16 - suffix.length;
const baseUsername = proposedUsername.length > maxBaseLength ? proposedUsername.substring(0, maxBaseLength) : proposedUsername;
finalUsername = `${baseUsername}${suffix}`;
counter++;
if (counter > 1000) { finalUsername = `User${user.uid.substring(0, 12)}`; break; }
}
const documentCreated = await createUserDocument(user, providerName.toLowerCase(), finalUsername, userEmail);
if (!documentCreated) { throw new Error('Failed to create user document'); }
showOAuthSuccessScreen(finalUsername, userEmail, providerName);
} catch (error) {
console.error(`Error in ${providerName} signup post-processing:`, error);
await cleanupFailedUser(user);
throw error;
}
} else {
await auth.signOut();
showMessage(`An account with this ${providerName} email already exists. Please login instead.`);
}
};
const startOAuthPopup = async (providerName) => {
try {
let provider;
if (providerName === 'Google') {
provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('email');
provider.addScope('profile');
provider.setCustomParameters({ prompt: 'select_account' });
} else if (providerName === 'GitHub') {
provider = new firebase.auth.GithubAuthProvider();
provider.addScope('user:email');
} else if (providerName === 'Microsoft') {
provider = new firebase.auth.OAuthProvider('microsoft.com');
provider.addScope('user.read');
} else return;
const result = await auth.signInWithPopup(provider);
localStorage.removeItem('oauthRedirectInProgress');
await processOAuthResult(result, providerName);
} catch (err) {
console.error('Popup sign-in error', err);
if (err && (err.code === 'auth/popup-blocked' || err.code === 'auth/cancelled-popup-request' || err.code === 'auth/operation-not-supported-in-this-environment' || err.code === 'auth/web-storage-unsupported')) {
await startOAuthRedirectFlow(providerName);
} else {
if (err && err.code) {
if (err.code === 'auth/popup-closed-by-user') { showMessage('', false); }
else if (err.code === 'auth/network-request-failed') showMessage('Network error. Please try again.');
else showMessage(`Failed to sign up with ${providerName}. Please try again.`);
} else {
showMessage(`Failed to sign up with ${providerName}. Please try again.`);
}
}
} finally {
let button;
if (providerName === 'Google') button = googleSignupBtn;
else if (providerName === 'GitHub') button = githubSignupBtn;
else if (providerName === 'Microsoft') button = microsoftSignupBtn;
if (button) setButtonLoading(button, false);
}
};
const startOAuthRedirectFlow = async (providerName) => {
try {
localStorage.setItem('oauthRedirectInProgress', providerName);
let provider;
if (providerName === 'Google') {
provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('email');
provider.addScope('profile');
provider.setCustomParameters({ prompt: 'select_account' });
} else if (providerName === 'GitHub') {
provider = new firebase.auth.GithubAuthProvider();
provider.addScope('user:email');
} else if (providerName === 'Microsoft') {
provider = new firebase.auth.OAuthProvider('microsoft.com');
provider.addScope('user.read');
} else return;
await auth.signInWithRedirect(provider);
} catch (err) {
console.error('redirect start error', err);
showMessage('Could not start redirect sign-in. Please try again.');
}
};
const handlePendingRedirectResult = async () => {
try {
const result = await auth.getRedirectResult();
const providerName = localStorage.getItem('oauthRedirectInProgress') || (result && result.additionalUserInfo && result.additionalUserInfo.providerId && result.additionalUserInfo.providerId.split('.')[0]);
if (result && result.user) {
await processOAuthResult(result, providerName);
}
} catch (err) {
console.error('getRedirectResult error', err);
showMessage('Sign-in redirect failed. Please try again.');
} finally {
localStorage.removeItem('oauthRedirectInProgress');
}
};
googleSignupBtn.addEventListener('click', () => {
setButtonLoading(googleSignupBtn, true);
startOAuthPopup('Google');
});
githubSignupBtn.addEventListener('click', () => {
setButtonLoading(githubSignupBtn, true);
startOAuthPopup('GitHub');
});