Skip to content

Commit

Permalink
Show guest user login modal if they try to access account page
Browse files Browse the repository at this point in the history
* If a not-logged in user goes to the account page view the browser
  route, show them the login modal. Display their account page on
  success
  • Loading branch information
Alice Rottersman committed Oct 13, 2017
1 parent d9f676e commit cec6110
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/mmw/js/src/account/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var App = require('../app'),
views = require('./views'),
models = require('./models'),
router = require('../router').router,
coreUtils= require('../core/utils');

var AccountController = {
Expand All @@ -11,15 +12,7 @@ var AccountController = {
},

account: function() {
App.rootView.footerRegion.show(
new views.AccountContainerView({
model: new models.AccountContainerModel()
})
);

App.rootView.layerPickerRegion.empty();

App.state.set('active_page', coreUtils.accountPageTitle);
showLoginOrAccountView();
},

accountCleanUp: function() {
Expand All @@ -28,6 +21,32 @@ var AccountController = {
}
};

function showAccountView() {
App.rootView.footerRegion.show(
new views.AccountContainerView({
model: new models.AccountContainerModel()
})
);
App.rootView.layerPickerRegion.empty();

App.state.set('active_page', coreUtils.accountPageTitle);
}

function showLoginOrAccountView() {
App.user.fetch().always(function() {
if (App.user.get('guest')) {
var loginSuccess = function() {
router.navigate("/account", { trigger: true });
};
App.showLoginModal(loginSuccess);
// Until the user has logged in, show the main page
router.navigate("/", { trigger: true });
} else {
showAccountView();
}
});
}

module.exports = {
AccountController: AccountController
};

0 comments on commit cec6110

Please sign in to comment.