Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Commit

Permalink
fixed issue on login bad redirecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Camel Aissani committed Jan 8, 2017
1 parent 86c5a72 commit f032f5a
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions server/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ var config = require('../config'),
printManager = require('./managers/printmanager'),
logger = require('winston');

const defaultAdminView = 'dashboard';

const adminViews = [
'account',
// 'account',
'accounting',
'dashboard',
'occupant',
Expand All @@ -18,7 +20,7 @@ const adminViews = [
];

const allViews = [
'account',
// 'account',
'accounting',
'dashboard',
'login',
Expand All @@ -38,6 +40,7 @@ function render(model, res) {
model.isRealmSelected = model.account && model.account.realm;
model.isDefaultRealmSelected = model.isRealmSelected && model.account.realm.name === '__default_';
model.isMultipleRealmsAvailable = model.account && model.account.realms && model.account.realms.length > 1;
logger.debug(model);
res.render('index', model);
}

Expand Down Expand Up @@ -96,15 +99,13 @@ function PAGES(router) {
}

router.route('/index').get(rs.restrictedAreaAndRedirect, rs.mustRealmSetAndRedirect, function(req, res) {
var model = {
view: req.query.view,
account: req.session.user
},
isCurrentViewAuthorized = (adminViews.indexOf(model.view) !== -1);

if (!isCurrentViewAuthorized) {
res.redirect('/index?view=' + adminViews[0]);
logger.info('View ' + model.view + ' not authorized. Redirect to ' + '/index?view=' + adminViews[0]);
const model = {
view: req.query.view,
account: req.session.user
};
if (!model.view || adminViews.indexOf(model.view) === -1) {
res.redirect(`/index?view=${defaultAdminView}`);
logger.info(`View ${model.view} is not valid. Redirecting to /index?view=${defaultAdminView}`);
return;
}
render(model, res);
Expand Down

0 comments on commit f032f5a

Please sign in to comment.