Skip to content

Commit

Permalink
Merge pull request #2 from Val-gee/valentina
Browse files Browse the repository at this point in the history
Split login and sign up portion of web application onto two different pages
  • Loading branch information
Val-gee authored Feb 17, 2024
2 parents 2b9cb3b + e972a3e commit e7b40f6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 14 Challenge: The Tech Blog
# The Tech Blog

## Description

Expand Down
11 changes: 11 additions & 0 deletions controllers/homeRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,15 @@ router.get('/login', async (req, res) => {
res.render('login');
});

router.get('/signup', async (req, res) => {
console.log(`GET /signup`);

if (req.session.logged_in) {
res.redirect('/dashboard');
return;
}

res.render('signup');
});

module.exports = router;
16 changes: 15 additions & 1 deletion public/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const loginFormHandler = async (event) => {

const signupFormHandler = async (event) => {
event.preventDefault();

const name = document.querySelector('#name-signup').value.trim();
const email = document.querySelector('#email-signup').value.trim();
const password = document.querySelector('#password-signup').value.trim();
Expand All @@ -41,6 +41,20 @@ const signupFormHandler = async (event) => {
}
};

const signUpButtonChange = async(event) => {
event.preventDefault();

console.log('switched to signup page');

const response = await fetch(`/signup`);

if (response.ok) {
document.location.replace('/signup');
}
};

document.querySelector('.sign-up').addEventListener('click', signUpButtonChange);

document.querySelector('.login-form').addEventListener('submit', loginFormHandler);

document.querySelector('.signup-form').addEventListener('submit', signupFormHandler);
31 changes: 6 additions & 25 deletions views/login.handlebars
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="row">
<div class="col-md-6">
<h2>Login</h2>
<div class="row justify-content-around">
<div class="col-md-4 border border-dark">
<h2 class="text-center">Login</h2>
<form class="form login-form">
<div class="form-group">
<label for="email-login">Email:</label>
Expand All @@ -10,28 +10,9 @@
<label for="password-login">Password:</label>
<input class="form-input" type="password" id="password-login" />
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit">Login</button>
</div>
</form>
</div>
<div class="col-md-6">
<h2>Sign up</h2>
<form class="form signup-form">
<div class="form-group">
<label for="name-signup">Name:</label>
<input class="form-input" type="text" id="name-signup" />
</div>
<div class="form-group">
<label for="email-signup">Email:</label>
<input class="form-input" type="text" id="email-signup" />
</div>
<div class="form-group">
<label for="password-signup">Password:</label>
<input class="form-input" type="password" id="password-signup" />
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit">Sign up!</button>
<div class="row justify-content-center form-group">
<button class="btn btn-dark" type="submit">Login</button>
<button class="sign-up btn btn-dark" type="click">or Sign Up</button>
</div>
</form>
</div>
Expand Down
24 changes: 24 additions & 0 deletions views/signup.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="row justify-content-around">
<div class="col-md-4 border border-dark">
<h2 class="text-center">Sign up</h2>
<form class="justify-content-center form signup-form">
<div class="form-group">
<label for="name-signup">Name:</label>
<input class="form-input" type="text" id="name-signup" />
</div>
<div class="form-group">
<label for="email-signup">Email:</label>
<input class="form-input" type="text" id="email-signup" />
</div>
<div class="form-group">
<label for="password-signup">Password:</label>
<input class="form-input" type="password" id="password-signup" />
</div>
<div class="form-group">
<button class="btn btn-dark" type="submit">Sign up!</button>
</div>
</form>
</div>
</div>

<script src="/js/login.js"></script>

0 comments on commit e7b40f6

Please sign in to comment.