diff --git a/public/javascripts/login.js b/public/javascripts/login.js new file mode 100644 index 0000000..a902af0 --- /dev/null +++ b/public/javascripts/login.js @@ -0,0 +1,18 @@ +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,}))$/; + if(expressionReguliere.test(document.getElementById("mail-input").value)){ + let email = document.getElementById("mail-input").value; + let passw = document.getElementById("password-input").value; + socket.emit("login", {"email":email,"password":passw}); + } + return false; +}) + +socket.on("login", data=>{ + if(data){ + window.location.href = "/"; + } +}) \ No newline at end of file diff --git a/views/layout.pug b/views/layout.pug index 3ce5cad..4a19a42 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -5,7 +5,7 @@ html 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 block content - script(src="/socket.io/socket.io.js") script(src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js") diff --git a/views/login.pug b/views/login.pug index 11b527a..ff32fa1 100644 --- a/views/login.pug +++ b/views/login.pug @@ -4,7 +4,7 @@ block content div(class='row main-form') div(class='col s12 m8 offset-m2 signinup z-depth-5' id="signin") h2 Welcome back - form + form#login div(class="input-field col s12") i(class="material-icons prefix") mail input(type="text" id="mail-input" class="autocomplete") @@ -50,3 +50,5 @@ block content label(for="mailforgot-input") Email input(type='submit' value='Send email') + + script(src="/javascripts/login.js")