summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfbin.py13
-rw-r--r--templates/login.tmpl3
2 files changed, 11 insertions, 5 deletions
diff --git a/fbin.py b/fbin.py
index 46845ea..8a77738 100755
--- a/fbin.py
+++ b/fbin.py
@@ -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>