
- Updated `.env` and `.env.test` files to include PostgreSQL connection settings and Redis configuration. - Migrated database from SQLite to PostgreSQL, updating relevant queries and connection logic. - Enhanced error handling and logging throughout the application. - Added new test utilities for PostgreSQL integration and updated user model methods. - Introduced new routes for user authentication and form management, ensuring compatibility with the new database structure. - Created login and registration views in EJS for user interaction.
239 lines
7.4 KiB
Plaintext
239 lines
7.4 KiB
Plaintext
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Login - Formies</title>
|
|
<style>
|
|
body {
|
|
font-family: sans-serif;
|
|
margin: 0;
|
|
background-color: #f4f7f6;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.navbar {
|
|
background-color: #333;
|
|
color: white;
|
|
padding: 1rem;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
.navbar a {
|
|
color: white;
|
|
text-decoration: none;
|
|
}
|
|
.navbar .logo {
|
|
font-size: 1.5rem;
|
|
font-weight: bold;
|
|
}
|
|
.container {
|
|
flex: 1;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
padding: 2rem;
|
|
}
|
|
.login-card {
|
|
background-color: white;
|
|
padding: 2rem;
|
|
border-radius: 0.5rem;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
width: 100%;
|
|
max-width: 400px;
|
|
}
|
|
.login-header {
|
|
text-align: center;
|
|
margin-bottom: 2rem;
|
|
}
|
|
.login-header h1 {
|
|
margin: 0;
|
|
color: #333;
|
|
font-size: 1.8rem;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 0.5rem;
|
|
color: #555;
|
|
}
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 0.75rem;
|
|
border: 1px solid #ddd;
|
|
border-radius: 0.25rem;
|
|
font-size: 1rem;
|
|
box-sizing: border-box;
|
|
}
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: #007bff;
|
|
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
|
|
}
|
|
.btn {
|
|
background-color: #007bff;
|
|
color: white;
|
|
padding: 0.75rem 1.5rem;
|
|
border: none;
|
|
border-radius: 0.25rem;
|
|
font-size: 1rem;
|
|
cursor: pointer;
|
|
width: 100%;
|
|
transition: background-color 0.2s;
|
|
}
|
|
.btn:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
.error-message {
|
|
background-color: #f8d7da;
|
|
color: #721c24;
|
|
padding: 0.75rem;
|
|
border-radius: 0.25rem;
|
|
margin-bottom: 1rem;
|
|
text-align: center;
|
|
}
|
|
.success-message {
|
|
background-color: #d4edda;
|
|
color: #155724;
|
|
padding: 0.75rem;
|
|
border-radius: 0.25rem;
|
|
margin-bottom: 1rem;
|
|
text-align: center;
|
|
}
|
|
.links {
|
|
text-align: center;
|
|
margin-top: 1rem;
|
|
}
|
|
.links a {
|
|
color: #007bff;
|
|
text-decoration: none;
|
|
font-size: 0.9rem;
|
|
}
|
|
.links a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<nav class="navbar">
|
|
<div class="logo"><a href="/">Formies</a></div>
|
|
<div>
|
|
<a href="/register">Register</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container">
|
|
<div class="login-card">
|
|
<div class="login-header">
|
|
<h1>Welcome Back</h1>
|
|
<p>Please sign in to continue</p>
|
|
</div>
|
|
|
|
<% if (typeof error !== 'undefined' && error) { %>
|
|
<div class="error-message"><%= error %></div>
|
|
<% } %>
|
|
|
|
<% if (typeof success !== 'undefined' && success) { %>
|
|
<div class="success-message"><%= success %></div>
|
|
<% } %>
|
|
|
|
<form action="/api/auth/login" method="POST">
|
|
<div class="form-group">
|
|
<label for="email">Email Address</label>
|
|
<input
|
|
type="email"
|
|
id="email"
|
|
name="email"
|
|
required
|
|
placeholder="Enter your email"
|
|
value="<%= typeof email !== 'undefined' ? email : '' %>"
|
|
/>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input
|
|
type="password"
|
|
id="password"
|
|
name="password"
|
|
required
|
|
placeholder="Enter your password"
|
|
/>
|
|
</div>
|
|
|
|
<button type="submit" class="btn">Sign In</button>
|
|
|
|
<div class="links">
|
|
<a href="/forgot-password">Forgot your password?</a>
|
|
<br>
|
|
<a href="/register">Don't have an account? Register</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.querySelector('form').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const email = document.getElementById('email').value;
|
|
const password = document.getElementById('password').value;
|
|
|
|
try {
|
|
const response = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ email, password })
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
// Store tokens
|
|
localStorage.setItem('accessToken', data.data.accessToken);
|
|
localStorage.setItem('refreshToken', data.data.refreshToken);
|
|
|
|
// Redirect to dashboard
|
|
window.location.href = '/dashboard';
|
|
} else {
|
|
// Show error message
|
|
const errorDiv = document.createElement('div');
|
|
errorDiv.className = 'error-message';
|
|
errorDiv.textContent = data.message || 'Login failed';
|
|
|
|
const existingError = document.querySelector('.error-message');
|
|
if (existingError) {
|
|
existingError.remove();
|
|
}
|
|
|
|
document.querySelector('.login-card').insertBefore(
|
|
errorDiv,
|
|
document.querySelector('form')
|
|
);
|
|
}
|
|
} catch (error) {
|
|
console.error('Login error:', error);
|
|
const errorDiv = document.createElement('div');
|
|
errorDiv.className = 'error-message';
|
|
errorDiv.textContent = 'An error occurred. Please try again.';
|
|
|
|
const existingError = document.querySelector('.error-message');
|
|
if (existingError) {
|
|
existingError.remove();
|
|
}
|
|
|
|
document.querySelector('.login-card').insertBefore(
|
|
errorDiv,
|
|
document.querySelector('form')
|
|
);
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |