mirror of
https://github.com/Dkunk7/crafters-coven.git
synced 2025-12-10 11:05:53 -06:00
added login/logout functionality, i think
This commit is contained in:
parent
0e4f54c96c
commit
0a40c0fe49
0
public/javascript/add-note.js
Normal file
0
public/javascript/add-note.js
Normal file
0
public/javascript/comment.js
Normal file
0
public/javascript/comment.js
Normal file
0
public/javascript/delete-note.js
Normal file
0
public/javascript/delete-note.js
Normal file
0
public/javascript/edit-note.js
Normal file
0
public/javascript/edit-note.js
Normal file
52
public/javascript/login.js
Normal file
52
public/javascript/login.js
Normal file
@ -0,0 +1,52 @@
|
||||
async function signupFormHandler(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// Double check these HTML values
|
||||
const username = document.querySelector(`#username-signup`).nodeValue.trim();
|
||||
const email = document.querySelector(`#email-signup`).nodeValue.trim();
|
||||
const password = document.querySelector(`#password-signup`).nodeValue.trim();
|
||||
|
||||
if (username && email && password) {
|
||||
const response = await fetch(`/api/users`, {
|
||||
method: 'post',
|
||||
body: JSON.stringify({
|
||||
username,
|
||||
email,
|
||||
password
|
||||
}),
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
console.log(`account created`);
|
||||
} else {
|
||||
alert(response.statusText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function loginFormHandler(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// Double check these HTML values
|
||||
const email = document.querySelector(`#email-login`).value.trim();
|
||||
const password = document.querySelector(`#password-login`).value.trim();
|
||||
|
||||
if (email && password) {
|
||||
const response = await fetch(`/api/users/login`, {
|
||||
method: 'post',
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
password
|
||||
}),
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
// Am I sticking with dashboard for this????
|
||||
document.location.replace(`/dashboard`);
|
||||
} else {
|
||||
alert(response.statusText);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
public/javascript/logout.js
Normal file
15
public/javascript/logout.js
Normal file
@ -0,0 +1,15 @@
|
||||
async function logout() {
|
||||
const response = await fetch(`api/users/logout`, {
|
||||
method: 'post',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
document.location.replace(`/`);
|
||||
} else {
|
||||
alert(response.statusText);
|
||||
}
|
||||
}
|
||||
|
||||
// Double check that #logout is actually the right name
|
||||
document.querySelector(`#logout`).addEventListener(`click`, logout);
|
||||
@ -13,7 +13,7 @@ const hbs = exphbs.create();
|
||||
const SequelizeStore = require(`connect-session-sequelize`)(session.Store);
|
||||
|
||||
const sess = {
|
||||
secret: 'CHANGE THIS AT SOME POINT to process.env.PORT and, ya know, do that.',
|
||||
secret: 'CHANGE THIS AT SOME POINT to process.env.DB_SECRET and, ya know, do that.',
|
||||
cookie: {},
|
||||
resave: false,
|
||||
saveUninitialized: true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user