-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.js
49 lines (39 loc) · 1.3 KB
/
signup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//create a signUp function
function signUp(){
var fullName = document.getElementById('fname').value
var email = document.getElementById('email').value
var phone = document.getElementById('phone').value
var password = document.getElementById('password').value
//creating a obj and assign the input value
var userobj ={
fullName,
email,
phone,
password
}
var get_user = JSON.parse(localStorage.getItem("users"))
console.log(get_user,'getuser')
if(get_user==null){
var arr = []
arr.push(userobj)
console.log("first signup")
localStorage.setItem("users", JSON.stringify(arr))
window.location.replace("./index.html")
}else{
console.log('signup')
var findUser = get_user.findIndex(function (value) {
console.log(value.email, "value")
if (value.email === email) {
return true
}
})
if (findUser === -1) {
get_user.push(userobj)
localStorage.setItem("users", JSON.stringify(get_user))
alert("user signup")
window.location.replace("./index.html")
} else {
alert("email address already exists")
}
}
}