Lekcja 2
This commit is contained in:
1 parent
0d1dce5535
commit
72ed8ef789
612 files changed
+64975
No files matched your search
@@ -0,0 +1,53 @@
|
||||
const express = require("express")
|
||||
const app = express()
|
||||
const PORT = 3000
|
||||
|
||||
const path = require("path")
|
||||
|
||||
app.use(express.urlencoded({
|
||||
extended: true
|
||||
}))
|
||||
|
||||
app.get("/", function (req, res) {
|
||||
res.sendFile(path.join(__dirname, '/static/add_user.html'))
|
||||
})
|
||||
|
||||
app.post("/handle_form", function (req, res) {
|
||||
let users = [
|
||||
{ nick: "111", email: "[email protected]" },
|
||||
{ nick: "222", email: "[email protected]" },
|
||||
{ nick: "333", email: "[email protected]" }
|
||||
]
|
||||
|
||||
let nick = req.body.nick
|
||||
let email = req.body.email
|
||||
|
||||
if (email == "") {
|
||||
res.send("Nie podano e-maila")
|
||||
} else {
|
||||
let email_in_database = false
|
||||
|
||||
for (let i = 0; i < users.length; i++) {
|
||||
if (email == users[i].email) {
|
||||
email_in_database = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (email_in_database) {
|
||||
res.send("E-mail istnieje już w bazie")
|
||||
} else {
|
||||
users.push({ nick: nick, email: email });
|
||||
res.send(users)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
app.use(express.static('static'))
|
||||
|
||||
app.listen(PORT, function () {
|
||||
console.log(PORT)
|
||||
})
|
||||
Reference in new issue
Block a user