Slight refactor
This commit is contained in:
+8
-22
@@ -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 = ?;';
|
||||||
|
|
||||||
@@ -135,10 +132,8 @@ 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();
|
||||||
|
|
||||||
@@ -195,10 +190,8 @@ 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;
|
||||||
@@ -206,10 +199,8 @@ function logout(connection) {
|
|||||||
|
|
||||||
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();
|
||||||
|
|
||||||
@@ -273,10 +264,8 @@ 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();
|
||||||
|
|
||||||
@@ -345,10 +334,8 @@ 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();
|
||||||
|
|
||||||
@@ -401,7 +388,6 @@ function passwordReset(connection) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
signup: signup,
|
signup: signup,
|
||||||
|
|||||||
+2
-8
@@ -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();
|
||||||
|
|
||||||
@@ -64,11 +61,8 @@ function profileRequest(connection) {
|
|||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user