Merge branch 'back' into 'master'
Back Closes #28 See merge request LETU/LETU!22
This commit is contained in:
commit
ba2986efe6
20 changed files with 267 additions and 88 deletions
|
@ -2,12 +2,14 @@ const https = require("https");
|
|||
const config = require("worker_threads").workerData;
|
||||
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_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){1,})((?:(?:[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 reg_group = /(?:(LP)[ -]{0,}(.*)|(?:(G[0-9])(S[0-9])))/;
|
||||
const base_url = config["edt"];
|
||||
const capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
|
||||
|
||||
|
||||
function fetchEvents(days = 1, TS_Start = new Date()) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -32,8 +34,8 @@ function fetchEvents(days = 1, TS_Start = new Date()) {
|
|||
reg_event.lastIndex++;
|
||||
}
|
||||
let event = [];
|
||||
let promotion = [];
|
||||
let classe = [];
|
||||
let semester = [];
|
||||
let group = [];
|
||||
/*
|
||||
m = [
|
||||
FullMatch,
|
||||
|
@ -47,21 +49,30 @@ function fetchEvents(days = 1, TS_Start = new Date()) {
|
|||
*/
|
||||
if (m[1] !== undefined) {
|
||||
// LPXXXX
|
||||
classe.push(m[5]);
|
||||
} else {
|
||||
m.splice(1, 6);
|
||||
// GXSX | SX | ASPE
|
||||
}
|
||||
let csplit = m[5].split("\\n");
|
||||
csplit.pop();
|
||||
csplit.forEach(e => {
|
||||
if (e === "ASPE") promotion.push(e);
|
||||
if (/^S[0-9]$/.test(e)) promotion.push(e);
|
||||
if (/^G[0-9]S[0-9]$/.test(e)) classe.push(e);
|
||||
});
|
||||
if (e === "ASPE") {
|
||||
semester.push(e);
|
||||
}else if(/^S[0-9]$/.test(e)) {
|
||||
semester.push(e);
|
||||
}else{
|
||||
let groupSplit = reg_group.exec(e);
|
||||
if (groupSplit[1] === 'LP') {
|
||||
group.push([groupSplit[2], groupSplit[1]]);
|
||||
} else {
|
||||
group.push([groupSplit[3], groupSplit[4]]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
event["title"] = m[3];
|
||||
event["promotion"] = promotion;
|
||||
event["class"] = classe;
|
||||
event["semesters"] = semester;
|
||||
event["groups"] = group;
|
||||
/*
|
||||
Date
|
||||
*/
|
||||
|
@ -83,7 +94,7 @@ function fetchEvents(days = 1, TS_Start = new Date()) {
|
|||
/*
|
||||
Teachers
|
||||
*/
|
||||
event['teachers'] = []
|
||||
event['teachers'] = [];
|
||||
let fullTeachers = m[6].split('\\n');
|
||||
fullTeachers.forEach(e => {
|
||||
if(e !== ""){
|
||||
|
@ -128,11 +139,11 @@ function compare(a, b) {
|
|||
}
|
||||
|
||||
function compareGroups(list1, list2) {
|
||||
return compare(list1, list2.map(g => [g.number, g.Semester.name, g.Semester.year]));
|
||||
return compare(list1.map(g => g[0] + " " + g[1]), list2.map(g => g.number + " " + g.Semester.name));
|
||||
}
|
||||
|
||||
function compareTeachers(list1, list2) {
|
||||
return compare(list1, list2.map(t => t.lastName.toUpperCase() + " " + t.firstName.toUpperCase()));
|
||||
return compare(list1.map(t => t[0].toUpperCase() + " " + t[1].toUpperCase()), list2.map(t => t.lastName.toUpperCase() + " " + t.firstName.toUpperCase()));
|
||||
}
|
||||
|
||||
function compareSemesters(list1, list2) {
|
||||
|
@ -147,13 +158,14 @@ async function updateDatabase() {
|
|||
include: {model: models.Semester, required: true}
|
||||
}, models.User, models.Semester]
|
||||
})) {
|
||||
if (!events.find(e => (e.title === event.name && e.startDate.getTime() === event.startDate.getTime() &&
|
||||
let ev = events.find(e => (e.title === event.name && e.startDate.getTime() === event.startDate.getTime() &&
|
||||
e.endDate.getTime() === event.endDate.getTime() && e.locations.join(", ") === event.locations &&
|
||||
compareGroups(e.class, event.Groups) && compareTeachers(e.teachers, event.Users) &&
|
||||
compareSemesters(e.semesters, event.Semesters))))
|
||||
compareGroups(e.groups, event.Groups) && compareTeachers(e.teachers, event.Users) &&
|
||||
compareSemesters(e.semesters, event.Semesters)));
|
||||
if (!ev)
|
||||
await event.destroy();
|
||||
else
|
||||
delete events[events.indexOf(event)];
|
||||
events = events.filter(e => e !== ev);
|
||||
}
|
||||
|
||||
for (let event of events) {
|
||||
|
@ -166,12 +178,12 @@ async function updateDatabase() {
|
|||
|
||||
let teachers = [];
|
||||
for (let teacher of event.teachers) {
|
||||
let t = await models.User.findOne({where: {permissions: 2, lastName: teacher[0], firstName: teacher[1]}});
|
||||
let t = await models.User.findOne({where: {permissions: 2, lastName: teacher[0].toUpperCase(), firstName: capitalizeFirstLetter(teacher[1])}});
|
||||
if (!t)
|
||||
t = await models.User.create({
|
||||
email: teacher[1].toLowerCase().replace(" ", "-") + "." + teacher[0].toLowerCase().replace(" ", "-") + "@univ-lyon1.fr",
|
||||
firstName: teacher[1],
|
||||
lastName: teacher[0],
|
||||
email: teacher[1].toLowerCase().replaceAll(" ", "-") + "." + teacher[0].toLowerCase().replaceAll(" ", "-") + "@univ-lyon1.fr",
|
||||
firstName: capitalizeFirstLetter(teacher[1]),
|
||||
lastName: teacher[0].toUpperCase(),
|
||||
permissions: 2,
|
||||
passwordHash: Math.round((Math.pow(36, 12 + 1) - Math.random() * Math.pow(36, 12))).toString(36).slice(1)
|
||||
});
|
||||
|
@ -180,7 +192,7 @@ async function updateDatabase() {
|
|||
await e.addUsers(teachers);
|
||||
|
||||
let semesters = [];
|
||||
for (let semester of event.promotion) {
|
||||
for (let semester of event.semesters) {
|
||||
let s = await models.Semester.findOne({where: {name: semester, year: event.startDate.getFullYear()}});
|
||||
if (!s)
|
||||
s = await models.Semester.create({
|
||||
|
@ -192,32 +204,18 @@ async function updateDatabase() {
|
|||
await e.addSemesters(semesters);
|
||||
|
||||
let groups = [];
|
||||
for (let group of event.class) {
|
||||
let rGroup = reg_classe.exec(group);
|
||||
let semesterName;
|
||||
let groupName;
|
||||
if (rGroup[1] !== undefined) {
|
||||
// LP
|
||||
semesterName = 'LP';
|
||||
groupName = rGroup[2];
|
||||
} else {
|
||||
// GXSX
|
||||
semesterName = rGroup[4];
|
||||
groupName = rGroup[3];
|
||||
}
|
||||
|
||||
|
||||
let s = await models.Semester.findOne({where: {name: semesterName, year: event.startDate.getFullYear()}});
|
||||
for (let group of event.groups) {
|
||||
let s = await models.Semester.findOne({where: {name: group[1], year: event.startDate.getFullYear()}});
|
||||
if (!s)
|
||||
s = await models.Semester.create({
|
||||
name: semesterName,
|
||||
name: group[1],
|
||||
year: event.startDate.getFullYear()
|
||||
});
|
||||
|
||||
let g = await models.Group.findOne({where: {number: groupName, SemesterId: s.id}});
|
||||
let g = await models.Group.findOne({where: {number: group[0], SemesterId: s.id}});
|
||||
if (!g)
|
||||
g = await models.Group.create({
|
||||
number: groupName,
|
||||
number: group[0],
|
||||
SemesterId: s.id
|
||||
});
|
||||
groups.push(g);
|
||||
|
|
2
app.js
2
app.js
|
@ -9,7 +9,6 @@ let config = process.env.NODE_ENV === "test" ? {} : require("./config/config.jso
|
|||
let indexRouter = require("./routes/index");
|
||||
const loginRouter = require("./routes/login");
|
||||
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");
|
||||
|
@ -41,7 +40,6 @@ app.use("/", indexRouter);
|
|||
app.use("/login", loginRouter);
|
||||
app.use("/email", require("./routes/email"));
|
||||
app.use("/edt", edtRouter);
|
||||
app.use("/home", homeRouter);
|
||||
app.use("/marks", marksRouter);
|
||||
app.use('/register', registerRouter);
|
||||
app.use('/viescol', viescolRouter);
|
||||
|
|
2
bin/www
2
bin/www
|
@ -17,7 +17,7 @@ const mailClient = new SMTPClient(process.env.NODE_ENV === "test" ? {} : require
|
|||
/**
|
||||
* Render all Sass to css
|
||||
*/
|
||||
css = sass.renderSync({
|
||||
let css = sass.renderSync({
|
||||
file: "sass/style.sass",
|
||||
includePaths: ["sass/"],
|
||||
outputStyle: "compressed"
|
||||
|
|
27
models/evaluation.js
Normal file
27
models/evaluation.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
"use strict";
|
||||
|
||||
const { Model } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class Evaluation extends Model {
|
||||
static associate(models) {
|
||||
Evaluation.belongsToMany(models.User, {through: "EvaluationTeacher"});
|
||||
Evaluation.hasMany(models.Grade);
|
||||
Evaluation.belongsTo(models.UE);
|
||||
}
|
||||
}
|
||||
Evaluation.init({
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
date: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: "Evaluation",
|
||||
});
|
||||
return Evaluation;
|
||||
};
|
30
models/grade.js
Normal file
30
models/grade.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
"use strict";
|
||||
|
||||
const { Model } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class Grade extends Model {
|
||||
static associate(models) {
|
||||
Grade.belongsTo(models.Evaluation);
|
||||
Grade.belongsTo(models.User, {as: "TeacherGrade"});
|
||||
Grade.belongsTo(models.User, {as: "StudentGrade"});
|
||||
}
|
||||
}
|
||||
Grade.init({
|
||||
score: {
|
||||
type: DataTypes.FLOAT,
|
||||
allowNull: false
|
||||
},
|
||||
limit: {
|
||||
type: DataTypes.FLOAT,
|
||||
allowNull: false
|
||||
},
|
||||
comment: {
|
||||
type: DataTypes.TEXT
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: "Grade",
|
||||
});
|
||||
return Grade;
|
||||
};
|
|
@ -20,7 +20,10 @@ module.exports = (sequelize, DataTypes) => {
|
|||
static associate(models) {
|
||||
User.belongsToMany(models.Group, {through: "UserGroup"});
|
||||
User.belongsToMany(models.Event, {through: "EventTeacher"});
|
||||
User.belongsToMany(models.Evaluation, {through: "EvaluationTeacher"});
|
||||
User.belongsToMany(models.UE, {through: "UEUser"});
|
||||
//User.hasMany(models.Grade, {as : "TeacherGrade"});
|
||||
//User.hasMany(models.Grade, {as: "StudentGrade"});
|
||||
}
|
||||
|
||||
checkPassword(password) {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
const express = require("express");
|
||||
const sessionCheck = require("./utils/sessionCheck");
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
router.get("/", sessionCheck(1), (req, res) => {
|
||||
res.render("pages/edt", { title: "L'ETU" });
|
||||
});
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
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;
|
|
@ -1,7 +1,8 @@
|
|||
const express = require("express");
|
||||
const sessionCheck = require("./utils/sessionCheck");
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
router.get("/", sessionCheck(1), (req, res) => {
|
||||
res.render("pages/marks", { title: "L'ETU" });
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
const express = require("express");
|
||||
const sessionCheck = require("./utils/sessionCheck");
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
router.get("/", sessionCheck(1), (req, res) => {
|
||||
res.render("pages/profil", { title: "L'ETU" });
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
const express = require("express");
|
||||
const sessionCheck = require("./utils/sessionCheck");
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
router.get("/", sessionCheck(1), (req, res) => {
|
||||
res.render("pages/viescol", { title: "L'ETU" });
|
||||
});
|
||||
|
||||
|
|
|
@ -1,37 +1,59 @@
|
|||
const models = require("../../models");
|
||||
|
||||
|
||||
function addWhere(options, index, attr, value) {
|
||||
if (!options.include[index].where)
|
||||
options.include[index].where = {};
|
||||
if (!options.include[index].where[attr])
|
||||
options.include[index].where[attr] = {};
|
||||
if (!options.include[index].where[attr][models.Sequelize.Op.or])
|
||||
options.include[index].where[attr][models.Sequelize.Op.or] = [];
|
||||
options.include[index].where[attr][models.Sequelize.Op.or].push(value);
|
||||
options.include[index].require = true;
|
||||
}
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
let startDate = data.startDate ? data.startDate : new Date(), endDate = data.endDate ? data.endDate : new Date();
|
||||
let options = {where: {startDate: startDate, endDate: endDate}, include: []};
|
||||
if (data.semesters) {
|
||||
let options = {
|
||||
where: {},
|
||||
include: [
|
||||
{model: models.User, attributes: ["email", "firstName", "lastName"]},
|
||||
{model: models.Group, include: models.Semester},
|
||||
{model: models.Semester, include: models.Group}
|
||||
]
|
||||
};
|
||||
if (data && data.startDate)
|
||||
options.where.startDate = data.startDate;
|
||||
if (data && data.endDate)
|
||||
options.where.endDate = data.endDate;
|
||||
if (data && data.semesters) {
|
||||
for (let semester of data.semesters) {
|
||||
let s = await models.Semester.findByPk(semester);
|
||||
if (!s) {
|
||||
socket.emit("agendaGet", {error: {message: "semester_not_found"}});
|
||||
return
|
||||
} else
|
||||
options.include.push({model: models.Semester, where: {id: s.id}, require: true});
|
||||
addWhere(options, 2, "id", s.id);
|
||||
}
|
||||
}
|
||||
if (data.groups) {
|
||||
if (data && data.groups) {
|
||||
for (let group of data.groups) {
|
||||
let g = await models.Group.findByPk(group);
|
||||
if (!g) {
|
||||
socket.emit("agendaGet", {error: {message: "group_not_found"}});
|
||||
return
|
||||
} else
|
||||
options.include.push({model: models.Group, where: {id: g.id}, require: true});
|
||||
addWhere(options, 1, "id", g.id);
|
||||
}
|
||||
}
|
||||
if (data.teachers) {
|
||||
if (data && data.teachers) {
|
||||
for (let teacher of data.teachers) {
|
||||
let t = await models.User.findByPk(teacher);
|
||||
if (!t) {
|
||||
socket.emit("agendaGet", {error: {message: "teacher_not_found"}});
|
||||
return
|
||||
} else
|
||||
options.include.push({model: models.User, where: {id: t.email}, require: true});
|
||||
addWhere(options, 0, "email", t.email);
|
||||
}
|
||||
}
|
||||
socket.emit("agendaGet", await models.Event.findAll(options));
|
||||
|
|
22
sockets/get/evaluationGet.js
Normal file
22
sockets/get/evaluationGet.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const models = require("../../models");
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
const options = {where: {},
|
||||
include: [models.UE, {model: models.User},
|
||||
{
|
||||
model: models.Grade,
|
||||
include: [{model: models.User, as: "TeacherGrade"}, {model: models.User, as: "StudentGrade"}]
|
||||
}]
|
||||
};
|
||||
|
||||
if (data && data.id)
|
||||
options.where.id = data.id;
|
||||
|
||||
if (socket.request.session.user.permissions === 2) {
|
||||
options.include[1].where = {email: socket.request.session.user.email};
|
||||
options.include[1].required = true;
|
||||
}
|
||||
socket.emit("evaluationGet", await models.Evaluation.findAll(options));
|
||||
}
|
||||
};
|
22
sockets/get/gradeGet.js
Normal file
22
sockets/get/gradeGet.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const models = require("../../models");
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
const options = {where: {}, include: [models.Evaluation,
|
||||
{model: models.User, as: "TeacherGrade"},
|
||||
{model: models.User, as: "StudentGrade"}]};
|
||||
|
||||
if (data && data.id)
|
||||
options.where.id = data.id;
|
||||
|
||||
switch (socket.request.session.user.permissions) {
|
||||
case 1:
|
||||
options.where.StudentGradeEmail = socket.request.session.user.email;
|
||||
break;
|
||||
case 2:
|
||||
options.where.TeacherGradeEmail = socket.request.session.user.email;
|
||||
break;
|
||||
}
|
||||
socket.emit("gradeGet", await models.Grade.findAll(options));
|
||||
}
|
||||
};
|
|
@ -2,19 +2,24 @@ const models = require("../../models");
|
|||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
let options = {where: {}, include: [{model: models.Semester, require: true}]};
|
||||
if (data.number)
|
||||
let options = {include: [{model: models.Semester}]};
|
||||
if (data && (data.id || data.number || data.semester))
|
||||
options.where = {};
|
||||
if (data && data.id)
|
||||
options.where.id = data.id;
|
||||
if (data && data.number)
|
||||
options.where.number = data.number;
|
||||
if (data.semester) {
|
||||
if (data && data.semester) {
|
||||
let s = await models.Semester.findByPk(data.semester);
|
||||
if (!s) {
|
||||
socket.emit("groupGet", {error: {message: "semester_not_found"}});
|
||||
return
|
||||
}
|
||||
options.include[0].where = {id: s.id};
|
||||
options.include[0].require = true;
|
||||
}
|
||||
if (data.users)
|
||||
options.include.push({model: models.User, require: true});
|
||||
if (data && data.users)
|
||||
options.include.push({model: models.User, where: {email: {[models.Sequelize.Op.in]: data.users}}, require: true});
|
||||
|
||||
socket.emit("groupGet", await models.Group.findAll(options));
|
||||
}
|
||||
|
|
|
@ -2,13 +2,17 @@ const models = require("../../models");
|
|||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
let options = {where: {}, include: []};
|
||||
if (data.name)
|
||||
let options = {include: [{model: models.Group}]};
|
||||
if (data && (data.id || data.name || data.year))
|
||||
options.where = {};
|
||||
if (data && data.id)
|
||||
options.where.id = data.id;
|
||||
if (data && data.name)
|
||||
options.where.name = data.name;
|
||||
if (data.year)
|
||||
if (data && data.year)
|
||||
options.where.year = data.year;
|
||||
if (data.groups)
|
||||
options.include.push({model: models.Group, require: true});
|
||||
if (data && data.groups)
|
||||
options.include[0].where = {id: {[models.Sequelize.Op.or]: data.groups}};
|
||||
|
||||
socket.emit("semesterGet", await models.Semester.findAll(options));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
module.exports = socket => {
|
||||
console.log("New connection !");
|
||||
console.log(socket.request.session.user);
|
||||
if (!socket.request.session.user) {
|
||||
socket.on("login", require("./login")(socket));
|
||||
socket.on("register", require("./register")(socket));
|
||||
|
@ -11,6 +10,14 @@ module.exports = socket => {
|
|||
socket.on("profileEdit", require("./profile/edit")(socket));
|
||||
socket.on("logout", require("./logout")(socket));
|
||||
socket.on("agendaGet", require("./get/agendaGet")(socket));
|
||||
socket.on("gradeGet", require("./get/gradeGet")(socket));
|
||||
if (socket.request.session.user.permissions > 1)
|
||||
socket.on("evaluationGet", require("./get/evaluationGet")(socket));
|
||||
if (socket.request.session.user.permissions > 2) {
|
||||
socket.on("groupGet", require("./get/groupGet")(socket));
|
||||
socket.on("semesterGet", require("./get/semesterGet")(socket));
|
||||
socket.on("userSet", require("./set/userSet")(socket));
|
||||
}
|
||||
}
|
||||
socket.emit("connected");
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ const models = require("../models");
|
|||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
let user = await models.User.findByPk(data.email);
|
||||
let user = await models.User.findByPk(data.email, {include: {model: models.Group, include: models.Semester}});
|
||||
if (!user)
|
||||
socket.emit("login", {error: {message: "not_found"}});
|
||||
else if (!user.checkPassword(data.password))
|
||||
|
|
43
sockets/set/userSet.js
Normal file
43
sockets/set/userSet.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
const models = require("../../models");
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
if (!data || !data.user) {
|
||||
socket.emit("userSet", {error: {message: "missing_arguments"}});
|
||||
return;
|
||||
}
|
||||
let u = await models.User.findByPk(data.user);
|
||||
if (!u) {
|
||||
socket.emit("userSet", {error: {message: "user_not_found"}});
|
||||
return;
|
||||
}
|
||||
for (let i in data)
|
||||
switch (i) {
|
||||
case "firstName":
|
||||
u.firstName = data.firstName;
|
||||
break;
|
||||
case "lastName":
|
||||
u.lastName = data.lastName;
|
||||
break;
|
||||
case "password":
|
||||
u.passwordHash = data.password;
|
||||
break;
|
||||
case "permissions":
|
||||
u.permissions = data.permissions;
|
||||
break;
|
||||
case "groups":
|
||||
let groups = [];
|
||||
for (let g of data.groups) {
|
||||
let gp = await models.Group.findByPk(g);
|
||||
if (!gp) {
|
||||
socket.emit("userGet", {error: {message: "group_not_found"}});
|
||||
return
|
||||
}
|
||||
groups.push(gp);
|
||||
}
|
||||
u.setGroups(groups);
|
||||
break;
|
||||
}
|
||||
await u.save();
|
||||
}
|
||||
};
|
|
@ -6,11 +6,14 @@ block navbar
|
|||
li
|
||||
.user-view.student
|
||||
p
|
||||
span.white-text.name Benoit Kezel
|
||||
span.white-text.name=session.user.firstName + " " + session.user.lastName
|
||||
p
|
||||
span.white-text.name G4S3
|
||||
if session.user.Groups[session.user.Groups.length-1].number.startsWith("G")
|
||||
span.white-text.name=session.user.Groups[session.user.Groups.length-1].number + session.user.Groups[session.user.Groups.length-1].Semester.name
|
||||
else
|
||||
span.white-text.name=session.user.Groups[session.user.Groups.length-1].Semester.name + " " + session.user.Groups[session.user.Groups.length-1].number
|
||||
p
|
||||
span.white-text.email benoit.kezel@etu.univ-lyon1.fr
|
||||
span.white-text.email=session.user.email
|
||||
|
||||
li
|
||||
a(href="/" class="waves-effect") Home
|
||||
|
@ -29,9 +32,9 @@ block navbar
|
|||
li
|
||||
.user-view.teacher
|
||||
p(href='#name')
|
||||
span.white-text.name Benoit Kezel
|
||||
span.white-text.name=session.user.firstName + " " + session.user.lastName
|
||||
p(href='#email')
|
||||
span.white-text.email benoit.kezel@etu.univ-lyon1.fr
|
||||
span.white-text.email=session.user.email
|
||||
li
|
||||
a(href="/" class="waves-effect") Home
|
||||
li
|
||||
|
@ -49,9 +52,9 @@ block navbar
|
|||
li
|
||||
.user-view.admin
|
||||
p(href='#name')
|
||||
span.white-text.name Benoit Kezel
|
||||
span.white-text.name=session.user.firstName + " " + session.user.lastName
|
||||
p(href='#email')
|
||||
span.white-text.email benoit.kezel@etu.univ-lyon1.fr
|
||||
span.white-text.email=session.user.email
|
||||
li
|
||||
a(href="/" class="waves-effect") Home
|
||||
li(class="active")
|
||||
|
|
Reference in a new issue