Skip to content

Commit f3dcd0f

Browse files
committed
Create and login setup on all pages
1 parent 456c974 commit f3dcd0f

File tree

7 files changed

+512
-28
lines changed

7 files changed

+512
-28
lines changed

public/build.html

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@
2525
gtag('js', new Date());
2626
gtag('config', 'G-SXELHG62RJ');
2727
</script>
28-
<script language="javascript" src="js/AoE4_Overlay.js"></script>
2928
</head>
3029

3130
<body>
3231
<header>
3332
<a class="title gold" href="./">Age of Empires IV<br />Build Order Tool</a>
33+
<a href="#" class="desktop-only logged-in modal-trigger" id="account" title="Account"
34+
data-target="modal-account"><span
35+
style="font-size: 3.8rem; margin-top: -0.8rem; color: transparent; text-shadow: 0 0 0 #ffdb88;">👤</span><span
36+
class="gold">Account Details</span></a>
37+
<a href="#" class="desktop-only logged-out modal-trigger" id="signup" title="Login/Signup"
38+
data-target="modal-signup"><span
39+
style="font-size: 3.8rem; margin-top: -0.8rem; color: transparent; text-shadow: 0 0 0 white;">👤</span><span>Login
40+
or Signup</span></a>
3441
<a href="./" title="Browse through popular AoE 4 Build Order Online!"><span
3542
style="font-size: 4.8rem; margin-top: -0.8rem;">👁</span><span>Browse All Builds</span></a>
3643
<a class="desktop-only" href="https://github.com/LENpolygon/Build-Order-Tool-AoE4-"
@@ -58,6 +65,55 @@
5865
</a>
5966
</header>
6067

68+
<!-- SIGN UP/LOGIN MODAL -->
69+
<div id="modal-signup" class="modal">
70+
<div class="modal-content">
71+
<h2 class="title gold">Login</h2><br />
72+
<form id="login-form">
73+
<div class="input-field">
74+
<label>Email address</label>
75+
<input type="email" id="login-email" required />
76+
</div>
77+
<br />
78+
<div class="input-field">
79+
<label>Your password</label>
80+
<input type="password" id="login-password" required />
81+
</div>
82+
<br />
83+
<button class="btn yellow darken-2 z-depth-0">Login</button>
84+
</form>
85+
<br />
86+
<h2 class="title gold">Sign up</h2><br />
87+
<form id="signup-form">
88+
<div class="input-field">
89+
<label>Email address</label>
90+
<input type="email" id="signup-email" required />
91+
</div>
92+
<br />
93+
<div class="input-field">
94+
<label>Username</label>
95+
<input type="text" id="username" required />
96+
</div>
97+
<br />
98+
<div class="input-field">
99+
<label>Choose password</label>
100+
<input type="password" id="signup-password" required />
101+
</div>
102+
<br />
103+
<button class="btn yellow darken-2 z-depth-0">Sign up</button>
104+
</form>
105+
</div>
106+
</div>
107+
<!-- ACCOUNT MODAL -->
108+
<div id="modal-account" class="modal">
109+
<div class="modal-content center-align">
110+
<h2 class="title gold">Account details</h2><br />
111+
<div class="account-details"></div>
112+
<br />
113+
<a href="#" class="grey-text" id="logout">Logout</a>
114+
</div>
115+
</div>
116+
61117
<main>
62118
<article>
63119
<section>
@@ -133,7 +189,9 @@ <h4 class="desktop-only" style="text-align: right; margin-right: 1rem;">Unique<b
133189
<div id="tooltipBox" class="tooltipBox">
134190
</div>
135191
<script language="javascript" src="js/lz-string.min.js"></script>
192+
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
136193
<script type="module" src="js/build.js"></script>
194+
<script language="javascript" src="js/AoE4_Overlay.js"></script>
137195
</div>
138196
</body>
139197

public/css/global.css

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,23 @@ table th {
325325
background-color: #a8bbbf;
326326
}
327327

