diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2012-05-23 18:38:39 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2012-05-23 18:38:39 +0200 |
commit | abf310d70377ce24edba54180804654301f971a8 (patch) | |
tree | acb77e58db23889880076d3b3758c572bda7bee7 | |
parent | 9f9645356bcd89a3ee93b9db39093c627eadf435 (diff) |
Redirect to login page and back to the original page afterwards when login is required.
-rwxr-xr-x | fbin.py | 13 | ||||
-rw-r--r-- | templates/login.tmpl | 3 |
2 files changed, 11 insertions, 5 deletions
@@ -284,12 +284,14 @@ class Application(object): c = Cookie.SimpleCookie(environ['HTTP_COOKIE'] if 'HTTP_COOKIE' in environ else None) user = self.validate_cookie(c) form = cgi.FieldStorage(fp = environ['wsgi.input'], environ = environ) + next = form.getvalue('next') if environ['REQUEST_METHOD'] != 'POST' or not 'username' in form or not 'password' in form: start_response('200 OK', [('Content-Type', 'text/html')]) return str(templates.login(searchList = { 'root': settings.virtual_root, 'user': user, 'error': None, + 'next': next, })) username = form.getvalue('username') @@ -303,6 +305,7 @@ class Application(object): 'root': settings.virtual_root, 'user': user, 'error': 'Login failed', + 'next': next, })) c = Cookie.SimpleCookie() @@ -315,7 +318,7 @@ class Application(object): c['identifier']['expires'] = expires start_response('302 Found', [ - ('Location', settings.virtual_root + 'u'), + ('Location', next if next else (settings.virtual_root + 'u')), ('Set-Cookie', c['uid'].OutputString()), ('Set-Cookie', c['identifier'].OutputString())]) return [] @@ -439,8 +442,8 @@ class Application(object): c = Cookie.SimpleCookie(environ['HTTP_COOKIE'] if 'HTTP_COOKIE' in environ else None) user = self.validate_cookie(c) if user == None: - start_response('200 OK', [('Content-Type', 'text/html')]) - return ['Not logged in.'] + start_response('302 Found', [('Location', settings.virtual_root + 'l?' + urllib.urlencode({'next': settings.virtual_root + 'm'}))]) + return [] files = self.get_files(user) start_response('200 OK', [('Content-Type', 'text/html')]) return str(templates.my(searchList = { @@ -454,8 +457,8 @@ class Application(object): c = Cookie.SimpleCookie(environ['HTTP_COOKIE'] if 'HTTP_COOKIE' in environ else None) user = self.validate_cookie(c) if user == None: - start_response('200 OK', [('Content-Type', 'text/html')]) - return ['Not logged in.'] + start_response('302 Found', [('Location', settings.virtual_root + 'l?' + urllib.urlencode({'next': settings.virtual_root + 'i'}))]) + return [] files = [f for f in self.get_files(user) if f.is_image()] start_response('200 OK', [('Content-Type', 'text/html')]) return str(templates.images(searchList = { diff --git a/templates/login.tmpl b/templates/login.tmpl index d8aaded..7638c07 100644 --- a/templates/login.tmpl +++ b/templates/login.tmpl @@ -5,6 +5,9 @@ #set error = $error or '' <div class="error">$error</div> <form method="post" action="${root}l"> +#if next + <input type="hidden" name="next" value="$next" /> +#end if <p>username</p> <p><input type="text" id="username" name="username" /></p> <p>password</p> |