Add login methods and route
This commit is contained in:
parent
9d8897fccc
commit
6e57b478e4
8 changed files with 87 additions and 53 deletions
2
app.js
2
app.js
|
@ -8,6 +8,7 @@ const session = require("express-session");
|
|||
const config = require("./config/config.json");
|
||||
|
||||
let indexRouter = require("./routes/index");
|
||||
const loginRouter = require("./routes/login");
|
||||
|
||||
let app = express();
|
||||
const sessionMiddleware = session({secret: config.secret});
|
||||
|
@ -35,6 +36,7 @@ app.use((req, res, next) => {
|
|||
});
|
||||
|
||||
app.use("/", indexRouter);
|
||||
app.use("/login", loginRouter);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use((req, res, next) => {
|
||||
|
|
|
@ -7,5 +7,6 @@
|
|||
"dialect": "postgres",
|
||||
"operatorsAliases": false
|
||||
},
|
||||
"secret": "keyboard cat"
|
||||
"secret": "keyboard cat",
|
||||
"passwordPrivateKey": "ecc635295f200847b79299df48e15759"
|
||||
}
|
||||
|
|
8
routes/login.js
Normal file
8
routes/login.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
let express = require("express");
|
||||
let router = express.Router();
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
res.render("login", { title: "L'ETU" });
|
||||
});
|
||||
|
||||
module.exports = router;
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = socket => {
|
||||
console.log("New connection !");
|
||||
socket.on("login", require("./login")(socket));
|
||||
socket.emit("connected");
|
||||
}
|
||||
|
|
20
sockets/login.js
Normal file
20
sockets/login.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
const modules = require("../models");
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
let user = await modules.User.findByPk(data.email);
|
||||
if (!user) {
|
||||
socket.emit("login", null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.checkPassword(data.password)) {
|
||||
socket.emit("login", null);
|
||||
return;
|
||||
}
|
||||
|
||||
socket.request.session.user = user;
|
||||
socket.request.session.save();
|
||||
socket.emit("login", user)
|
||||
}
|
||||
}
|
|
@ -1,52 +1,5 @@
|
|||
extends layout
|
||||
|
||||
block content
|
||||
div(class='row main-form')
|
||||
div(class='col s12 m8 offset-m2 signinup z-depth-5' id="signin")
|
||||
h2 Welcome back
|
||||
form
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") mail
|
||||
input(type="text" id="mail-input" class="autocomplete")
|
||||
label(for="mail-input") Email
|
||||
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") lock
|
||||
input(type="password" id="password-input" class="autocomplete")
|
||||
label(for="password-input") Password
|
||||
|
||||
input(type='submit' value='Login')
|
||||
|
||||
div(class='col s12 m8 offset-m2 signinup z-depth-5' id="signup")
|
||||
h2 Welcome
|
||||
form
|
||||
div(class="input-field col s6")
|
||||
i(class="material-icons prefix") portrait
|
||||
input(type="text" id="firstname-input" class="autocomplete")
|
||||
label(for="firstname-input") First Name
|
||||
|
||||
div(class="input-field col s6")
|
||||
input(type="text" id="lastname-input" class="autocomplete")
|
||||
label(for="lastname-input") Last Name
|
||||
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") mail
|
||||
input(type="text" id="mailreg-input" class="autocomplete")
|
||||
label(for="mailreg-input") Email
|
||||
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") lock
|
||||
input(type="password" id="passwordreg-input" class="autocomplete")
|
||||
label(for="passwordreg-input") Password
|
||||
|
||||
input(type='submit' value='Register')
|
||||
|
||||
div(class='col s12 m8 offset-m2 signinup z-depth-5' id="forgotPsw")
|
||||
h2 Forgot password
|
||||
form
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") mail
|
||||
input(type="text" id="mailforgot-input" class="autocomplete")
|
||||
label(for="mailforgot-input") Email
|
||||
|
||||
input(type='submit' value='Send email')
|
||||
h1= title
|
||||
p Welcome to #{title}
|
||||
|
|
52
views/login.pug
Normal file
52
views/login.pug
Normal file
|
@ -0,0 +1,52 @@
|
|||
extends layout
|
||||
|
||||
block content
|
||||
div(class='row main-form')
|
||||
div(class='col s12 m8 offset-m2 signinup z-depth-5' id="signin")
|
||||
h2 Welcome back
|
||||
form
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") mail
|
||||
input(type="text" id="mail-input" class="autocomplete")
|
||||
label(for="mail-input") Email
|
||||
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") lock
|
||||
input(type="password" id="password-input" class="autocomplete")
|
||||
label(for="password-input") Password
|
||||
|
||||
input(type='submit' value='Login')
|
||||
|
||||
div(class='col s12 m8 offset-m2 signinup z-depth-5' id="signup")
|
||||
h2 Welcome
|
||||
form
|
||||
div(class="input-field col s6")
|
||||
i(class="material-icons prefix") portrait
|
||||
input(type="text" id="firstname-input" class="autocomplete")
|
||||
label(for="firstname-input") First Name
|
||||
|
||||
div(class="input-field col s6")
|
||||
input(type="text" id="lastname-input" class="autocomplete")
|
||||
label(for="lastname-input") Last Name
|
||||
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") mail
|
||||
input(type="text" id="mailreg-input" class="autocomplete")
|
||||
label(for="mailreg-input") Email
|
||||
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") lock
|
||||
input(type="password" id="passwordreg-input" class="autocomplete")
|
||||
label(for="passwordreg-input") Password
|
||||
|
||||
input(type='submit' value='Register')
|
||||
|
||||
div(class='col s12 m8 offset-m2 signinup z-depth-5' id="forgotPsw")
|
||||
h2 Forgot password
|
||||
form
|
||||
div(class="input-field col s12")
|
||||
i(class="material-icons prefix") mail
|
||||
input(type="text" id="mailforgot-input" class="autocomplete")
|
||||
label(for="mailforgot-input") Email
|
||||
|
||||
input(type='submit' value='Send email')
|
|
@ -1,3 +0,0 @@
|
|||
extends layout
|
||||
|
||||
block content
|
Reference in a new issue