Slight refactor

This commit is contained in:
2019-05-20 00:34:47 +10:00
parent e1c21f509e
commit 9bae98e055
2 changed files with 298 additions and 318 deletions
+8 -22
View File
@@ -10,8 +10,7 @@ let sendmail = require('sendmail')();
let { validateEmail } = require('../common/utilities.js'); let { validateEmail } = require('../common/utilities.js');
let { throttle, isThrottled } = require('../common/throttle.js'); let { throttle, isThrottled } = require('../common/throttle.js');
function signup(connection) { const signup = (connection) => (req, res) => {
return (req, res) => {
//formidable handles forms //formidable handles forms
let form = formidable.IncomingForm(); let form = formidable.IncomingForm();
@@ -89,16 +88,14 @@ function signup(connection) {
res.status(200).write('Verification email sent!'); res.status(200).write('Verification email sent!');
res.end(); res.end();
}); });
})
}); });
}); });
}); });
}); });
} });
} }
function verify(connection) { const verify = (connection) => (req, res) => {
return (req, res) => {
//get the saved data //get the saved data
let query = 'SELECT email, username, salt, hash, verify FROM signups WHERE email = ?;'; let query = 'SELECT email, username, salt, hash, verify FROM signups WHERE email = ?;';
@@ -134,11 +131,9 @@ function verify(connection) {
}); });
}); });
}); });
}
} }
function login(connection) { const login = (connection) => (req, res) => {
return (req, res) => {
//formidable handles forms //formidable handles forms
let form = formidable.IncomingForm(); let form = formidable.IncomingForm();
@@ -194,22 +189,18 @@ function login(connection) {
}); });
}); });
}); });
}
} }
function logout(connection) { const logout = (connection) => (req, res) => {
return (req, res) => {
let query = 'DELETE FROM sessions WHERE sessions.accountId IN (SELECT accounts.id FROM accounts WHERE email = ?) AND token = ?;'; let query = 'DELETE FROM sessions WHERE sessions.accountId IN (SELECT accounts.id FROM accounts WHERE email = ?) AND token = ?;';
connection.query(query, [req.body.email, req.body.token], (err) => { connection.query(query, [req.body.email, req.body.token], (err) => {
if (err) throw err; if (err) throw err;
}); });
res.end(); res.end();
}
} }
function passwordChange(connection) { const passwordChange = (connection) => (req, res) => {
return (req, res) => {
//formidable handles forms //formidable handles forms
let form = formidable.IncomingForm(); let form = formidable.IncomingForm();
@@ -272,11 +263,9 @@ function passwordChange(connection) {
}); });
}); });
}); });
}
} }
function passwordRecover(connection) { const passwordRecover = (connection) => (req, res) => {
return (req, res) => {
//formidable handles forms //formidable handles forms
let form = formidable.IncomingForm(); let form = formidable.IncomingForm();
@@ -344,11 +333,9 @@ function passwordRecover(connection) {
}); });
}); });
}); });
}
} }
function passwordReset(connection) { const passwordReset = (connection) => (req, res) => {
return (req, res) => {
//formidable handles forms //formidable handles forms
let form = formidable.IncomingForm(); let form = formidable.IncomingForm();
@@ -400,7 +387,6 @@ function passwordReset(connection) {
}); });
}); });
}); });
}
} }
module.exports = { module.exports = {
+3 -9
View File
@@ -4,8 +4,7 @@ require('dotenv').config();
//libraries //libraries
let formidable = require('formidable'); let formidable = require('formidable');
function profileCreate(connection) { const profileCreate = (connection) => (req, res) => {
return (req, res) => {
//formidable handles forms //formidable handles forms
let form = formidable.IncomingForm(); let form = formidable.IncomingForm();
@@ -16,7 +15,6 @@ function profileCreate(connection) {
//separate this section so it can be used elsewhere too //separate this section so it can be used elsewhere too
return profileCreateInner(connection, req, res, fields); return profileCreateInner(connection, req, res, fields);
}); });
};
} }
function profileCreateInner(connection, req, res, fields) { function profileCreateInner(connection, req, res, fields) {
@@ -51,8 +49,7 @@ function profileCreateInner(connection, req, res, fields) {
}); });
} }
function profileRequest(connection) { const profileRequest = (connection) => (req, res) => {
return (req, res) => {
//formidable handles forms //formidable handles forms
let form = formidable.IncomingForm(); let form = formidable.IncomingForm();
@@ -63,12 +60,9 @@ function profileRequest(connection) {
//separate this section so it can be used elsewhere too //separate this section so it can be used elsewhere too
return profileRequestInner(connection, req, res, fields); return profileRequestInner(connection, req, res, fields);
}); });
}; };
}
function profileRequestInner(connection, req, res, fields) { function profileRequestInner(connection, req, res, fields) {
//TODO: do something with the id and token provided
let query = 'SELECT * FROM profiles WHERE accountId IN (SELECT accounts.id FROM accounts WHERE username = ?);'; let query = 'SELECT * FROM profiles WHERE accountId IN (SELECT accounts.id FROM accounts WHERE username = ?);';
connection.query(query, [fields.username], (err, results) => { connection.query(query, [fields.username], (err, results) => {
if (err) throw err; if (err) throw err;