mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 00:10:25 +01:00
initial login and register routes
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
var topicsController = require('./topics'),
|
var topicsController = require('./topics'),
|
||||||
categoriesController = require('./categories'),
|
categoriesController = require('./categories'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
|
auth = require('../routes/authentication'),
|
||||||
|
meta = require('../meta'),
|
||||||
|
plugins = require('../plugins'),
|
||||||
categories = require('../categories'),
|
categories = require('../categories'),
|
||||||
categoryTools = require('../categoryTools');
|
categoryTools = require('../categoryTools');
|
||||||
|
|
||||||
@@ -75,5 +78,67 @@ Controllers.home = function(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Controllers.login = function (req, res, next) {
|
||||||
|
var data = {},
|
||||||
|
login_strategies = auth.get_login_strategies(),
|
||||||
|
num_strategies = login_strategies.length,
|
||||||
|
emailersPresent = plugins.hasListeners('action:email.send');
|
||||||
|
|
||||||
|
if (num_strategies == 0) {
|
||||||
|
data = {
|
||||||
|
'login_window:spansize': 'col-md-12',
|
||||||
|
'alternate_logins': false
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
data = {
|
||||||
|
'login_window:spansize': 'col-md-6',
|
||||||
|
'alternate_logins': true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.authentication = login_strategies;
|
||||||
|
data.token = res.locals.csrf_token;
|
||||||
|
data.showResetLink = emailersPresent;
|
||||||
|
|
||||||
|
if (res.locals.isAPI) {
|
||||||
|
res.json(data);
|
||||||
|
} else {
|
||||||
|
res.render('login', data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Controllers.register = function (req, res, next) {
|
||||||
|
var data = {},
|
||||||
|
login_strategies = auth.get_login_strategies(),
|
||||||
|
num_strategies = login_strategies.length;
|
||||||
|
|
||||||
|
if (num_strategies == 0) {
|
||||||
|
data = {
|
||||||
|
'register_window:spansize': 'col-md-12',
|
||||||
|
'alternate_logins': false
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
data = {
|
||||||
|
'register_window:spansize': 'col-md-6',
|
||||||
|
'alternate_logins': true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.authentication = login_strategies;
|
||||||
|
|
||||||
|
data.token = res.locals.csrf_token;
|
||||||
|
data.minimumUsernameLength = meta.config.minimumUsernameLength;
|
||||||
|
data.maximumUsernameLength = meta.config.maximumUsernameLength;
|
||||||
|
data.minimumPasswordLength = meta.config.minimumPasswordLength;
|
||||||
|
data.termsOfUse = meta.config.termsOfUse;
|
||||||
|
|
||||||
|
if (res.locals.isAPI) {
|
||||||
|
res.json(data);
|
||||||
|
} else {
|
||||||
|
res.render('register', data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = Controllers;
|
module.exports = Controllers;
|
||||||
@@ -85,58 +85,6 @@ var path = require('path'),
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/login', function (req, res) {
|
|
||||||
var data = {},
|
|
||||||
login_strategies = auth.get_login_strategies(),
|
|
||||||
num_strategies = login_strategies.length,
|
|
||||||
emailersPresent = Plugins.hasListeners('action:email.send');
|
|
||||||
|
|
||||||
if (num_strategies == 0) {
|
|
||||||
data = {
|
|
||||||
'login_window:spansize': 'col-md-12',
|
|
||||||
'alternate_logins': false
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
data = {
|
|
||||||
'login_window:spansize': 'col-md-6',
|
|
||||||
'alternate_logins': true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data.authentication = login_strategies;
|
|
||||||
data.token = res.locals.csrf_token;
|
|
||||||
data.showResetLink = emailersPresent;
|
|
||||||
|
|
||||||
res.json(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/register', function (req, res) {
|
|
||||||
var data = {},
|
|
||||||
login_strategies = auth.get_login_strategies(),
|
|
||||||
num_strategies = login_strategies.length;
|
|
||||||
|
|
||||||
if (num_strategies == 0) {
|
|
||||||
data = {
|
|
||||||
'register_window:spansize': 'col-md-12',
|
|
||||||
'alternate_logins': false
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
data = {
|
|
||||||
'register_window:spansize': 'col-md-6',
|
|
||||||
'alternate_logins': true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data.authentication = login_strategies;
|
|
||||||
|
|
||||||
data.token = res.locals.csrf_token;
|
|
||||||
data.minimumUsernameLength = meta.config.minimumUsernameLength;
|
|
||||||
data.maximumUsernameLength = meta.config.maximumUsernameLength;
|
|
||||||
data.minimumPasswordLength = meta.config.minimumPasswordLength;
|
|
||||||
data.termsOfUse = meta.config.termsOfUse;
|
|
||||||
res.json(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/topic/:id/:slug?', function (req, res, next) {
|
app.get('/topic/:id/:slug?', function (req, res, next) {
|
||||||
var uid = req.user? parseInt(req.user.uid, 10) : 0;
|
var uid = req.user? parseInt(req.user.uid, 10) : 0;
|
||||||
var tid = req.params.id;
|
var tid = req.params.id;
|
||||||
|
|||||||
@@ -589,8 +589,8 @@ process.on('uncaughtException', function(err) {
|
|||||||
|
|
||||||
// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
|
// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
|
||||||
(function () {
|
(function () {
|
||||||
var routes = ['login', 'register', 'account', '403', '404', '500'],
|
var routes = ['register', 'account', '403', '404', '500'],
|
||||||
loginRequired = ['unread', 'notifications'];
|
loginRequired = ['notifications'];
|
||||||
|
|
||||||
async.each(routes.concat(loginRequired), function(route, next) {
|
async.each(routes.concat(loginRequired), function(route, next) {
|
||||||
app.get('/' + route, function (req, res) {
|
app.get('/' + route, function (req, res) {
|
||||||
@@ -620,6 +620,12 @@ process.on('uncaughtException', function(err) {
|
|||||||
app.get('/', app.buildHeader, controllers.home);
|
app.get('/', app.buildHeader, controllers.home);
|
||||||
app.get('/api/home', app.prepareAPI, controllers.home);
|
app.get('/api/home', app.prepareAPI, controllers.home);
|
||||||
|
|
||||||
|
app.get('/login', app.buildHeader, controllers.login);
|
||||||
|
app.get('/api/login', app.prepareAPI, controllers.login);
|
||||||
|
|
||||||
|
app.get('/register', app.buildHeader, controllers.register);
|
||||||
|
app.get('/api/register', app.prepareAPI, controllers.register);
|
||||||
|
|
||||||
app.get('/topic/:topic_id/:slug?', app.buildHeader, controllers.topics.get);
|
app.get('/topic/:topic_id/:slug?', app.buildHeader, controllers.topics.get);
|
||||||
app.get('/api/topic/:topic_id/:slug?', app.prepareAPI, controllers.topics.get);
|
app.get('/api/topic/:topic_id/:slug?', app.prepareAPI, controllers.topics.get);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user