update css and authform - stealtech, add register js and fix register backend
This commit is contained in:
parent
f39d1cdbf8
commit
d1dc1b4bf0
4 changed files with 225 additions and 147 deletions
|
@ -1,190 +1,194 @@
|
||||||
.container {
|
.container {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
background-color: var(--background-secondary);
|
background-color: var(--background-secondary);
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
width: clamp(200px, 50%, 300px);
|
width: clamp(200px, 50%, 300px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.content form {
|
.content form {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-container {
|
.auth-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
flex-direction: column;
|
||||||
align-items: center;
|
justify-content: center;
|
||||||
flex-direction: column;
|
align-items: center;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
background: linear-gradient(135deg, rgba(31 30 30 / 90%) 0%, rgba(45 45 45 / 90%) 100%);
|
background: linear-gradient(135deg, rgba(31 30 30 / 90%) 0%, rgba(45 45 45 / 90%) 100%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-logo {
|
.auth-logo {
|
||||||
margin-bottom: 2rem;
|
text-align: center;
|
||||||
text-align: center;
|
margin-bottom: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-logo h1 {
|
.auth-logo h1 {
|
||||||
font-size: 2.5rem;
|
font-size: 2.5rem;
|
||||||
font-weight: bold;
|
margin-bottom: 0.5rem;
|
||||||
color: var(--text);
|
color: var(--accent);
|
||||||
margin: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-logo p {
|
.auth-logo p {
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-card {
|
.auth-card {
|
||||||
width: 100%;
|
background-color: var(--background-secondary);
|
||||||
max-width: 400px;
|
border-radius: 8px;
|
||||||
border-radius: 8px;
|
box-shadow: var(--card-shadow);
|
||||||
box-shadow: var(--card-shadow);
|
width: 100%;
|
||||||
background-color: var(--background-secondary);
|
max-width: 400px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
animation: fade-in 0.5s ease;
|
animation: fade-in 0.5s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-header {
|
.auth-header {
|
||||||
padding: 1.5rem;
|
padding: 1.5rem;
|
||||||
background-color: rgba(0 0 0 / 10%);
|
text-align: center;
|
||||||
text-align: center;
|
border-bottom: 1px solid var(--border);
|
||||||
|
background-color: rgba(0 0 0 / 10%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-header h2 {
|
.auth-header h2 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
color: var(--text);
|
font-size: 1.5rem;
|
||||||
font-size: 1.5rem;
|
color: var(--text);
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-form {
|
.auth-form {
|
||||||
padding: 1.5rem;
|
padding: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-form form {
|
.auth-form form {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-toggle {
|
.auth-toggle {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: 1.5rem;
|
margin-top: 1.5rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: var(--text-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-footer {
|
.form-footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-top: 1rem;
|
font-size: 0.9rem;
|
||||||
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-footer a {
|
.form-footer a {
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-footer a:hover {
|
.form-footer a:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-footer label {
|
.form-footer label {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.25rem;
|
gap: 0.5rem;
|
||||||
white-space: nowrap;
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-form button {
|
.auth-form button {
|
||||||
margin-top: 1rem;
|
margin-top: 0.5rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.password-group {
|
.password-group {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.password-wrapper {
|
.password-wrapper {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.password-wrapper input {
|
.password-wrapper input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding-right: 2rem;
|
padding-right: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle-password {
|
.toggle-password {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 10px;
|
right: 12px;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
fill: var(--text-secondary);
|
fill: var(--text-secondary);
|
||||||
transition: fill 0.2s;
|
transition: fill 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle-password:hover {
|
.toggle-password:hover {
|
||||||
fill: var(--accent);
|
fill: var(--text);
|
||||||
}
|
}
|
||||||
|
|
||||||
.error-message {
|
.error-message {
|
||||||
color: var(--error);
|
color: var(--error);
|
||||||
background-color: rgb(237 66 69 / 10%);
|
background-color: rgb(237 66 69 / 10%);
|
||||||
border-left: 4px solid var(--error);
|
padding: 0.75rem;
|
||||||
padding: 0.75rem;
|
margin-bottom: 1.5rem;
|
||||||
margin-bottom: 1rem;
|
border-radius: 4px;
|
||||||
border-radius: 4px;
|
display: none;
|
||||||
display: none;
|
font-size: 0.9rem;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes fade-in {
|
@keyframes fade-in {
|
||||||
from {
|
from {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateY(-20px);
|
transform: translateY(-20px);
|
||||||
}
|
}
|
||||||
|
|
||||||
to {
|
to {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: translateY(0);
|
transform: translateY(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-link {
|
.auth-link {
|
||||||
color: #57f287;
|
color: var(--accent);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-link:hover {
|
.auth-link:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (width <= 480px) {
|
@media (width <= 480px) {
|
||||||
.auth-card {
|
.auth-card {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-logo h1 {
|
.auth-logo h1 {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const loginForm = document.getElementById("login-form");
|
const loginForm = document.getElementById("login-form");
|
||||||
|
const registerForm = document.getElementById("register-form");
|
||||||
const errorMessage = document.getElementById("error-message");
|
const errorMessage = document.getElementById("error-message");
|
||||||
const rememberMe = document.getElementById("remember-me");
|
const rememberMe = document.getElementById("remember-me");
|
||||||
const emailInput = document.getElementById("email");
|
const emailInput = document.getElementById("email");
|
||||||
|
@ -58,6 +59,64 @@ if (loginForm) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (registerForm) {
|
||||||
|
registerForm.addEventListener("submit", async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const email = emailInput?.value.trim();
|
||||||
|
const username = document.getElementById("username")?.value.trim();
|
||||||
|
const password = document.getElementById("password")?.value.trim();
|
||||||
|
const inviteCode = document.getElementById("invite-code")?.value.trim();
|
||||||
|
|
||||||
|
if (!email || !password) {
|
||||||
|
if (errorMessage) {
|
||||||
|
errorMessage.style.display = "block";
|
||||||
|
errorMessage.textContent = "Please enter email, password.";
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/auth/register", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
credentials: "same-origin",
|
||||||
|
body: JSON.stringify({
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
invite: inviteCode,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.success) {
|
||||||
|
window.location.href = "/";
|
||||||
|
} else {
|
||||||
|
if (errorMessage) {
|
||||||
|
errorMessage.style.display = "block";
|
||||||
|
|
||||||
|
if (Array.isArray(data.errors)) {
|
||||||
|
errorMessage.innerHTML = data.errors
|
||||||
|
.map((err) => `<p>${err}</p>`)
|
||||||
|
.join("");
|
||||||
|
} else {
|
||||||
|
errorMessage.textContent =
|
||||||
|
data.error ||
|
||||||
|
"An error occurred. Please try again.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Register error:", error);
|
||||||
|
if (errorMessage) {
|
||||||
|
errorMessage.style.display = "block";
|
||||||
|
errorMessage.textContent =
|
||||||
|
"An error occurred. Please try again.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const passwordInput = document.getElementById("password");
|
const passwordInput = document.getElementById("password");
|
||||||
|
|
|
@ -73,9 +73,13 @@ async function handler(
|
||||||
?.count,
|
?.count,
|
||||||
) === 0;
|
) === 0;
|
||||||
|
|
||||||
|
let inviteValid: boolean = true;
|
||||||
if (!firstUser && invite) {
|
if (!firstUser && invite) {
|
||||||
const inviteValidation: { valid: boolean; error?: string } =
|
const inviteValidation: { valid: boolean; error?: string } =
|
||||||
isValidInvite(invite);
|
isValidInvite(invite);
|
||||||
|
|
||||||
|
inviteValid = inviteValidation.valid;
|
||||||
|
|
||||||
if (!inviteValidation.valid && inviteValidation.error) {
|
if (!inviteValidation.valid && inviteValidation.error) {
|
||||||
errors.push(inviteValidation.error);
|
errors.push(inviteValidation.error);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +107,7 @@ async function handler(
|
||||||
errors.push("Username or email already exists");
|
errors.push("Username or email already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invite && !firstUser) {
|
if (invite && inviteValid && !firstUser) {
|
||||||
[inviteData] =
|
[inviteData] =
|
||||||
await reservation`SELECT * FROM invites WHERE id = ${invite};`;
|
await reservation`SELECT * FROM invites WHERE id = ${invite};`;
|
||||||
|
|
||||||
|
|
|
@ -1,49 +1,60 @@
|
||||||
<div class="auth-form">
|
<div class="auth-form">
|
||||||
<div class="error-message" id="error-message">
|
<div class="error-message" id="error-message">
|
||||||
<%= pageType === "register" ? "Registration failed. Please try again." : "Invalid email or password. Please try again." %>
|
<%= pageType==="register" ? "Registration failed. Please try again."
|
||||||
</div>
|
: "Invalid email or password. Please try again." %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form id="<%= pageType === "register" ? "register-form" : "login-form" %>" class="form">
|
<form id="<%= pageType === "register" ? "register-form" : "login-form" %>" class="form">
|
||||||
<% if (pageType === "register") { %>
|
<% if (pageType==="register") { %>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="username">Username</label>
|
<label for="username">Username</label>
|
||||||
<input type="text" name="username" id="username" required placeholder="Enter your username">
|
<input type="text" name="username" id="username" required placeholder="Enter your username">
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<% if (requires_invite === true) { %>
|
||||||
<label for="email">Email</label>
|
<div class="form-group">
|
||||||
<input type="email" name="email" id="email" required placeholder="Enter your email">
|
<label for="invite">Invite Code</label>
|
||||||
</div>
|
<input type="text" name="invite" id="invite-code" required placeholder="Enter your invite code">
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<div class="form-group password-group">
|
<div class="form-group">
|
||||||
<label for="password">Password</label>
|
<label for="email">Email</label>
|
||||||
<div class="password-wrapper">
|
<input type="email" name="email" id="email" required placeholder="Enter your email">
|
||||||
<input type="password" name="password" id="password" required placeholder="Enter your password">
|
</div>
|
||||||
<svg id="toggle-password" class="toggle-password" viewBox="0 0 24 24">
|
|
||||||
<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zm0 13c-3.03 0-5.5-2.47-5.5-5.5s2.47-5.5 5.5-5.5 5.5 2.47 5.5 5.5-2.47 5.5-5.5 5.5zm0-9a3.5 3.5 0 100 7 3.5 3.5 0 000-7z"/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<% if (pageType !== "register") { %>
|
<div class="form-group password-group">
|
||||||
<div class="form-footer">
|
<label for="password">Password</label>
|
||||||
<label>
|
<div class="password-wrapper">
|
||||||
<input type="checkbox" name="remember" id="remember-me">Remember me
|
<input type="password" name="password" id="password" required placeholder="Enter your password">
|
||||||
</label>
|
<svg id="toggle-password" class="toggle-password" viewBox="0 0 24 24">
|
||||||
<a href="/auth/forgot-password">Forgot password?</a>
|
<path
|
||||||
</div>
|
d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zm0 13c-3.03 0-5.5-2.47-5.5-5.5s2.47-5.5 5.5-5.5 5.5 2.47 5.5 5.5-2.47 5.5-5.5 5.5zm0-9a3.5 3.5 0 100 7 3.5 3.5 0 000-7z" />
|
||||||
<% } %>
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button type="submit"><%= pageType === "register" ? "Register" : "Login" %></button>
|
<% if (pageType !=="register" ) { %>
|
||||||
</form>
|
<div class="form-footer">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="remember" id="remember-me">Remember me
|
||||||
|
</label>
|
||||||
|
<a href="/auth/forgot-password">Forgot password?</a>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<div class="auth-toggle">
|
<button type="submit">
|
||||||
<p>
|
<%= pageType==="register" ? "Register" : "Login" %>
|
||||||
<%= pageType === "register" ? "Already have an account?" : "Don't have an account?" %>
|
</button>
|
||||||
<a href="<%= pageType === 'register' ? '/auth/login' : '/auth/register' %>" class="auth-link">
|
</form>
|
||||||
<%= pageType === "register" ? "Login" : "Register" %>
|
|
||||||
</a>
|
<div class="auth-toggle">
|
||||||
</p>
|
<p>
|
||||||
</div>
|
<%= pageType==="register" ? "Already have an account?" : "Don't have an account?" %>
|
||||||
|
<a href="<%= pageType === 'register' ? '/auth/login' : '/auth/register' %>" class="auth-link">
|
||||||
|
<%= pageType==="register" ? "Login" : "Register" %>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue