* Renamed User.pushLocation() method to User.setLocation() and User.popLocation() to User.getLocation()

* Modified location setting and getting to achieve adequate redirection after logging in, unsubscribing etc.
 * Removed obsolete code
This commit is contained in:
Tobi Schäfer 2008-05-12 17:37:17 +00:00
parent e2a849b2cc
commit d44e34dd1d
5 changed files with 17 additions and 35 deletions

View file

@ -45,24 +45,6 @@ HopObject.prototype.map = function(values) {
}
HopObject.prototype.onRequest = function() {
if (req.postParams.cancel) {
switch (this.constructor) {
case Admin:
res.redirect(req.action + "?page=" + req.queryParams.page +
"#" + req.queryParams.id);
case File:
res.redirect(res.handlers.files.href());
case Members:
case Membership:
res.redirect(this._parent.href());
case Skin:
case Skins:
res.redirect(Skins.getRedirectUrl(req.postParams));
default:
res.redirect(this.href());
}
}
User.autoLogin();
res.handlers.membership = User.getMembership();
@ -84,22 +66,21 @@ HopObject.prototype.onRequest = function() {
if (!this.getPermission(req.action)) {
if (!session.user) {
User.setLocation(root.href() + req.path);
res.message = gettext("Please login first.");
res.redirect(res.handlers.site.members.href("login"));
}
User.getLocation();
res.status = 401;
res.write(gettext("Sorry, you are not allowed to access this part of the site."));
res.stop();
}
res.handlers.layout = res.handlers.site.layout || new Layout;
res.skinpath = res.handlers.layout.getSkinPath();
res.meta.values = {};
res.handlers.site.renderSkinAsString("Site#values");
// FIXME: remove after debugging
//res.contentType === "text/html" && res.debug(res.skinpath.toSource());
return;
}
@ -114,7 +95,7 @@ HopObject.prototype.delete_action = function() {
var parent = this._parent;
var url = this.constructor.remove.call(this, this) || parent.href();
res.message = gettext("{0} was successfully deleted.", str);
res.redirect(User.popLocation() || url);
res.redirect(User.getLocation() || url);
} catch(ex) {
res.message = ex;
app.log(ex);

View file

@ -83,7 +83,7 @@ Members.prototype.register_action = function() {
gettext('Welcome to "{0}"!', title));
res.message = gettext('Welcome to "{0}", {1}. Have fun!',
title, user.name);
res.redirect(User.popLocation() || this._parent.href());
res.redirect(User.getLocation() || this._parent.href());
} catch (ex) {
app.log(ex);
res.message = ex;
@ -163,14 +163,12 @@ Members.prototype.login_action = function() {
var user = User.login(req.postParams);
res.message = gettext('Welcome to "{0}", {1}. Have fun!',
res.handlers.site.getTitle(), user.name);
res.redirect(User.popLocation() || this._parent.href());
res.redirect(User.getLocation() || this._parent.href());
} catch (ex) {
res.message = ex;
app.log(ex);
}
}
User.pushLocation();
session.data.token = User.getSalt();
res.data.action = this.href(req.action);
res.data.title = gettext("Login to {0}", this._parent.title);

View file

@ -475,14 +475,14 @@ Site.prototype.unsubscribe_action = function() {
Membership.remove(Membership.getByName(session.user.name));
res.message = gettext("Successfully unsubscribed from site {0}.",
this.title);
res.redirect(User.popLocation() || this.href());
res.redirect(User.getLocation() || this.href());
} catch (ex) {
app.log(ex)
res.message = ex.toString();
}
}
User.pushLocation();
User.setLocation();
res.data.title = gettext("Remove subscription to {0}", this.title);
res.data.body = this.renderSkinAsString("$HopObject#confirm", {
text: gettext('You are about to unsubscribe from site {0}.', this.title)

View file

@ -46,9 +46,9 @@ Story.prototype.getPermission = function(action) {
switch (action) {
case ".":
case "main":
return this.creator === session.user ||
return this.status !== Story.CLOSED ||
this.creator === session.user ||
Membership.require(Membership.MANAGER) ||
this.status !== Story.CLOSED ||
User.require(User.PRIVILEGED);
case "comment":
return this.site.commentMode === Site.ENABLED &&
@ -248,9 +248,10 @@ Story.prototype.rotate_action = function() {
}
Story.prototype.comment_action = function() {
// Check if user is logged in since we allow linking here for any user
if (!User.require(User.REGULAR)) {
User.pushLocation(this.href(req.action) + "#form");
res.message = gettext("Please login to add a comment.");
User.setLocation(this.href(req.action) + "#form");
res.message = gettext("Please login first.");
res.redirect(this.site.members.href("login"));
}
var comment = new Comment(this);

View file

@ -259,13 +259,15 @@ User.getMembership = function() {
return membership || new Membership;
}
User.pushLocation = function(url) {
User.setLocation = function(url) {
session.data.location = url || req.data.http_referer;
//app.debug("Pushed location " + session.data.location);
return;
}
User.popLocation = function() {
User.getLocation = function() {
var url = session.data.location;
delete session.data.location;
//app.debug("Popped location " + url);
return url;
}