328+
button {
329+
cursor: pointer;
330+
display: inline-block;
331+
font-family: "Lucida Grande", Tahoma, Verdana, Arial, sans-serif;
332+
font-size: 1.3rem;
333+
letter-spacing: .1rem;
334+
line-height: 1.3rem;
335+
padding: .9rem 1.3rem;
336+
text-transform: uppercase;
337+
-webkit-appearance: none;
338+
border-width: 1px;
339+
border-style: solid;
340+
border-color: #ffdb88;
341+
background: #181C29;
342+
color: #ffdb88;
343+
}
344+
328345
@media screen and (max-width:800px) {
329346
html {
330347
font-size: 6.7px;
@@ -358,4 +375,61 @@ table th {
358375
.mobile-only {
359376
display: none;
360377
}
378+
}
379+
380+
.modal {
381+
-webkit-box-shadow: 0 24px 38px 3px rgba(0, 0, 0, 0.14), 0 9px 46px 8px rgba(0, 0, 0, 0.12), 0 11px 15px -7px rgba(0, 0, 0, 0.2);
382+
box-shadow: 0 24px 38px 3px rgba(0, 0, 0, 0.14), 0 9px 46px 8px rgba(0, 0, 0, 0.12), 0 11px 15px -7px rgba(0, 0, 0, 0.2)
383+
}
384+
385+
.modal {
386+
display: none;
387+
position: fixed;
388+
left: 0;
389+
right: 0;
390+
background: #2C374F;
391+
padding: 0;
392+
max-height: 70%;
393+
width: 55%;
394+
margin: auto;
395+
overflow-y: auto;
396+
border-radius: 2px;
397+
will-change: top, opacity;
398+
font-size: 1.6rem;
399+
}
400+
401+
.modal:focus {
402+
outline: none
403+
}
404+
405+
@media only screen and (max-width: 992px) {
406+
.modal {
407+
width: 80%
408+
}
409+
}
410+
411+
.modal .modal-content {
412+
padding: 24px
413+
}
414+
415+
.modal .modal-close {
416+
cursor: pointer
417+
}
418+
419+
.modal .modal-footer .btn, .modal .modal-footer .btn-large, .modal .modal-footer .btn-small, .modal .modal-footer .btn-flat {
420+
margin: 6px 0
421+
}
422+
423+
.modal-overlay {
424+
position: fixed;
425+
z-index: 999;
426+
top: -25%;
427+
left: 0;
428+
bottom: 0;
429+
right: 0;
430+
height: 125%;
431+
width: 100%;
432+
background: #000;
433+
display: none;
434+
will-change: opacity
361435
}

public/index.html

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<meta name="description" content="View, Create, and Share Build Orders for Age of Empires IV" />
1111
<meta name="author" content="LEN polygon" />
1212
<meta name="locale" content="en" />
13-
<meta name="viewport" content="width=device-width, initial-scale=1" />
13+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1414
<meta name="format-detection" content="telephone=no" />
1515
<meta name="theme-color" content="#11141D" />
1616
<link rel="icon" type="image/png" href="/assets/favicon.ico" />
@@ -30,7 +30,14 @@
3030
<body id="background">
3131
<header>
3232
<a class="title gold" href="./">Age of Empires IV<br />Build Order Tool</a>
33-
33+
<a href="#" class="desktop-only logged-in modal-trigger" id="account" title="Account"
34+
data-target="modal-account"><span
35+
style="font-size: 3.8rem; margin-top: -0.8rem; color: transparent; text-shadow: 0 0 0 #ffdb88;">👤</span><span
36+
class="gold">Account Details</span></a>
37+
<a href="#" class="desktop-only logged-out modal-trigger" id="signup" title="Login/Signup"
38+
data-target="modal-signup"><span
39+
style="font-size: 3.8rem; margin-top: -0.8rem; color: transparent; text-shadow: 0 0 0 white;">👤</span><span>Login
40+
or Signup</span></a>
3441
<a id="BOforCIV" class="gold" href="./build.html?c=" title="Create your own AoE 4 Build Order Online!"><span
3542
style="font-size: 4.5rem; margin-top: -0.8rem;"></span><span>Create New Build</span></a>
3643
<a class="desktop-only" href="https://github.com/LENpolygon/Build-Order-Tool-AoE4-"
@@ -56,6 +63,55 @@
5663
</a>
5764
</header>
5865

66+
<!-- SIGN UP/LOGIN MODAL -->
67+
<div id="modal-signup" class="modal">
68+
<div class="modal-content">
69+
<h2 class="title gold">Login</h2><br />
70+
<form id="login-form">
71+
<div class="input-field">
72+
<label>Email address</label>
73+
<input type="email" id="login-email" required />
74+
</div>
75+
<br />
76+
<div class="input-field">
77+
<label>Your password</label>
78+
<input type="password" id="login-password" required />
79+
</div>
80+
<br />
81+
<button class="btn yellow darken-2 z-depth-0">Login</button>
82+
</form>
83+
<br />
84+
<h2 class="title gold">Sign up</h2><br />
85+
<form id="signup-form">
86+
<div class="input-field">
87+
<label>Email address</label>
88+
<input type="email" id="signup-email" required />
89+
</div>
90+
<br />
91+
<div class="input-field">
92+
<label>Username</label>
93+
<input type="text" id="username" required />
94+
</div>
95+
<br />
96+
<div class="input-field">
97+
<label>Choose password</label>
98+
<input type="password" id="signup-password" required />
99+
</div>
100+
<br />
101+
<button class="btn yellow darken-2 z-depth-0">Sign up</button>
102+
</form>
103+
</div>
104+
</div>
105+
<!-- ACCOUNT MODAL -->
106+
<div id="modal-account" class="modal">
107+
<div class="modal-content center-align">
108+
<h2 class="title gold">Account details</h2><br />
109+
<div class="account-details"></div>
110+
<br />
111+
<a href="#" class="grey-text" id="logout">Logout</a>
112+
</div>
113+
</div>
114+
59115
<div id="civBox">
60116
<div class="civFlag" id="civilizationFlag">
61117
</div>
@@ -107,6 +163,7 @@ <h4 id="civilizationFocus"></h4>
107163
Age of Empires IV and all its icons, artwork, and flair are property of Relic Entertainment, World's Edge &
108164
Xbox Game Studios. This website is for educational purposes only.
109165
</footer>
166+
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
110167
<script type="module" src="js/index.js"></script>
111168
</body>
112169

public/js/build.js

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ var selectedciv = null;
1818
var buildorder = null;
1919
var buildordercolumns = 2;
2020
var usp = new URLSearchParams(window.location.search);
21-
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-app.js"; import firebaseConfig from '../json/fs.js'; const app = initializeApp(firebaseConfig); import { getFirestore, doc, getDoc, setDoc, collection, updateDoc, addDoc } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-firestore.js"; const db = getFirestore();
21+
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-app.js"; import firebaseConfig from '../json/fs.js'; const app = initializeApp(firebaseConfig);
22+
import { getFirestore, doc, getDoc, setDoc, collection, updateDoc, addDoc } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-firestore.js"; const db = getFirestore();
23+
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-auth.js"; const auth = getAuth();
2224
if (isNaN(usp.get("c"))) {
2325
for (let i = 0; i < civilizations.length; i++) {
2426
if (usp.get("c") == civilizations[i].abbr) {
@@ -62,6 +64,8 @@ for (let i = 0; i < civilizations.length; i++) {
6264
str += "><a href=\"build.html?c=" + civilizations[i].abbr + "\">✎ " + civilizations[i].civilization + "</a></li>";
6365
}
6466
str += "<li class=\"mobile-only\"><a class =\"gold\" href=\"index.html\">👁 Browse all Builds</a></li>";
67+
str += "<li class=\"mobile-only\"><a href=\"#\" class=\"logged-in modal-trigger\" data-target=\"modal-account\">👤 Your Account</a></li>";
68+
str += "<li class=\"mobile-only\"><a href=\"#\" class=\"logged-out modal-trigger\" data-target=\"modal-signup\">👤 Login / Signup</a></li>";
6569
str += "<li class=\"mobile-only\"><a href=\"https://github.com/LENpolygon/Build-Order-Tool-AoE4-\">💻 View Github Page</a></li>";
6670
str += "<li class=\"mobile-only\"><a href=\"https://ko-fi.com/lenpolygon\">💰 Support Website</a></li>";
6771
str +="<li class=\"mobile-only\"><a style=\"color: aqua;\" id=\"copyForOverlayBtnMobile\">🗗 Build to Clipboard (text)</a></li>";
@@ -523,4 +527,80 @@ document.getElementById('tooltipBox').style.display = "none";
523527
// RANDOMIZE background
524528
//////////////////////////////////////////////////
525529
//const backgroundOptions = ["02celebration", "03focuslongbowmen", "04lordrobertsb", "07raisedstakestwoknights", "10mongoltrebuchet", "11chinesetradecaravans", "12mongolscharging", "15paytributeb", "alarm"];
526-
//document.getElementById("background").style.backgroundImage = "url(img/" + backgroundOptions[Math.floor(Math.random() * backgroundOptions.length)] + ".png)";
530+
//document.getElementById("background").style.backgroundImage = "url(img/" + backgroundOptions[Math.floor(Math.random() * backgroundOptions.length)] + ".png)";
531+
532+
// signup
533+
const signupForm = document.querySelector('#signup-form');
534+
signupForm.addEventListener('submit', (e) => {
535+
e.preventDefault();
536+
// get user info
537+
const email = signupForm['signup-email'].value;
538+
const password = signupForm['signup-password'].value;
539+
// sign up the user
540+
createUserWithEmailAndPassword(auth, email, password).then(cred => {
541+
return setDoc(doc(db, "users", cred.user.uid), { user: signupForm['username'].value });
542+
}).then(() => {
543+
// console.log(cred.user);
544+
// close the signup modal & reset form
545+
const modal = document.querySelector('#modal-signup');
546+
M.Modal.getInstance(modal).close();
547+
signupForm.reset();
548+
});
549+
});
550+
551+
// logout
552+
const logout = document.querySelector('#logout');
553+
logout.addEventListener('click', (e) => {
554+
e.preventDefault();
555+
const modal = document.querySelector('#modal-account');
556+
M.Modal.getInstance(modal).close();
557+
auth.signOut();
558+
})
559+
560+
// login
561+
const loginForm = document.querySelector('#login-form');
562+
loginForm.addEventListener('submit', (e) => {
563+
e.preventDefault();
564+
// get user info
565+
const email = loginForm['login-email'].value;
566+
const password = loginForm['login-password'].value;
567+
signInWithEmailAndPassword(auth, email, password).then(cred => {
568+
// console.log(cred.user);
569+
// close the login modal & reset form
570+
const modal = document.querySelector('#modal-signup');
571+
M.Modal.getInstance(modal).close();
572+
loginForm.reset();
573+
})
574+
})
575+
576+
// listen for auth status changes
577+
auth.onAuthStateChanged(user => {
578+
console.log(user);
579+
if (user) {
580+
setupUI(user);
581+
} else {
582+
setupUI();
583+
}
584+
})
585+
586+
const loggedOutLinks = document.querySelectorAll('.logged-out');
587+
const loggedInLinks = document.querySelectorAll('.logged-in');
588+
const accountDetails = document.querySelector('.account-details');
589+
const setupUI = (user) => {
590+
if (user) {
591+
accountDetails.innerHTML = `<div>Logged in as ${user.email}</div>`;
592+
// toggle UI elements
593+
loggedInLinks.forEach(item => item.style.display = 'block');
594+
loggedOutLinks.forEach(item => item.style.display = 'none');
595+
} else {
596+
// hide account info
597+
accountDetails.innerHTML = '';
598+
loggedInLinks.forEach(item => item.style.display = 'none');
599+
loggedOutLinks.forEach(item => item.style.display = 'block');
600+
}
601+
}
602+
// setup materialize components
603+
document.addEventListener('DOMContentLoaded', function () {
604+
var modals = document.querySelectorAll('.modal');
605+
M.Modal.init(modals);
606+
});

0 commit comments

Comments
 (0)