From fdfbcceb010b47ece96560a36e142d0ee9dd9a7a Mon Sep 17 00:00:00 2001 From: flifloo Date: Sat, 12 Dec 2020 18:20:02 +0100 Subject: [PATCH 1/2] Fix semicolons --- app.js | 4 ++-- models/user.js | 2 +- public/javascripts/login.js | 4 ++-- public/javascripts/main.js | 2 +- public/javascripts/profil.js | 2 +- public/javascripts/register.js | 2 +- sockets/email/checkResend.js | 2 +- sockets/email/forgotPassword.js | 2 +- sockets/email/setPassword.js | 4 ++-- sockets/login.js | 2 +- sockets/logout.js | 2 +- sockets/profile/edit.js | 6 +++--- sockets/register.js | 2 +- sockets/utils/emailPassword.js | 2 +- test/test-pages.js | 2 +- views/template/layout.pug | 6 +++--- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app.js b/app.js index 5d204c4..caba270 100644 --- a/app.js +++ b/app.js @@ -12,8 +12,8 @@ const edtRouter = require("./routes/edt"); const homeRouter = require("./routes/home"); const marksRouter = require("./routes/marks"); const registerRouter = require("./routes/register"); -const viescolRouter = require("./routes/viescol") -const profilRouter = require("./routes/profil") +const viescolRouter = require("./routes/viescol"); +const profilRouter = require("./routes/profil"); let app = express(); const sessionMiddleware = session({ diff --git a/models/user.js b/models/user.js index 5847790..6868932 100644 --- a/models/user.js +++ b/models/user.js @@ -19,7 +19,7 @@ module.exports = (sequelize, DataTypes) => { class User extends Model { static associate(models) { User.belongsToMany(models.Group, {through: "UserGroup"}); - User.belongsToMany(models.Event, {through: "EventTeacher"}) + User.belongsToMany(models.Event, {through: "EventTeacher"}); User.belongsToMany(models.UE, {through: "UEUser"}); } diff --git a/public/javascripts/login.js b/public/javascripts/login.js index ece14e1..1f04c1b 100644 --- a/public/javascripts/login.js +++ b/public/javascripts/login.js @@ -11,7 +11,7 @@ document.getElementById("login").addEventListener("submit", e=>{ alert('Format d\'email incorrect.'); } return false; -}) +}); socket.on("login", data=>{ if(data.error){ @@ -19,4 +19,4 @@ socket.on("login", data=>{ }else{ window.location.href = "/"; } -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/public/javascripts/main.js b/public/javascripts/main.js index 20b1d66..74ddccb 100644 --- a/public/javascripts/main.js +++ b/public/javascripts/main.js @@ -18,7 +18,7 @@ socket.on("logout", data=>{ }else{ window.location.href = "/"; } -}) +}); function profilRedirect(){ diff --git a/public/javascripts/profil.js b/public/javascripts/profil.js index c2c044b..3d2b7f8 100644 --- a/public/javascripts/profil.js +++ b/public/javascripts/profil.js @@ -18,4 +18,4 @@ socket.on("profileEdit", data=>{ }else{ window.location.href = "/"; } -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/public/javascripts/register.js b/public/javascripts/register.js index 3b5833a..aad9acf 100644 --- a/public/javascripts/register.js +++ b/public/javascripts/register.js @@ -20,4 +20,4 @@ socket.on("register", data=>{ }else{ window.location.href = "/"; } -}) +}); diff --git a/sockets/email/checkResend.js b/sockets/email/checkResend.js index 07d85c5..d0de62a 100644 --- a/sockets/email/checkResend.js +++ b/sockets/email/checkResend.js @@ -11,4 +11,4 @@ module.exports = socket => { else await emailCheck(socket, user, null); } -} +}; diff --git a/sockets/email/forgotPassword.js b/sockets/email/forgotPassword.js index d415c15..b13bccc 100644 --- a/sockets/email/forgotPassword.js +++ b/sockets/email/forgotPassword.js @@ -10,4 +10,4 @@ module.exports = socket => { else await emailPassword(socket, user, null); } -} +}; diff --git a/sockets/email/setPassword.js b/sockets/email/setPassword.js index 809de18..7c3399a 100644 --- a/sockets/email/setPassword.js +++ b/sockets/email/setPassword.js @@ -5,7 +5,7 @@ module.exports = socket => { return async (data) => { let user = await models.User.findOne({where: {passwordToken: data.token}}); if (!user) - socket.emit("setPassword", {error: {message: "invalid_token"}}) + socket.emit("setPassword", {error: {message: "invalid_token"}}); else if (user.passwordTokenDate && ((new Date().getTime() - user.passwordTokenDate.getTime()) / 1000 > 3600)) socket.emit("setPassword", {error: {message: "expired_token"}}); else { @@ -16,4 +16,4 @@ module.exports = socket => { socket.emit("setPassword", true); } } -} +}; diff --git a/sockets/login.js b/sockets/login.js index e1a7341..6d0b89a 100644 --- a/sockets/login.js +++ b/sockets/login.js @@ -15,4 +15,4 @@ module.exports = socket => { socket.emit("login", user) } } -} +}; diff --git a/sockets/logout.js b/sockets/logout.js index 2244722..6e7be2f 100644 --- a/sockets/logout.js +++ b/sockets/logout.js @@ -7,4 +7,4 @@ module.exports = socket => { socket.emit("logout", {error: { message: "not_logged_in"}}); } } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/sockets/profile/edit.js b/sockets/profile/edit.js index 99565a4..1b93aec 100644 --- a/sockets/profile/edit.js +++ b/sockets/profile/edit.js @@ -6,7 +6,7 @@ module.exports = socket => { if (!user) socket.emit("profileEdit", {error: {message: "not_found"}}); else if (!user.checkPassword(data.oldPassword)) - socket.emit("profileEdit", {error: {message: "invalid_password"}}) + socket.emit("profileEdit", {error: {message: "invalid_password"}}); else { if (data.firstName !== user.firstName) user.firstName = data.firstName; @@ -14,10 +14,10 @@ module.exports = socket => { user.lastName = data.lastName; user.newPassword = data.newPassword; if (data.password && !user.checkPassword(data.password)) - user.passwordHash = data.password + user.passwordHash = data.password; socket.request.session.user = user; socket.request.session.save(); socket.emit("profileEdit", user) } } -} +}; diff --git a/sockets/register.js b/sockets/register.js index 740b2c8..eaa8381 100644 --- a/sockets/register.js +++ b/sockets/register.js @@ -18,4 +18,4 @@ module.exports = socket => { await emailCheck(socket, user, null); } } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/sockets/utils/emailPassword.js b/sockets/utils/emailPassword.js index 3bc7132..281499d 100644 --- a/sockets/utils/emailPassword.js +++ b/sockets/utils/emailPassword.js @@ -16,7 +16,7 @@ module.exports = async (socket, user, callBack) => { subject: "forgot password" }), async (err, message) => { if (err) - socket.emit("forgotPassword", {error: {message: "fail_send_mail"}}) + socket.emit("forgotPassword", {error: {message: "fail_send_mail"}}); else { user.passwordToken = token; user.passwordTokenDate = new Date(); diff --git a/test/test-pages.js b/test/test-pages.js index f4afba0..c75dee1 100644 --- a/test/test-pages.js +++ b/test/test-pages.js @@ -20,7 +20,7 @@ async function clean() { before(async () => { [app, models] = await setup(); -}) +}); it("Main page content", async () => { await request(app) diff --git a/views/template/layout.pug b/views/template/layout.pug index 5fa9957..825a399 100644 --- a/views/template/layout.pug +++ b/views/template/layout.pug @@ -7,9 +7,9 @@ html link(rel="stylesheet", href="/stylesheets/style.css") script(src="/socket.io/socket.io.js") body - - var student = false - - var teacher = true - - var admin = false + - let student = false + - let teacher = true + - let admin = false div(class="row" id="page") div(class="col s2" id="panel") block navbar From e6470383c312cf5b6d99f9c91beee1588859275b Mon Sep 17 00:00:00 2001 From: flifloo Date: Sat, 12 Dec 2020 18:28:44 +0100 Subject: [PATCH 2/2] Fix const vars --- agenda/worker.js | 11 +++++++++-- bin/www | 12 ++++++------ models/user.js | 2 +- routes/edt.js | 6 +++--- routes/email.js | 4 ++-- routes/home.js | 6 +++--- routes/index.js | 4 ++-- routes/login.js | 4 ++-- routes/marks.js | 4 ++-- routes/profil.js | 4 ++-- routes/register.js | 4 ++-- routes/utils/sessionCheck.js | 2 +- routes/viescol.js | 6 +++--- 13 files changed, 38 insertions(+), 31 deletions(-) diff --git a/agenda/worker.js b/agenda/worker.js index a26f450..5a5f934 100644 --- a/agenda/worker.js +++ b/agenda/worker.js @@ -4,6 +4,7 @@ const models = require("../models"); const reg_event = /(?:(?:BEGIN:VEVENT\nDTSTAMP:(?:[A-Z0-9]*?)\nDTSTART:([A-Z0-9]*?)\nDTEND:([A-Z0-9]*?)\nSUMMARY: {0,}([a-zéèàA-Z0-9-. \, \\/ô]*?)\nLOCATION:([a-zA-Zéèà0-9-. \,\\]*?)\nDESCRIPTION:(?:\\n){0,}(LP(?:[ a-zA-Z0-9]*))\\n((?:(?:[A-Z]*) (?:[A-Z]*)(?: (?:[A-Z]*)){0,}\\n){0,})(?:.*?)\nEND:VEVENT)|(?:BEGIN:VEVENT\nDTSTAMP:(?:[A-Z0-9]*?)\nDTSTART:([A-Z0-9]*?)\nDTEND:([A-Z0-9]*?)\nSUMMARY: {0,}((?:S(?:[A-Z0-9-]*)|M(?:[A-Z0-9-]*)(?:\/M(?:[A-Z0-9-]*)){0,}|Conférence)[a-zéèàA-Z0-9-. \, \\/]*?)\nLOCATION:([a-zA-Zéèà0-9-. \,\\]*?)\nDESCRIPTION:(?:\\n){0,}((?:(?:G[0-9]S[0-9]|S[0-9]|ASPE)\\n){0,})((?:(?:[A-Z]*) (?:[A-Z]*)(?: (?:[A-Z]*)){0,}\\n){0,})(?:.*?)\nEND:VEVENT))/gs; const reg_location = /((?:[SH0-9][0-9]{2})|(?:(?:Préfa |Amphi)[0-9]))/g; +const reg_teachers = /^(?:((?:[a-zA-Z]*[ -]{0,}){0,}) ([a-zA-Z]*))$/m; const reg_date = /([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z/; const reg_classe = /(?:(LP)[ -]{0,}(.*)|(?:(G[0-9])(S[0-9])))/; const base_url = config["edt"]; @@ -82,8 +83,14 @@ function fetchEvents(days = 1, TS_Start = new Date()) { /* Teachers */ - event["teachers"] = m[6].split("\\n"); - event["teachers"].pop(); + event['teachers'] = [] + let fullTeachers = m[6].split('\\n'); + fullTeachers.forEach(e => { + if(e !== ""){ + let splittedTeachers = reg_teachers.exec(e); + event['teachers'].push([splittedTeachers[1],splittedTeachers[2]]); + } + }); output.push(event); } resolve(output); diff --git a/bin/www b/bin/www index 0e0c83c..b75ec66 100755 --- a/bin/www +++ b/bin/www @@ -30,7 +30,7 @@ fs.writeFileSync("public/stylesheets/style.css", css.css); * Get port from environment and store in Express. */ -let port = normalizePort(process.env.PORT || "3000"); +const port = normalizePort(process.env.PORT || "3000"); app.set("port", port); app.set("mailClient", mailClient); @@ -38,7 +38,7 @@ app.set("mailClient", mailClient); * Create HTTP server. */ -let server = http.createServer(app); +const server = http.createServer(app); /** * Create socket.io server @@ -66,7 +66,7 @@ models.sequelize.sync().then(() => { */ function normalizePort(val) { - let port = parseInt(val, 10); + const port = parseInt(val, 10); if (isNaN(port)) { // named pipe @@ -90,7 +90,7 @@ function onError(error) { throw error; } - let bind = typeof port === "string" + const bind = typeof port === "string" ? "Pipe " + port : "Port " + port; @@ -114,8 +114,8 @@ function onError(error) { */ function onListening() { - let addr = server.address(); - let bind = typeof addr === "string" + const addr = server.address(); + const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port; debug("Listening on " + bind); diff --git a/models/user.js b/models/user.js index 6868932..d2ccef9 100644 --- a/models/user.js +++ b/models/user.js @@ -8,7 +8,7 @@ const { } = require("sequelize"); module.exports = (sequelize, DataTypes) => { function hash(password, email) { - let cipher = crypto.createCipheriv( + const cipher = crypto.createCipheriv( "aes-256-cbc", privateKey, crypto.createHash("md5").update(email).digest("base64").slice(0, 16) diff --git a/routes/edt.js b/routes/edt.js index 6e74d6b..753a638 100644 --- a/routes/edt.js +++ b/routes/edt.js @@ -1,8 +1,8 @@ -let express = require("express"); -let router = express.Router(); +const express = require("express"); +const router = express.Router(); router.get("/", (req, res) => { res.render("pages/edt", { title: "L'ETU" }); }); -module.exports = router; \ No newline at end of file +module.exports = router; diff --git a/routes/email.js b/routes/email.js index 0597f15..0771a69 100644 --- a/routes/email.js +++ b/routes/email.js @@ -8,7 +8,7 @@ const sessionCheck = require("./utils/sessionCheck"); router.get("/check", async (req, res) => { if (!req.query.token) return error(req, res, "Missing argument", 400); - let user = await models.User.findOne({where: {emailToken: req.query.token}}); + const user = await models.User.findOne({where: {emailToken: req.query.token}}); if (user) { user.emailVerified = true; if (user.email.endsWith("@etu.univ-lyon1.fr")) @@ -25,7 +25,7 @@ router.get("/forget", sessionCheck(-1), async (req, res) => { if (!req.query.token) res.render("forget", {title: "L'ETU"}); else { - let user = await models.User.findOne({where: {passwordToken: data.token}}); + const user = await models.User.findOne({where: {passwordToken: data.token}}); if (!user) return error(req, res, "Invalid token", 400); else if (user.passwordTokenDate && ((new Date().getTime() - user.passwordTokenDate.getTime()) / 1000 > 3600)) diff --git a/routes/home.js b/routes/home.js index 10276d9..0e85584 100644 --- a/routes/home.js +++ b/routes/home.js @@ -1,9 +1,9 @@ -let express = require("express"); -let router = express.Router(); +const express = require("express"); +const router = express.Router(); /* GET home page. */ router.get("/", (req, res) => { res.render("pages/home", { title: "L'ETU" }); }); -module.exports = router; \ No newline at end of file +module.exports = router; diff --git a/routes/index.js b/routes/index.js index ced825d..fee5fcb 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,5 +1,5 @@ -let express = require("express"); -let router = express.Router(); +const express = require("express"); +const router = express.Router(); const sessionCheck = require("./utils/sessionCheck"); router.get("/", sessionCheck(1), (req, res) => { diff --git a/routes/login.js b/routes/login.js index 0a899f0..1f1aef2 100644 --- a/routes/login.js +++ b/routes/login.js @@ -1,5 +1,5 @@ -let express = require("express"); -let router = express.Router(); +const express = require("express"); +const router = express.Router(); const sessionCheck = require("./utils/sessionCheck"); router.get("/",sessionCheck(-1), (req, res) => { diff --git a/routes/marks.js b/routes/marks.js index c4d5cb9..db46ce0 100644 --- a/routes/marks.js +++ b/routes/marks.js @@ -1,5 +1,5 @@ -let express = require("express"); -let router = express.Router(); +const express = require("express"); +const router = express.Router(); router.get("/", (req, res) => { res.render("pages/marks", { title: "L'ETU" }); diff --git a/routes/profil.js b/routes/profil.js index 529ff2b..82c23b8 100644 --- a/routes/profil.js +++ b/routes/profil.js @@ -1,5 +1,5 @@ -let express = require("express"); -let router = express.Router(); +const express = require("express"); +const router = express.Router(); router.get("/", (req, res) => { res.render("pages/profil", { title: "L'ETU" }); diff --git a/routes/register.js b/routes/register.js index 9e99f1c..a7410dd 100644 --- a/routes/register.js +++ b/routes/register.js @@ -1,5 +1,5 @@ -let express = require("express"); -let router = express.Router(); +const express = require("express"); +const router = express.Router(); const sessionCheck = require("./utils/sessionCheck"); router.get("/",sessionCheck(-1), (req, res) => { diff --git a/routes/utils/sessionCheck.js b/routes/utils/sessionCheck.js index 5a54bc5..5c66215 100644 --- a/routes/utils/sessionCheck.js +++ b/routes/utils/sessionCheck.js @@ -1,4 +1,4 @@ -let error = require("./error"); +const error = require("./error"); function sessionCheck(permission) { return (req, res, next) => { diff --git a/routes/viescol.js b/routes/viescol.js index bc0c341..e846717 100644 --- a/routes/viescol.js +++ b/routes/viescol.js @@ -1,8 +1,8 @@ -let express = require("express"); -let router = express.Router(); +const express = require("express"); +const router = express.Router(); router.get("/", (req, res) => { res.render("pages/viescol", { title: "L'ETU" }); }); -module.exports = router; \ No newline at end of file +module.exports = router;