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 { throttle, isThrottled } = require('../common/throttle.js');
function signup(connection) {
return (req, res) => {
const signup = (connection) => (req, res) => {
//formidable handles forms
let form = formidable.IncomingForm();
@@ -89,16 +88,14 @@ function signup(connection) {
res.status(200).write('Verification email sent!');
res.end();
});
})
});
});
});
});
}
});
}
function verify(connection) {
return (req, res) => {
const verify = (connection) => (req, res) => {
//get the saved data
let query = 'SELECT email, username, salt, hash, verify FROM signups WHERE email = ?;';
@@ -134,11 +131,9 @@ function verify(connection) {
});
});
});
}
}
function login(connection) {
return (req, res) => {
const login = (connection) => (req, res) => {
//formidable handles forms
let form = formidable.IncomingForm();
@@ -194,22 +189,18 @@ function login(connection) {
});
});
});
}
}
function logout(connection) {
return (req, res) => {
const logout = (connection) => (req, res) => {
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) => {
if (err) throw err;
});
res.end();
}
}
function passwordChange(connection) {
return (req, res) => {
const passwordChange = (connection) => (req, res) => {
//formidable handles forms
let form = formidable.IncomingForm();
@@ -272,11 +263,9 @@ function passwordChange(connection) {
});
});
});
}
}
function passwordRecover(connection) {
return (req, res) => {
const passwordRecover = (connection) => (req, res) => {
//formidable handles forms
let form = formidable.IncomingForm();
@@ -344,11 +333,9 @@ function passwordRecover(connection) {
});
});
});
}
}
function passwordReset(connection) {
return (req, res) => {
const passwordReset = (connection) => (req, res) => {
//formidable handles forms
let form = formidable.IncomingForm();
@@ -400,7 +387,6 @@ function passwordReset(connection) {
});
});
});
}
}
module.exports = {
+3 -9
View File
@@ -4,8 +4,7 @@ require('dotenv').config();
//libraries
let formidable = require('formidable');
function profileCreate(connection) {
return (req, res) => {
const profileCreate = (connection) => (req, res) => {
//formidable handles forms
let form = formidable.IncomingForm();
@@ -16,7 +15,6 @@ function profileCreate(connection) {
//separate this section so it can be used elsewhere too
return profileCreateInner(connection, req, res, fields);
});
};
}
function profileCreateInner(connection, req, res, fields) {
@@ -51,8 +49,7 @@ function profileCreateInner(connection, req, res, fields) {
});
}
function profileRequest(connection) {
return (req, res) => {
const profileRequest = (connection) => (req, res) => {
//formidable handles forms
let form = formidable.IncomingForm();
@@ -63,12 +60,9 @@ function profileRequest(connection) {
//separate this section so it can be used elsewhere too
return 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 = ?);';
connection.query(query, [fields.username], (err, results) => {
if (err) throw err;