-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
102 lines (87 loc) · 2.18 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const express = require ("express")
const path = require("path")
const morgan = require('morgan')
const bodyParser = require ('body-parser')
const app = express()
const PORT = 5000
let userArray = [ ]
app.use(morgan('dev'))
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
app.use(express.static(path.join(__dirname, "./public")))
app.set("views", path.join(__dirname, "views"))
app.set("view engine", "ejs")
app.get('/', (req, res) => {
res.render("index", {
pageTitle: "Home"
})
})
app.get('/login', (req, res) => {
res.render("login", {
pageTitle: "Login"
})
})
app.get('/signIn', (req, res) => {
res.render("signIn", {
pageTitle: "Sign In",
obj: {}
})
})
app.post('/submitForm', (req, res) => {
let userObject = req.body
let username = req.body.username
let password = req.body.password
let secondPassword = req.body.confirmPasswor
console.log(username)
console.log(userObject)
if (!password){
return res.render("signIn", {
pageTitle: "signIn",
obj : {
errorMessage: "Provide a Password"
}
})
}
if (secondPassword.length <6){
return res.render("signIn", {
pageTitle: "signIn",
obj : {
errorMessage: "Provide is too short"
}
})
}
if (!password){
return res.render("signIn", {
pageTitle: "signIn",
obj : {
errorMessage: "Provide a Password"
}
})
}
return res.render("signIn", {
pageTitle: "signIn",
obj: {
errorMessage: "work in progress"
}
})
let usernameArray = []
console.log(usernameArray)
if (usernameArray.indexOf(userObject.username) === -1) {
userArray.push(userobject)
return res.render("signIn", {
pageTitle: "signIn",
obj: {
errorMessage: "Successfully signed up"
}
})
}
return res.render ("signIn", {
pageTitle: "Sign Up",
obj: {
errorMessage: "username already exists"
}
})
});
app.listen(PORT, function(){
console.log("server is now running")
})