Commit 3bdfc65e authored by benjamin.sitbon's avatar benjamin.sitbon
Browse files

ajout des regex pour le register

parent 5993e445
......@@ -18,9 +18,11 @@ Accédez au dossier contenant le serveur Node
Installez les dépendances
`npm install`
`npm install nodemon`
Démarrez le serveur Node
`npm start` si vous avez installé nodemon sinon
`node server.js`
Vous pouvez ensuite visualiser le site en local sur un navigateur: **localhost:8080**
......
......@@ -98,16 +98,17 @@ app.get(config.rootApi + "pokemons",function (req,res){
app.post('/register', async (req, res) => {
console.log(req.body);
try{
let foundUser = users.find((data) => req.body.email === data.email);
let foundUser = users.find((data) => req.body.e === data.email);
if (!foundUser) {
let hashPassword = await bcrypt.hash(req.body.password, 10);
let hashPassword = await bcrypt.hash(req.body.p, 10);
let newUser = {
username: req.body.username,
email: req.body.email,
username: req.body.u,
email: req.body.e,
password: hashPassword,
cart:[]
};
......
document.getElementsByClassName("btn")[0].onclick = async function(){
let email = document.getElementById("email").value;
let password = document.getElementById("password").value;
let username = document.getElementById("username").value;
if(email === "" || password === "" || username === ""){
document.getElementsByClassName("text")[0].innerHTML = "Some fields aren't completed"
return 0;
}
let data = {email, password, username};
document.getElementsByClassName("btn")[0].onclick = async function(){
const response = await fetch("http://localhost:8081/register", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
const json = await response.json();
let email = document.getElementById("email");
let password = document.getElementById("password");
let username = document.getElementById("username");
if(json.msg === "invalid"){
document.getElementsByClassName("text")[0].innerHTML = "User already registered"
if(email.value === "" || password.value === "" || username.value === ""){
document.getElementsByClassName("text")[0].innerHTML = "Some fields aren't filled"
return 0;
}
else if(json.msg === "error"){
document.getElementsByClassName("text")[0].innerHTML = "An error occured"
if(!email.checkValidity()){
document.getElementsByClassName("text")[0].innerHTML = "Email doesn't exist"
return 0;
}else if(!username.checkValidity()){
document.getElementsByClassName("text")[0].innerHTML = "The username must be longer than 6 letters and lower than 12"
return 0;
}else if(!password.checkValidity()){
document.getElementsByClassName("text")[0].innerHTML = "The password must be longer than 7 letters and have at least one Uppercase and digit"
return 0;
}
else{
window.location.href = "login.html"
let e = email.value;
let p = password.value;
let u = username.value;
let data = {e, p, u}
const response = await fetch("http://localhost:8081/register", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
const json = await response.json();
if(json.msg === "invalid"){
document.getElementsByClassName("text")[0].innerHTML = "User already registered"
}
else if(json.msg === "error"){
document.getElementsByClassName("text")[0].innerHTML = "An error occured"
}
else{
window.location.href = "login.html"
}
}
}
\ No newline at end of file
}
......@@ -7,35 +7,38 @@
<link rel="stylesheet" href="css/register.css">
<title>Register</title>
</head>
<body>
<main>
<div class="form">
<form action="/register" method="POST" class="login-box">
<form action="#" method="#" class="login-box">
<h1>Sign up</h1>
<label for="email"> Adresse mail </label>
<div class="textbox">
<i class="fa fa-envelope" aria-hidden="true"></i>
<input type="email" id ="email" name="email" placeholder="JPSartre@gmail.com" required="@">
<input type="email" id ="email" name="email" placeholder="JPSartre@gmail.com" required="@" pattern="[A-Za-z0-9\._-]+@([A-Za-z]+\.[A-Za-z]+)+">
</div>
<label for="username"> username </label>
<div class="textbox">
<i class="fa fa-user" aria-hidden="true"></i>
<input type="text" id ="username" name="username" placeholder="jpdu75" required="">
<input type="text" id ="username" name="username" placeholder="jpdu75" required="" pattern="[A-Za-z0-9]{6,12}">
</div>
<label for="street"> Password </label>
<div class="textbox">
<i class="fa fa-lock" aria-hidden="true"></i>
<input type="password" id ="password" name="password" placeholder="password123" required="">
<input type="password" id ="password" name="password" placeholder="password123" required="" pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$">
</div>
</form>
<button class = "btn">Sign up</button>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment