Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sitbon.benjamin
App et archi Web TP 2020
Commits
3bdfc65e
Commit
3bdfc65e
authored
Jun 23, 2021
by
benjamin.sitbon
Browse files
ajout des regex pour le register
parent
5993e445
Changes
4
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
3bdfc65e
...
...
@@ -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**
...
...
backend/server.js
View file @
3bdfc65e
...
...
@@ -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
.
e
mail
===
data
.
email
);
let
foundUser
=
users
.
find
((
data
)
=>
req
.
body
.
e
===
data
.
email
);
if
(
!
foundUser
)
{
let
hashPassword
=
await
bcrypt
.
hash
(
req
.
body
.
p
assword
,
10
);
let
hashPassword
=
await
bcrypt
.
hash
(
req
.
body
.
p
,
10
);
let
newUser
=
{
username
:
req
.
body
.
u
sername
,
email
:
req
.
body
.
e
mail
,
username
:
req
.
body
.
u
,
email
:
req
.
body
.
e
,
password
:
hashPassword
,
cart
:[]
};
...
...
frontend/js/reg.js
View file @
3bdfc65e
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
}
frontend/registration.html
View file @
3bdfc65e
...
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment