commit
627196254a
13 changed files with 54 additions and 13 deletions
|
@ -7,12 +7,16 @@ document.getElementById("login").addEventListener("submit", e=>{
|
||||||
let email = document.getElementById("mail-input").value;
|
let email = document.getElementById("mail-input").value;
|
||||||
let passw = document.getElementById("password-input").value;
|
let passw = document.getElementById("password-input").value;
|
||||||
socket.emit("login", {"email":email,"password":passw});
|
socket.emit("login", {"email":email,"password":passw});
|
||||||
|
}else{
|
||||||
|
alert('Format d\'email incorrect.');
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on("login", data=>{
|
socket.on("login", data=>{
|
||||||
if(data){
|
if(data.error){
|
||||||
|
alert(data.error.message);
|
||||||
|
}else{
|
||||||
window.location.href = "/";
|
window.location.href = "/";
|
||||||
}
|
}
|
||||||
})
|
})
|
21
public/javascripts/main.js
Normal file
21
public/javascripts/main.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
let socket = io.connect();
|
||||||
|
/*
|
||||||
|
Front-end Event
|
||||||
|
*/
|
||||||
|
// Disconnect
|
||||||
|
document.getElementById("logout").addEventListener("click", function() {
|
||||||
|
socket.emit("logout")
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Socket Actions
|
||||||
|
*/
|
||||||
|
// Disconnect
|
||||||
|
socket.on("logout", data=>{
|
||||||
|
if(data.error){
|
||||||
|
alert(data.error.message);
|
||||||
|
}else{
|
||||||
|
window.location.href = "/";
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,4 +1,4 @@
|
||||||
//let socket = io.connect();
|
let socket = io.connect();
|
||||||
|
|
||||||
document.getElementById("register").addEventListener("submit", e=>{
|
document.getElementById("register").addEventListener("submit", e=>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -15,7 +15,9 @@ document.getElementById("register").addEventListener("submit", e=>{
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("register", data=>{
|
socket.on("register", data=>{
|
||||||
if(data){
|
if(data.error){
|
||||||
|
alert(data.error.message);
|
||||||
|
}else{
|
||||||
window.location.href = "/";
|
window.location.href = "/";
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
let express = require("express");
|
let express = require("express");
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
const sessionCheck = require("./utils/sessionCheck");
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
router.get("/",sessionCheck(-1), (req, res) => {
|
||||||
res.render("pages/register", { title: "L'ETU" });
|
res.render("pages/register", { title: "L'ETU" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module.exports = (req, res, message, status, subMessage) => {
|
module.exports = (req, res, message, status, subMessage) => {
|
||||||
res.status(status || 500);
|
res.status(status || 500);
|
||||||
res.render("error", {message: message, error: {status: subMessage || undefined}});
|
res.render("template/error", {message: message, error: {status: subMessage || undefined}});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module.exports = socket => {
|
module.exports = socket => {
|
||||||
console.log("New connection !");
|
console.log("New connection !");
|
||||||
|
console.log(socket.request.session.user);
|
||||||
if (!socket.request.session.user) {
|
if (!socket.request.session.user) {
|
||||||
socket.on("login", require("./login")(socket));
|
socket.on("login", require("./login")(socket));
|
||||||
socket.on("register", require("./register")(socket));
|
socket.on("register", require("./register")(socket));
|
||||||
|
@ -8,6 +9,7 @@ module.exports = socket => {
|
||||||
socket.on("setPassword", require("./email/setPassword")(socket));
|
socket.on("setPassword", require("./email/setPassword")(socket));
|
||||||
} else {
|
} else {
|
||||||
socket.on("profileEdit", require("./profile/edit")(socket));
|
socket.on("profileEdit", require("./profile/edit")(socket));
|
||||||
|
socket.on("logout", require("./logout")(socket));
|
||||||
}
|
}
|
||||||
socket.emit("connected");
|
socket.emit("connected");
|
||||||
}
|
}
|
||||||
|
|
10
sockets/logout.js
Normal file
10
sockets/logout.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
module.exports = socket => {
|
||||||
|
return async (data) => {
|
||||||
|
if(socket.request.session.user){
|
||||||
|
socket.request.session.destroy();
|
||||||
|
socket.emit("logout", true);
|
||||||
|
}else{
|
||||||
|
socket.emit("logout", {error: { message: "not_logged_in"}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ const models = require("../../models");
|
||||||
|
|
||||||
module.exports = socket => {
|
module.exports = socket => {
|
||||||
return async (data) => {
|
return async (data) => {
|
||||||
let user = await models.User.findByPk(data.email);
|
let user = await models.User.findByPk(socket.request.session.user.email);
|
||||||
if (!user)
|
if (!user)
|
||||||
socket.emit("profileEdit", {error: {message: "not_found"}});
|
socket.emit("profileEdit", {error: {message: "not_found"}});
|
||||||
else if (!user.checkPassword(data.oldPassword))
|
else if (!user.checkPassword(data.oldPassword))
|
||||||
|
|
|
@ -22,7 +22,7 @@ html
|
||||||
label(for="password-input") Password
|
label(for="password-input") Password
|
||||||
|
|
||||||
input(type='submit' value='Login')
|
input(type='submit' value='Login')
|
||||||
button(class="notregister") Not registered ?
|
a(class="notregister" href="register") Not registered ?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ html
|
||||||
label(for="passwordreg-input") Password
|
label(for="passwordreg-input") Password
|
||||||
|
|
||||||
input(type='submit' value='Register')
|
input(type='submit' value='Register')
|
||||||
button(class="alreadyregister") Already registered ?
|
a(class="alreadyregister" href="login") Already registered ?
|
||||||
|
|
||||||
script(src="/javascripts/register.js")
|
script(src="/javascripts/register.js")
|
||||||
script(src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js")
|
script(src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js")
|
|
@ -15,4 +15,5 @@ html
|
||||||
block navbar
|
block navbar
|
||||||
div(class="col s10" id="main")
|
div(class="col s10" id="main")
|
||||||
block content
|
block content
|
||||||
|
script(src="/javascripts/main.js")
|
||||||
script(src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js")
|
script(src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js")
|
||||||
|
|
|
@ -5,15 +5,15 @@ block navbar
|
||||||
div(id="navprofile" class="student")
|
div(id="navprofile" class="student")
|
||||||
p Kezel Benoit
|
p Kezel Benoit
|
||||||
p G4S3
|
p G4S3
|
||||||
a Logout
|
a(id="logout") Logout
|
||||||
if teacher === true
|
if teacher === true
|
||||||
div(id="navprofile" class="teacher")
|
div(id="navprofile" class="teacher")
|
||||||
p Kezel Benoit
|
p Kezel Benoit
|
||||||
a Logout
|
a(id="logout") Logout
|
||||||
if admin === true
|
if admin === true
|
||||||
div(id="navprofile" class="admin")
|
div(id="navprofile" class="admin")
|
||||||
p Kezel Benoit
|
p Kezel Benoit
|
||||||
a Logout
|
a(id="logout") Logout
|
||||||
|
|
||||||
div(id="navtop")
|
div(id="navtop")
|
||||||
ul
|
ul
|
||||||
|
|
Reference in a new issue