Mercurial > hg > bitsyauth
changeset 5:2693b81f5960
fix redirection behaviour (though ultimately the whole class should be refactored not to store request on it)
author | k0s <k0scist@gmail.com> |
---|---|
date | Sat, 26 Dec 2009 22:56:56 -0500 |
parents | 4db4c02ed1ea |
children | 40fa556252a7 |
files | bitsyauth/__init__.py |
diffstat | 1 files changed, 11 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/bitsyauth/__init__.py Sat Dec 26 22:41:28 2009 -0500 +++ b/bitsyauth/__init__.py Sat Dec 26 22:56:56 2009 -0500 @@ -46,7 +46,6 @@ self.site = site or '' self.realm = realm or self.site self.captcha = True - self.redirect_to = '/' # redirect to site root self.urls = { 'login': '/login', 'join': '/join', } self.keys = {} # keys, words for CAPTCHA request @@ -70,6 +69,7 @@ self.request = Request(environ) self.request.path_info = self.request.path_info.rstrip('/') + self.redirect_to = self.request.script_name # URLs intrinsic to BitsyAuth if self.request.path_info == '/logout': @@ -168,11 +168,12 @@ if errors: return self.get_response(function(errors=errors, wrap=True)) else: - return self.redirect("Welcome!") + location = self.request.POST.get('referer') + return self.redirect("Welcome!", location=location) - def redirect(self, message=''): + def redirect(self, message='', location=None): """redirect from instrinsic urls""" - return exc.HTTPSeeOther(message, location=self.redirect_to) + return exc.HTTPSeeOther(message, location=location or self.redirect_to) def image_captcha(self, wrap=True): """return data for the image""" @@ -190,13 +191,17 @@ form = Form(action='', submit='Login') form.add_element('textfield', 'Name', input_name='username') form.add_element('password', 'Password', input_name='password') - if referer is not None: + if referer: form.add_element('hidden', 'referer', value=referer) return form def login(self, errors=None, wrap=False, action=None): """login div""" - form = self.login_form(action=action) + referer = None + if hasattr(self, 'request'): + referer = self.request.referer + + form = self.login_form(action=action, referer=referer) join = self.urls.get('join') retval = form(errors) if join: