Setup user register
This commit is contained in:
parent
18983b4461
commit
b73136b6ac
5 changed files with 47 additions and 5 deletions
|
@ -43,13 +43,11 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
},
|
},
|
||||||
firstName: {
|
firstName: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: false
|
||||||
unique: "userFullName"
|
|
||||||
},
|
},
|
||||||
lastName: {
|
lastName: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: false
|
||||||
unique: "userFullName"
|
|
||||||
},
|
},
|
||||||
passwordHash: {
|
passwordHash: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
|
|
21
public/javascripts/register.js
Normal file
21
public/javascripts/register.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
//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,}))$/;
|
||||||
|
let mail = document.getElementById("mailreg-input").value;
|
||||||
|
if(expressionReguliere.test(mail)) {
|
||||||
|
socket.emit("register", {
|
||||||
|
"email": mail,
|
||||||
|
"firstName": document.getElementById("firstname-input").value,
|
||||||
|
"lastName": document.getElementById("lastname-input").value,
|
||||||
|
"password": document.getElementById("passwordreg-input").value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("register", data=>{
|
||||||
|
if(data){
|
||||||
|
window.location.href = "/";
|
||||||
|
}
|
||||||
|
});
|
|
@ -1,5 +1,6 @@
|
||||||
module.exports = socket => {
|
module.exports = socket => {
|
||||||
console.log("New connection !");
|
console.log("New connection !");
|
||||||
socket.on("login", require("./login")(socket));
|
socket.on("login", require("./login")(socket));
|
||||||
|
socket.on("register", require("./register")(socket));
|
||||||
socket.emit("connected");
|
socket.emit("connected");
|
||||||
}
|
}
|
||||||
|
|
21
sockets/register.js
Normal file
21
sockets/register.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
const modules = require("../models");
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
return async (data) => {
|
||||||
|
if (await modules.User.findByPk(data.email) || !data.email.endsWith("univ-lyon1.fr")) {
|
||||||
|
socket.emit("register", null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let user = await modules.User.create({
|
||||||
|
email: data.email,
|
||||||
|
firstName: data.firstName,
|
||||||
|
lastName: data.lastName,
|
||||||
|
passwordHash: data.password
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.request.session.user = user;
|
||||||
|
socket.request.session.save();
|
||||||
|
socket.emit("register", user);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ block content
|
||||||
|
|
||||||
div(class='col s12 m8 offset-m2 signinup z-depth-5' id="signup")
|
div(class='col s12 m8 offset-m2 signinup z-depth-5' id="signup")
|
||||||
h2 Welcome
|
h2 Welcome
|
||||||
form
|
form#register
|
||||||
div(class="input-field col s6")
|
div(class="input-field col s6")
|
||||||
i(class="material-icons prefix") portrait
|
i(class="material-icons prefix") portrait
|
||||||
input(type="text" id="firstname-input" class="autocomplete")
|
input(type="text" id="firstname-input" class="autocomplete")
|
||||||
|
@ -52,3 +52,4 @@ block content
|
||||||
input(type='submit' value='Send email')
|
input(type='submit' value='Send email')
|
||||||
|
|
||||||
script(src="/javascripts/login.js")
|
script(src="/javascripts/login.js")
|
||||||
|
script(src="/javascripts/register.js")
|
||||||
|
|
Reference in a new issue