|
|
@ -34,43 +34,7 @@ app.use(sessions({
|
|
|
|
app.use(cookieParser());
|
|
|
|
app.use(cookieParser());
|
|
|
|
var session;
|
|
|
|
var session;
|
|
|
|
app.use(express.static(staticPath));
|
|
|
|
app.use(express.static(staticPath));
|
|
|
|
app.get('/bruh', function(req, res) {
|
|
|
|
|
|
|
|
var tagline;
|
|
|
|
|
|
|
|
var signup;
|
|
|
|
|
|
|
|
var loc;
|
|
|
|
|
|
|
|
if (req.session.userId) {
|
|
|
|
|
|
|
|
tagline = "logout";
|
|
|
|
|
|
|
|
signup = "hidden";
|
|
|
|
|
|
|
|
loc = "/__logout";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tagline = "log in";
|
|
|
|
|
|
|
|
loc = "login.html"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
res.render('pages/index', {
|
|
|
|
|
|
|
|
tagline: tagline,
|
|
|
|
|
|
|
|
signup: signup,
|
|
|
|
|
|
|
|
loc: loc
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/', function(req, res) {
|
|
|
|
|
|
|
|
console.log("Moving to a diff site");
|
|
|
|
|
|
|
|
var tagline;
|
|
|
|
|
|
|
|
var signup;
|
|
|
|
|
|
|
|
var loc;
|
|
|
|
|
|
|
|
if (req.session.userId) {
|
|
|
|
|
|
|
|
tagline = "logout";
|
|
|
|
|
|
|
|
signup = "hidden";
|
|
|
|
|
|
|
|
loc = "__logout";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tagline = "log in";
|
|
|
|
|
|
|
|
loc = "login.html";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
res.render('pages/index', {
|
|
|
|
|
|
|
|
tagline: tagline,
|
|
|
|
|
|
|
|
signup: signup,
|
|
|
|
|
|
|
|
loc: loc
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
const GLINK_SIZE = 6;
|
|
|
|
const GLINK_SIZE = 6;
|
|
|
|
function getRandomGLink() {
|
|
|
|
function getRandomGLink() {
|
|
|
|
let glink = "";
|
|
|
|
let glink = "";
|
|
|
@ -127,6 +91,8 @@ function filter(path) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function checkFileExistsSync(fp){
|
|
|
|
function checkFileExistsSync(fp){
|
|
|
|
let exists = true;
|
|
|
|
let exists = true;
|
|
|
|
|
|
|
|
console.log(staticPath + fp);
|
|
|
|
|
|
|
|
fp = staticPath + fp;
|
|
|
|
try{
|
|
|
|
try{
|
|
|
|
fs.accessSync(fp, fs.constants.F_OK);
|
|
|
|
fs.accessSync(fp, fs.constants.F_OK);
|
|
|
|
}catch(e){
|
|
|
|
}catch(e){
|
|
|
@ -159,6 +125,25 @@ app.get('/public/', (request, response) => {
|
|
|
|
|
|
|
|
|
|
|
|
const query = "INSERT INTO data (id, url, glink, time, isGeo, radius, latitude, longitude) VALUES (?, ?, ?, toTimestamp(now()), ?, ?, ?, ?)";
|
|
|
|
const query = "INSERT INTO data (id, url, glink, time, isGeo, radius, latitude, longitude) VALUES (?, ?, ?, toTimestamp(now()), ?, ?, ?, ?)";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/', function(req, res) {
|
|
|
|
|
|
|
|
console.log("Moving to a diff site");
|
|
|
|
|
|
|
|
var tagline;
|
|
|
|
|
|
|
|
var signup;
|
|
|
|
|
|
|
|
var loc;
|
|
|
|
|
|
|
|
if (req.session.userId) {
|
|
|
|
|
|
|
|
tagline = "logout";
|
|
|
|
|
|
|
|
signup = "hidden";
|
|
|
|
|
|
|
|
loc = "__logout";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tagline = "log in";
|
|
|
|
|
|
|
|
loc = "login.html";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
res.render('pages/index', {
|
|
|
|
|
|
|
|
tagline: tagline,
|
|
|
|
|
|
|
|
signup: signup,
|
|
|
|
|
|
|
|
loc: loc
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
app.post('/__add', function(req, res) {
|
|
|
|
app.post('/__add', function(req, res) {
|
|
|
|
session = req.session;
|
|
|
|
session = req.session;
|
|
|
|
console.log("add " + req.session);
|
|
|
|
console.log("add " + req.session);
|
|
|
@ -253,15 +238,16 @@ app.get('/__logout', function(req, res, cb) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.log("session invalid");
|
|
|
|
console.log("session invalid");
|
|
|
|
tagline = "log in";
|
|
|
|
tagline = "log in";
|
|
|
|
loc = "/login.html";
|
|
|
|
loc = "login.html";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.render('pages/index', {
|
|
|
|
// res.render('pages/index', {
|
|
|
|
tagline: tagline,
|
|
|
|
// tagline: tagline,
|
|
|
|
signup: signup,
|
|
|
|
// signup: signup,
|
|
|
|
loc: loc
|
|
|
|
// loc: loc
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
res.redirect("/");
|
|
|
|
console.log("done");
|
|
|
|
console.log("done");
|
|
|
|
|
|
|
|
res.end();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
app.post('/__check', function(req, res) {
|
|
|
|
app.post('/__check', function(req, res) {
|
|
|
|
let user_latitude = req.body.latitude;
|
|
|
|
let user_latitude = req.body.latitude;
|
|
|
@ -291,7 +277,7 @@ app.post('/__check', function(req, res) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
app.get('/__signup', function(req, res, cb) {
|
|
|
|
app.get('/__signup', function(req, res) {
|
|
|
|
console.log("Entered signup");
|
|
|
|
console.log("Entered signup");
|
|
|
|
let email = req.body.email;
|
|
|
|
let email = req.body.email;
|
|
|
|
let password = req.body.password;
|
|
|
|
let password = req.body.password;
|
|
|
@ -310,19 +296,19 @@ app.get('/__signup', function(req, res, cb) {
|
|
|
|
client.execute(add_qry, [id, email, hash], {prepare: true}, function(err, result) {
|
|
|
|
client.execute(add_qry, [id, email, hash], {prepare: true}, function(err, result) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
console.log(err.message);
|
|
|
|
console.log(err.message);
|
|
|
|
return cb("");
|
|
|
|
res.end();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.log("signed up");
|
|
|
|
console.log("signed up");
|
|
|
|
return cb("");
|
|
|
|
res.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.log("Passwords don't match");
|
|
|
|
console.log("Passwords don't match");
|
|
|
|
return cb("");
|
|
|
|
res.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
app.post('/__login', function(req, res, cb) {
|
|
|
|
app.post('/__login', function(req, res) {
|
|
|
|
console.log("entered login");
|
|
|
|
console.log("entered login");
|
|
|
|
let email = req.body.email;
|
|
|
|
let email = req.body.email;
|
|
|
|
let password = req.body.password;
|
|
|
|
let password = req.body.password;
|
|
|
@ -354,23 +340,59 @@ app.post('/__login', function(req, res, cb) {
|
|
|
|
req.session.userId = email;
|
|
|
|
req.session.userId = email;
|
|
|
|
session = req.session;
|
|
|
|
session = req.session;
|
|
|
|
console.log(req.session);
|
|
|
|
console.log(req.session);
|
|
|
|
|
|
|
|
res.redirect("/");
|
|
|
|
var tagline;
|
|
|
|
/*res.redirect("/index_1.html");*/
|
|
|
|
var signup;
|
|
|
|
res.end();
|
|
|
|
var loc;
|
|
|
|
|
|
|
|
if (req.session.userId) {
|
|
|
|
|
|
|
|
tagline = "logout";
|
|
|
|
|
|
|
|
signup = "hidden";
|
|
|
|
|
|
|
|
loc = "/__logout"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
tagline = "log in";
|
|
|
|
console.log("Wrong password");
|
|
|
|
loc = "login.html";
|
|
|
|
res.redirect("/login.html?error=auth");
|
|
|
|
|
|
|
|
res.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.render('pages/index', {
|
|
|
|
})
|
|
|
|
tagline: tagline,
|
|
|
|
.catch(err => {
|
|
|
|
signup: signup,
|
|
|
|
console.log(err.message);
|
|
|
|
loc: loc
|
|
|
|
res.end();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/__login', function(req, res) {
|
|
|
|
|
|
|
|
console.log("entered login");
|
|
|
|
|
|
|
|
let email = req.body.email;
|
|
|
|
|
|
|
|
let password = req.body.password;
|
|
|
|
|
|
|
|
/** Validate to make sure user-password exists */
|
|
|
|
|
|
|
|
let emailRX = new RegExp("^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z]+)+$");
|
|
|
|
|
|
|
|
let domainRX = new RegExp("[A-Za-z0-9!@#$%^&*]");
|
|
|
|
|
|
|
|
let minRXCharUp = new RegExp("[A-Z]");
|
|
|
|
|
|
|
|
let minRXCharLow = new RegExp("[a-z]");
|
|
|
|
|
|
|
|
let minRXNum = new RegExp("[0-9]");
|
|
|
|
|
|
|
|
let symRX = new RegExp("[!@#$%^&*]");
|
|
|
|
|
|
|
|
let selQry = "select password from account where email = ? allow filtering";
|
|
|
|
|
|
|
|
if (emailRX.test(email) && domainRX.test(password) && minRXNum.test(password) && minRXCharUp.test(password) && minRXCharLow.test(password) && symRX.test(password) && password.length >= 10) {
|
|
|
|
|
|
|
|
client.execute(selQry, [email], {}, function(error, result) {
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
|
|
console.log(error.message);
|
|
|
|
|
|
|
|
res.end();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (result.rows.length === 0) {
|
|
|
|
|
|
|
|
console.log("Wrong email");
|
|
|
|
|
|
|
|
res.redirect("/login.html?error=auth");
|
|
|
|
|
|
|
|
res.end();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let hash = result.rows[0]["password"];
|
|
|
|
|
|
|
|
console.log(password, hash);
|
|
|
|
|
|
|
|
bcrypt.compare(password, hash)
|
|
|
|
|
|
|
|
.then(match => {
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
|
|
|
|
console.log("Logged in");
|
|
|
|
|
|
|
|
req.session.userId = email;
|
|
|
|
|
|
|
|
session = req.session;
|
|
|
|
|
|
|
|
console.log(req.session);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.redirect("/");
|
|
|
|
/*res.redirect("/index_1.html");*/
|
|
|
|
/*res.redirect("/index_1.html");*/
|
|
|
|
res.end();
|
|
|
|
res.end();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -391,9 +413,8 @@ app.post('/__login', function(req, res, cb) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Redirect requests to corresponding entry in database */
|
|
|
|
/* Redirect requests to corresponding entry in database */
|
|
|
|
app.get('/*', (request, response, cb) => {
|
|
|
|
app.get('/*', (request, response) => {
|
|
|
|
console.log("Entered");
|
|
|
|
console.log("Entered");
|
|
|
|
let original_request = request.path;
|
|
|
|
let original_request = request.path;
|
|
|
|
console.log(original_request);
|
|
|
|
console.log(original_request);
|
|
|
@ -401,12 +422,14 @@ app.get('/*', (request, response, cb) => {
|
|
|
|
original_request = original_request.substring(0, original_request.length - 1);
|
|
|
|
original_request = original_request.substring(0, original_request.length - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let req_path = filter(original_request);
|
|
|
|
let req_path = filter(original_request);
|
|
|
|
|
|
|
|
console.log(checkFileExistsSync(original_request));
|
|
|
|
if (!req_path) {
|
|
|
|
if (!req_path) {
|
|
|
|
if (checkFileExistsSync(original_request)) {
|
|
|
|
if (checkFileExistsSync(original_request)) {
|
|
|
|
|
|
|
|
console.log(original_request + " unable");
|
|
|
|
response.redirect(original_request);
|
|
|
|
response.redirect(original_request);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
response.redirect("/error.html");
|
|
|
|
response.redirect("/error.html");
|
|
|
|
return cb("");
|
|
|
|
response.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let geoQry = "select isGeo from data where glink = ? allow filtering";
|
|
|
|
let geoQry = "select isGeo from data where glink = ? allow filtering";
|
|
|
|