-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
107 lines (89 loc) · 3.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
98
99
100
101
102
103
104
105
106
107
var express = require('express'),
request = require('request'),
bodyParser = require('body-parser'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
mysql = require('mysql');
con = mysql.createConnection({
host: "localhost",
user: "root",
database: "Hyperion"
});
app = express();
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({extended: true}));
app.get('/', function(req, res){
res.render('landing');
});
app.get('/about', function(req, res){
res.render('about');
});
app.get('/technology', function(req, res){
res.render('technology');
});
app.get('/user', function(req, res){
con.query("SELECT * FROM users WHERE Name = 'Ogechi Duru'", function (err, result, fields) {
if (err) throw err;
var user = result[0];
con.query("SELECT * FROM users WHERE NOT Name = '"+result[0]['Name']+"'", function (err, result, fields) {
var neighbors = result;
res.render('user', {user : user, neighbors: neighbors});
});
});
});
// app.get('/enter', function(req, res){
// res.render("enter");
// });
app.post('/register', function(req, res){
con.query("SELECT Email FROM users", function(err, result, fields){
if(err){
throw err;
} else {
for(var i = 0; i < result.length; i++){
if(result[i]['Email'] == req.body.newUser.email){
//alert('Email already exists');
res.redirect("enter");
return;
}
}
let name = req.body.newUser.name;
let location = req.body.newUser.location;
let email = req.body.newUser.email;
let password = req.body.newUser.password;
con.query("INSERT INTO `users` (`Name`, `Location`, `Email`, `Passwords`) VALUES ('"+name+"', '"+location+"', '"+email+"', '"+password+"')");
res.redirect("address");
}
});
//
// if()
// console.log(req.body.newUser.email);
// res.send("hi");
});
app.post('/login', function(req, res){
con.query("SELECT * FROM users", function(err, result, fields){
if(err){
throw err;
} else {
for(var i = 0; i < result.length; i++){
if(result[i]['Email'] == req.body.newUser.emaillogin){
if(result[i]['Passwords'] == req.body.newUser.passwordlogin){
var user = result[i];
con.query("SELECT * FROM users WHERE NOT Name = '"+result[i]['Name']+"'", function (err, result, fields) {
var neighbors = result;
console.log(neighbors);
//res.render('user', {user : user, neighbors: neighbors});
res.redirect
return 0;
});
}
}
}
res.redirect("enter");
//alert('Wrong email or password');
}
});
});
app.listen(4000, function(){
console.log("Started on port 4000");
});