# HG changeset patch # User Ludovic Chabant # Date 1392007582 28800 # Node ID cbf7db1ff0d5055b989999062f6697db0fd2d283 # Parent 964fd28e9b396755127ed4030eb796d1b84cfc90 Better authentication handling: - Not bundling user info with every response anymore. - Ability to optionally bundle user info with the page read API endpoint. - New API endpoint for current user info. diff -r 964fd28e9b39 -r cbf7db1ff0d5 wikked/assets/js/wikked/models.js --- a/wikked/assets/js/wikked/models.js Thu Feb 06 22:00:32 2014 -0800 +++ b/wikked/assets/js/wikked/models.js Sun Feb 09 20:46:22 2014 -0800 @@ -13,12 +13,11 @@ var exports = {}; var NavigationModel = exports.NavigationModel = Backbone.Model.extend({ - idAttribute: 'path', defaults: function() { return { path: "", action: "read", - user: false + username: false }; }, initialize: function() { @@ -26,12 +25,15 @@ model._onChangePath(path); }); this._onChangePath(this.get('path')); - this.on('change:auth', function(model, auth) { - model._onChangeAuth(auth); + this.on('change:user', function(model, auth) { + model._onChangeUser(auth); }); - this._onChangeAuth(this.get('auth')); + this._onChangeUser(this.get('user')); return this; }, + url: function() { + return '/api/user/info'; + }, doPreviewSearch: function(query, callback) { if (this._isSearching) { this._pendingQuery = query; @@ -78,18 +80,16 @@ this.doPreviewSearch(q, c); } }, - _onChangeAuth: function(auth) { - if (auth) { + _onChangeUser: function(user) { + if (user) { this.set({ url_login: false, - url_logout: '/#/logout', - username: auth.username + url_logout: '/#/logout' }); } else { this.set({ url_login: '/#/login', - url_logout: false, - username: false + url_logout: false }); } } @@ -189,7 +189,7 @@ var MasterPageModel = exports.MasterPageModel = PageModel.extend({ initialize: function() { - this.nav = new NavigationModel({ id: this.id }); + this.nav = new NavigationModel({ path: this.id }); this.footer = new FooterModel(); MasterPageModel.__super__.initialize.apply(this, arguments); this.on('change:auth', function(model, auth) { @@ -253,10 +253,21 @@ -1, 'cog'); }, + url: function() { + var url = PageReadModel.__super__.url.apply(this, arguments); + if (!this.nav.get('user')) { + url += '?user'; + } + return url; + }, checkStatePath: function() { return this.get('path'); }, _onChange: function() { + if (this.get('user')) { + // Forward user info to the navigation model. + this.nav.set('user', this.get('user')); + } if (this.getMeta('redirect')) { // Handle redirects. var newPath = this.getMeta('redirect').replace(/^\//, ""); diff -r 964fd28e9b39 -r cbf7db1ff0d5 wikked/assets/tpl/nav.html --- a/wikked/assets/tpl/nav.html Thu Feb 06 22:00:32 2014 -0800 +++ b/wikked/assets/tpl/nav.html Sun Feb 09 20:46:22 2014 -0800 @@ -24,8 +24,8 @@