fixed 1495

v1.18.x
Julian Lam 11 years ago
parent 883978007d
commit b56df975e0

@ -186,7 +186,9 @@ var ajaxify = ajaxify || {};
if (data && data.status === 404) { if (data && data.status === 404) {
return ajaxify.go('404'); return ajaxify.go('404');
} else if (data && data.status === 403) { } else if (data && data.status === 403) {
return ajaxify.go('403'); app.alertError('[[global:please_log_in]]');
app.previousUrl = url;
return ajaxify.go('login');
} else if (data && data.status === 302) { } else if (data && data.status === 302) {
return ajaxify.go(data.responseJSON.slice(1)); return ajaxify.go(data.responseJSON.slice(1));
} else if (textStatus !== "abort") { } else if (textStatus !== "abort") {

@ -1,3 +1,6 @@
"use strict";
/* global define, app, RELATIVE_PATH */
define(function() { define(function() {
var Login = {}; var Login = {};
@ -6,11 +9,12 @@ define(function() {
e.preventDefault(); e.preventDefault();
var loginData = { var loginData = {
'username': $('#username').val(), 'username': $('#username').val(),
'password': $('#password').val(), 'password': $('#password').val(),
'remember': $('#remember').prop('checked'), 'remember': $('#remember').prop('checked'),
'_csrf': $('#csrf-token').val() '_csrf': $('#csrf-token').val()
}; },
previousUrl = $('input[name="previousUrl"]').val();
$('#login').attr('disabled', 'disabled').html('Logging in...'); $('#login').attr('disabled', 'disabled').html('Logging in...');
$('#login-error-notify').hide(); $('#login-error-notify').hide();
@ -21,7 +25,9 @@ define(function() {
data: loginData, data: loginData,
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
$('#login').html('Redirecting...'); $('#login').html('Redirecting...');
if(!app.previousUrl) { if (previousUrl) {
app.previousUrl = previousUrl;
} else if (!app.previousUrl) {
app.previousUrl = '/'; app.previousUrl = '/';
} }

@ -176,6 +176,9 @@ Controllers.login = function(req, res, next) {
data.token = res.locals.csrf_token; data.token = res.locals.csrf_token;
data.showResetLink = emailersPresent; data.showResetLink = emailersPresent;
data.allowLocalLogin = meta.config.allowLocalLogin === undefined || parseInt(meta.config.allowLocalLogin, 10) === 1; data.allowLocalLogin = meta.config.allowLocalLogin === undefined || parseInt(meta.config.allowLocalLogin, 10) === 1;
if (req.query.next) {
data.previousUrl = req.query.next;
}
res.render('login', data); res.render('login', data);
}; };

@ -15,6 +15,10 @@ var app,
middleware.isAdmin = function(req, res, next) { middleware.isAdmin = function(req, res, next) {
if (!req.user) {
return res.redirect('/login?next=admin');
}
user.isAdministrator((req.user && req.user.uid) ? req.user.uid : 0, function (err, isAdmin) { user.isAdministrator((req.user && req.user.uid) ? req.user.uid : 0, function (err, isAdmin) {
if (err) { if (err) {
return next(err); return next(err);

@ -99,7 +99,7 @@ middleware.checkGlobalPrivacySettings = function(req, res, next) {
if (res.locals.isAPI) { if (res.locals.isAPI) {
return res.json(403, 'not-allowed'); return res.json(403, 'not-allowed');
} else { } else {
return res.redirect('403'); return res.redirect('login?next=' + req.url);
} }
} }
@ -107,8 +107,13 @@ middleware.checkGlobalPrivacySettings = function(req, res, next) {
}; };
middleware.checkAccountPermissions = function(req, res, next) { middleware.checkAccountPermissions = function(req, res, next) {
// This middleware ensures that only the requested user and admins can pass
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
if (callerUID === 0) {
return res.redirect('/login?next=' + req.url);
}
// this function requires userslug to be passed in. todo: /user/uploadpicture should pass in userslug I think // this function requires userslug to be passed in. todo: /user/uploadpicture should pass in userslug I think
user.getUidByUserslug(req.params.userslug, function (err, uid) { user.getUidByUserslug(req.params.userslug, function (err, uid) {
if (err) { if (err) {

@ -31,7 +31,7 @@
function login(req, res, next) { function login(req, res, next) {
if(meta.config.allowLocalLogin !== undefined && parseInt(meta.config.allowLocalLogin, 10) === 0) { if(meta.config.allowLocalLogin !== undefined && parseInt(meta.config.allowLocalLogin, 10) === 0) {
return res.send(403); return res.send(404);
} }
passport.authenticate('local', function(err, userData, info) { passport.authenticate('local', function(err, userData, info) {

Loading…
Cancel
Save