chiark / gitweb /
Return from login page to what you were trying to do
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 May 2008 15:39:42 +0000 (16:39 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 May 2008 15:39:42 +0000 (16:39 +0100)
lib/cgi.c
lib/cgi.h
server/actions.c

index 1d1ddd708e85725d45edc462ac182ca230d8bedd..c3a7680efef8d04a41fbb6544ac0db5ad6997f60 100644 (file)
--- a/lib/cgi.c
+++ b/lib/cgi.c
@@ -213,6 +213,11 @@ void cgi_set(const char *name, const char *value) {
   hash_add(cgi_args, name, &value, HASH_INSERT_OR_REPLACE);
 }
 
+/** @brief Clear CGI arguments */
+void cgi_clear(void) {
+  cgi_args = hash_new(sizeof (char *));
+}
+
 /** @brief Add SGML-style quoting
  * @param src String to quote (UTF-8)
  * @return Quoted string
@@ -354,7 +359,7 @@ char *cgi_thisurl(const char *url) {
     dynstr_append(d, n ? '&' : '?');
     dynstr_append_string(d, urlencodestring(keys[n]));
     dynstr_append(d, '=');
-    dynstr_append_string(d, cgi_get(keys[n]));
+    dynstr_append_string(d, urlencodestring(cgi_get(keys[n])));
   }
   dynstr_terminate(d);
   return d->vec;
index ec60482d8ec21e528a76847647f8183d1e0f158c..f8f5bf21ab7c4b5680434c61ba380bc68ca158f0 100644 (file)
--- a/lib/cgi.h
+++ b/lib/cgi.h
@@ -35,6 +35,7 @@ void cgi_opentag(struct sink *output, const char *name, ...);
 void cgi_closetag(struct sink *output, const char *name);
 char *cgi_makeurl(const char *url, ...);
 char *cgi_thisurl(const char *url);
+void cgi_clear(void);
 
 #endif
 
index c53575ee0c9d23fdd9d1b16052605229dfd6733d..90c5a1f459d34d81534360256f9d100051847567 100644 (file)
@@ -289,7 +289,11 @@ static void act_login(void) {
   if(!login_as(username, password)) {
     /* Report the succesful login */
     dcgi_status_string = "loginok";
-    dcgi_expand("login", 1);
+    /* Redirect back to where we came from, if necessary */
+    if(cgi_get("back"))
+      redirect(0);
+    else
+      dcgi_expand("login", 1);
   }
 }
 
@@ -651,8 +655,12 @@ void dcgi_action(const char *action) {
       /* Some right or other is required */
       dcgi_lookup(DCGI_RIGHTS);
       if(!(actions[n].rights & dcgi_rights)) {
+        const char *back = cgi_thisurl(config->url);
         /* Failed operations jump you to the login screen with an error
-         * message */
+         * message.  On success, the user comes back to the page they were
+         * after. */
+        cgi_clear();
+        cgi_set("back", back);
         login_error("noright");
         return;
       }