-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
97 lines (71 loc) · 2.12 KB
/
app.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
const express = require('express');
const path = require('path');
const app = express();
let coordinates = [];
let coordinatesLogin = [];
const tol = 10;
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.urlencoded({ extended: true }));
app.set('view engine', 'ejs');
app.get('/favicon.ico', (req, res) => res.status(204));
app.get('/', (req, res) => {
res.render('home');
})
app.get('/register', (req, res) => {
res.render('register');
})
app.get('/login', (req, res) => {
res.render('login');
})
app.get('/verify', (req, res) => {
console.log(coordinates);
console.log(coordinatesLogin);
if (coordinates.length != coordinatesLogin.length)
res.render('error');
const n = coordinates.length;
let flag = true;
for (let i = 0; i < n; i++) {
const aX = Number(coordinates[i].X);
const bX = Number(coordinatesLogin[i].X);
const aY = Number(coordinates[i].Y);
const bY = Number(coordinatesLogin[i].Y);
if((bX > aX + tol) || (bX < aX - Number(tol))) {
flag = false;
console.log(aX + tol);
console.log(aX - tol);
console.log(bX);
break;
}
if((bY > aY + tol) ||( bY < aY - Number(tol))) {
flag = false;
console.log(aY);
console.log(bY);
break;
}
}
if(!flag)
context = {result: 'Error Wrong Passpoints!'};
else
context = {result: 'Success Login!'}
coordinates = [];
coordinatesLogin = [];
res.render('result', context);
})
app.post('/data', (req, res) => {
const imgX = req.body.imgX;
const imgY = req.body.imgY;
coordinates.push({ 'X': imgX, 'Y': imgY });
console.log(coordinates);
res.redirect('/register');
})
app.post('/dataLogin', (req, res) => {
const imgX = req.body.imgX;
const imgY = req.body.imgY;
coordinatesLogin.push({ 'X': imgX, 'Y': imgY });
console.log(coordinatesLogin);
res.redirect('/login');
})
app.listen(process.env.PORT || 8000, (err) => {
if (!err)
console.log("server running on port 8000");
})