summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2014-03-25 17:54:33 +0200
committerGarren Smith <garren.smith@gmail.com>2014-03-25 17:54:33 +0200
commit198bea3479dfecac13ab1a3e95f902b8eba02f7d (patch)
treede96e1c9ec1326681f73d012b5106ab117b26008
parent0f7be287d6a9358d960beb17b16ad7b5e20bd360 (diff)
downloadcouchdb-198bea3479dfecac13ab1a3e95f902b8eba02f7d.tar.gz
Fauxton: Redirected to correct page after login
Fixes COUCHDB-2209
-rw-r--r--src/fauxton/app/addons/auth/base.js3
-rw-r--r--src/fauxton/app/addons/auth/resources.js21
-rw-r--r--src/fauxton/app/addons/auth/routes.js13
-rw-r--r--src/fauxton/app/addons/auth/templates/noAccess.html4
-rw-r--r--src/fauxton/app/core/auth.js2
5 files changed, 36 insertions, 7 deletions
diff --git a/src/fauxton/app/addons/auth/base.js b/src/fauxton/app/addons/auth/base.js
index c7bbb04c4..b8545fcda 100644
--- a/src/fauxton/app/addons/auth/base.js
+++ b/src/fauxton/app/addons/auth/base.js
@@ -52,7 +52,8 @@ function(app, FauxtonAPI, Auth) {
};
var authDenied = function () {
- FauxtonAPI.navigate('/noAccess', {replace: true});
+ var url = window.location.hash.replace('#','');
+ FauxtonAPI.navigate('/noAccess?urlback=' + url, {replace: true});
};
FauxtonAPI.auth.registerAuth(auth);
diff --git a/src/fauxton/app/addons/auth/resources.js b/src/fauxton/app/addons/auth/resources.js
index 71744e37c..edfd70847 100644
--- a/src/fauxton/app/addons/auth/resources.js
+++ b/src/fauxton/app/addons/auth/resources.js
@@ -252,6 +252,9 @@ function (app, FauxtonAPI, CouchdbSession) {
Auth.LoginView = FauxtonAPI.View.extend({
template: 'addons/auth/templates/login',
+ initialize: function (options) {
+ this.urlBack = options.urlBack || "";
+ },
events: {
"submit #login": "login"
@@ -263,10 +266,16 @@ function (app, FauxtonAPI, CouchdbSession) {
var that = this,
username = this.$('#username').val(),
password = this.$('#password').val(),
+ urlBack = this.urlBack,
promise = this.model.login(username, password);
promise.then(function () {
FauxtonAPI.addNotification({msg: FauxtonAPI.session.messages.loggedIn });
+
+ if (urlBack) {
+ return FauxtonAPI.navigate(urlBack);
+ }
+
FauxtonAPI.navigate('/');
});
@@ -346,7 +355,17 @@ function (app, FauxtonAPI, CouchdbSession) {
});
Auth.NoAccessView = FauxtonAPI.View.extend({
- template: "addons/auth/templates/noAccess"
+ template: "addons/auth/templates/noAccess",
+
+ initialize: function (options) {
+ this.urlBack = options.urlBack || "";
+ },
+
+ serialize: function () {
+ return {
+ urlBack: this.urlBack
+ };
+ }
});
return Auth;
diff --git a/src/fauxton/app/addons/auth/routes.js b/src/fauxton/app/addons/auth/routes.js
index fe40a774d..74395e86d 100644
--- a/src/fauxton/app/addons/auth/routes.js
+++ b/src/fauxton/app/addons/auth/routes.js
@@ -21,15 +21,21 @@ function(app, FauxtonAPI, Auth) {
layout: 'one_pane',
routes: {
+ 'login?*extra': 'login',
'login': 'login',
'logout': 'logout',
'createAdmin': 'createAdmin',
+ 'noAccess?*extra': 'noAccess',
'noAccess': 'noAccess'
},
login: function () {
+ var urlBack = app.getParams().urlback;
this.crumbs = [{name: 'Login', link:"#"}];
- this.setView('#dashboard-content', new Auth.LoginView({model: FauxtonAPI.session}));
+ this.setView('#dashboard-content', new Auth.LoginView({
+ model: FauxtonAPI.session,
+ urlBack: urlBack
+ }));
},
logout: function () {
@@ -50,8 +56,11 @@ function(app, FauxtonAPI, Auth) {
},
noAccess: function () {
+ var urlBack = app.getParams().urlback;
this.crumbs = [{name: 'Access Denied', link:"#"}];
- this.setView('#dashboard-content', new Auth.NoAccessView());
+ this.setView('#dashboard-content', new Auth.NoAccessView({
+ urlBack: urlBack
+ }));
this.apiUrl = 'noAccess';
},
});
diff --git a/src/fauxton/app/addons/auth/templates/noAccess.html b/src/fauxton/app/addons/auth/templates/noAccess.html
index ceff99233..ffa736ed5 100644
--- a/src/fauxton/app/addons/auth/templates/noAccess.html
+++ b/src/fauxton/app/addons/auth/templates/noAccess.html
@@ -15,6 +15,8 @@ the License.
<div class="span12">
<h2> Access Denied </h2>
- <p> You do not have permission to view this page. <br/> You might need to <a href="#login"> login </a> to view this page/ </p>
+ <p> You do not have permission to view this page. <br/>
+ You might need to <a href="#login<% if (urlBack){ %>?urlback=<%=urlBack%> <% } %> "> login </a> to view this page/
+ </p>
</div>
diff --git a/src/fauxton/app/core/auth.js b/src/fauxton/app/core/auth.js
index 15cf5667f..19e4a8c99 100644
--- a/src/fauxton/app/core/auth.js
+++ b/src/fauxton/app/core/auth.js
@@ -60,8 +60,6 @@ function(FauxtonAPI, Backbone) {
}
});
-// FauxtonAPI.auth = new Auth();
-
return Auth;
});