diff --git a/public/javascripts/edt.js b/public/javascripts/edt.js index 6144c49..889b557 100644 --- a/public/javascripts/edt.js +++ b/public/javascripts/edt.js @@ -1,4 +1,3 @@ -const socket = io.connect(); const date = document.getElementById("date"); const details = document.getElementById("details"); const marksdetailsbackground = document.getElementById("marksdetailsbackground"); diff --git a/public/javascripts/home.js b/public/javascripts/home.js index fdea4e3..f52b5e2 100644 --- a/public/javascripts/home.js +++ b/public/javascripts/home.js @@ -1,5 +1,3 @@ -const socket = io.connect(); - socket.on("agendaGet", data => { document.querySelectorAll(".eventName, .eventLocation").forEach(p => p.innerHTML = ""); data.forEach(event => { diff --git a/public/javascripts/login.js b/public/javascripts/login.js index 1f04c1b..e9a51da 100644 --- a/public/javascripts/login.js +++ b/public/javascripts/login.js @@ -1,5 +1,3 @@ -let socket = io.connect(); - document.getElementById("login").addEventListener("submit", e=>{ e.preventDefault(); let expressionReguliere = /^(([^<>()[]\.,;:s@]+(.[^<>()[]\.,;:s@]+)*)|(.+))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/; diff --git a/public/javascripts/main.js b/public/javascripts/main.js index 74ddccb..1bc9682 100644 --- a/public/javascripts/main.js +++ b/public/javascripts/main.js @@ -1,10 +1,12 @@ -let socket = io.connect(); +const socket = io.connect(); /* Front-end Event */ // Disconnect -document.getElementById("logout").addEventListener("click", function() { - socket.emit("logout") +document.addEventListener("DOMContentLoaded", () => { + const logout = document.getElementById("logout"); + if (logout) + logout.addEventListener("click", () => socket.emit("logout")); }); @@ -23,4 +25,4 @@ socket.on("logout", data=>{ function profilRedirect(){ document.location.href="/profil"; -} \ No newline at end of file +} diff --git a/public/javascripts/marks-student.js b/public/javascripts/marks-student.js index f4f4050..e79ff85 100644 --- a/public/javascripts/marks-student.js +++ b/public/javascripts/marks-student.js @@ -1,4 +1,3 @@ -const socket = io.connect(); const marks = document.getElementById("marksrow"); const evaluationTemplate = marks.querySelector("#evaluationTemplate"); const gradeTemplate = marks.querySelector("#gradeTemplate"); diff --git a/public/javascripts/marks-teacher.js b/public/javascripts/marks-teacher.js index 18daa4f..09b08c5 100644 --- a/public/javascripts/marks-teacher.js +++ b/public/javascripts/marks-teacher.js @@ -1,4 +1,3 @@ -const socket = io.connect(); const group = document.getElementById("group"); const evaluation = document.getElementById("evaluation"); const marksform = document.getElementById("marksform"); diff --git a/public/javascripts/profil.js b/public/javascripts/profil.js index 3d2b7f8..a562c71 100644 --- a/public/javascripts/profil.js +++ b/public/javascripts/profil.js @@ -1,5 +1,3 @@ -let socket = io.connect(); - document.getElementById("editprofil").addEventListener("submit", e=>{ e.preventDefault(); socket.emit("profileEdit", { diff --git a/public/javascripts/register.js b/public/javascripts/register.js index aad9acf..edc06d3 100644 --- a/public/javascripts/register.js +++ b/public/javascripts/register.js @@ -1,5 +1,3 @@ -let socket = io.connect(); - document.getElementById("register").addEventListener("submit", e=>{ e.preventDefault(); let expressionReguliere = /^(([^<>()[]\.,;:s@]+(.[^<>()[]\.,;:s@]+)*)|(.+))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/; diff --git a/sass/style.sass b/sass/style.sass index c8077a3..0d4676d 100644 --- a/sass/style.sass +++ b/sass/style.sass @@ -247,11 +247,11 @@ h3 div:nth-child(3) text-align: left - #marksrow padding: 20px 70px - +#logout, #logout>a + cursor: pointer #marksdetails, #details z-index: 100001 diff --git a/views/pages/login.pug b/views/pages/login.pug index 11a7e62..9b13903 100644 --- a/views/pages/login.pug +++ b/views/pages/login.pug @@ -1,12 +1,6 @@ -doctype html -html - head - title= title - link(href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet") - link(rel="stylesheet", href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css") - link(rel="stylesheet", href="/stylesheets/style.css") - script(src="/socket.io/socket.io.js") - body +extends ../template/layout + +block content div(class='row main-form') div(class='col s12 m8 offset-m2 signinup z-depth-5' id="signin") h2 Welcome back @@ -37,4 +31,3 @@ html input(type='submit' value='Send email') script(src="/javascripts/login.js") - script(src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js") \ No newline at end of file diff --git a/views/pages/register.pug b/views/pages/register.pug index 3ec7d41..5fcadbf 100644 --- a/views/pages/register.pug +++ b/views/pages/register.pug @@ -1,12 +1,6 @@ -doctype html -html - head - title= title - link(href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet") - link(rel="stylesheet", href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css") - link(rel="stylesheet", href="/stylesheets/style.css") - script(src="/socket.io/socket.io.js") - body +extends ../template/layout + +block content div(class='row main-form') div(class='col s12 m8 offset-m2 signinup z-depth-5' id="signup") h2 Welcome @@ -34,4 +28,3 @@ html a(class="alreadyregister" href="login") Already registered ? script(src="/javascripts/register.js") - script(src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js") \ No newline at end of file diff --git a/views/template/layout.pug b/views/template/layout.pug index a7878dc..7c25a41 100644 --- a/views/template/layout.pug +++ b/views/template/layout.pug @@ -14,15 +14,26 @@ html meta(name="msapplication-TileColor" content="#da532c") meta(name="theme-color" content="#ffffff") script(src="/socket.io/socket.io.js") + script(src="/javascripts/main.js") body - - var student = false; - - var teacher = true; - - var admin = false; + - + var student = false, teacher = false, admin = false; + if (session.user) { + switch (session.user.permissions) { + case 1: + student = true; + break; + case 2: + teacher = true; + break; + case 3: + admin = true; + } + } div(class="row" id="page") block navbar div(class="col s12" id="main") block content - script(src="/javascripts/main.js") script(src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js") script. M.AutoInit(); diff --git a/views/template/navbar.pug b/views/template/navbar.pug index 1e67b42..85aea5b 100644 --- a/views/template/navbar.pug +++ b/views/template/navbar.pug @@ -2,7 +2,7 @@ extends layout block navbar ul#slide-out.sidenav - if session.user.permissions === 1 + if student li .user-view.student p @@ -12,8 +12,8 @@ block navbar span.white-text.name=session.user.Groups[session.user.Groups.length-1].displayName p span.white-text.email=session.user.email - a - span.white-text Se déconnecter + a#logout + span.white-text Logout li a(href="/" class="waves-effect") Home @@ -28,15 +28,15 @@ block navbar li a(href="/viescol" class="waves-effect") School and student life - if session.user.permissions === 2 + else if teacher li .user-view.teacher p(href='#name') span.white-text.name=session.user.firstName + " " + session.user.lastName p(href='#email') span.white-text.email=session.user.email - a - span.white-text Se déconnecter + a#logout + span.white-text Logout li a(href="/" class="waves-effect") Home li @@ -50,15 +50,15 @@ block navbar li a(href="/viescol" class="waves-effect") School and student life - if session.user.permissions === 3 + else if admin li .user-view.admin p(href='#name') span.white-text.name=session.user.firstName + " " + session.user.lastName p(href='#email') span.white-text.email=session.user.email - a - span.white-text Se déconnecter + a#logout + span.white-text Logout li a(href="/" class="waves-effect") Home li(class="active")