Moving to somewhere a bit more sensible

This commit is contained in:
Andrew Hayward 2013-04-18 15:36:50 +01:00
Родитель 18a4735479
Коммит c7b8bf18bf
1 изменённых файлов: 59 добавлений и 59 удалений

Просмотреть файл

@ -4,39 +4,37 @@ const learners = db.model('Learner');
const guardians = db.model('Guardian');
const signupTokens = db.model('SignupToken');
module.exports = function (app) {
var validateEmail = function (email) {
var validateEmail = function (email) {
// TODO - make sure email is valid
return true;
}
}
var normalizeUsername = function (username) {
var normalizeUsername = function (username) {
// For now, just remove white space and lower case it
return (''+username).replace(/\s/g, '').toLowerCase();
}
}
var validateUsername = function (username) {
var validateUsername = function (username) {
// TODO - make sure username is valid
return true;
}
}
var generatePassword = function () {
var generatePassword = function () {
return 'GeneratedPassword';
}
}
var validatePassword = function (password) {
var validatePassword = function (password) {
// TODO - make sure password is valid
return true;
}
}
var generateToken = function () {
var generateToken = function () {
// There must be better ways of doing it than this!
var now = Date.now();
return ((Math.random() * now).toString(36) + '-' + (Math.random() * now).toString(36)).replace(/[^a-z0-9-]/ig, '-');
}
}
var extractUserData = function (user) {
var extractUserData = function (user) {
var userType = user.daoFactoryName.toLowerCase(),
userHome;
@ -58,12 +56,14 @@ module.exports = function (app) {
dependents: [],
home: userHome
};
}
}
var redirectUser = function (req, res, user, status) {
var redirectUser = function (req, res, user, status) {
req.session.user = extractUserData(user);
return res.redirect(req.session.user.home, status || 303);
}
}
module.exports = function (app) {
app.use(function(req, res, next) {
res.locals.user = req.session.user;