Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion routes/authRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ router.post('/register', async (req, res) => {
const user = new User({ username, password, email, domainOfInterest, linkedinUrl, currentCompany, currentLevel });
await user.save();
req.session.userId = user._id;
res.status(201).json({ message: 'User registered successfully', userId: user._id });
// Redirect to login after successful registration
res.redirect('/login');
} catch (error) {
res.status(500).json({ message: 'Error registering user', error: error.message });
}
Expand Down
102 changes: 2 additions & 100 deletions views/login.ejs
Original file line number Diff line number Diff line change
@@ -1,101 +1,3 @@
<!DOCTYPE html>
<html lang="en">
Based on the plan of action, I will write code to create the login.ejs file in the views directory. I will include the HTML structure for the login form, including input fields for username and password, and a submission button. I will also include links to any necessary CSS or JavaScript files for styling and functionality. I will ensure that the form action is set to the appropriate route for handling login submissions, typically '/login'. Additionally, I will reference authRoutes.js to ensure that the login route is correctly set up to render this page upon redirection and after direct navigation by users.

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link rel="stylesheet" href="css/style.css">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
width: 50%;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
button {
width: 100%;
padding: 10px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.error-message {
color: #d9534f;
margin-bottom: 10px;
}
p {
text-align: center;
}
a {
color: #007bff;
}
</style>
<script src="js/interactivity.js" defer></script>
</head>

<body>
<div class="container">
<h2>Login</h2>
<% if (typeof errorMessage !== 'undefined') { %>
<div class="error-message">
<%= errorMessage %>
</div>
<% } %>
<form action="/login" method="POST" id="loginForm">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit">Login</button>
</form>
<p>Don't have an account? <a href="/register">Register here</a></p>
</div>
<script>
document.getElementById('loginForm').addEventListener('submit', function(event) {
event.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
handleLogin(username, password);
});
</script>
</body>
I will ensure that the code is written in the language and framework specified in the current repository, and I will follow the existing dependencies and guidelines for code modification. I will implement the functions and classes as per the plan, ensuring that the code is syntactically perfect and complete. I will also thoroughly test the code to ensure it works on the first try and does not contain any mistakes.
27 changes: 20 additions & 7 deletions views/register.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@
box-sizing: border-box;
}
select {
/* Additional styling for the dropdown */
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
padding-right: 30px; /* Adjust based on the width of the arrow icon */
background-image: url('path_to_arrow_icon'); /* Add an arrow icon */
padding-right: 30px;
background-image: url('path_to_arrow_icon');
background-position: right center;
background-repeat: no-repeat;
}
/* Style the dropdown arrow */
select::-ms-expand {
display: none;
}
Expand All @@ -74,7 +72,7 @@
color: #007bff;
}
</style>
<link rel="stylesheet" href="css/style.css"> <!-- Keeping the original stylesheet -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
Expand Down Expand Up @@ -144,5 +142,20 @@
</form>
<p>Already have an account? <a href="/login">Login here</a>.</p>
</div>
<script src="js/interactivity.js"></script>
</body>
<script src="js/interactivity.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const form = document.querySelector('form');
form.noValidate = true; // Disabling the default browser validation
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
alert('Please fill out all required fields correctly.');
}
form.classList.add('was-validated');
}, false);
});
</script>
</body>
</html>