diff options
-rwxr-xr-x | fbin.py | 35 | ||||
-rw-r--r-- | templates/login.tmpl | 3 |
2 files changed, 32 insertions, 6 deletions
@@ -372,19 +372,29 @@ class Application(object): self.update_user_login(user) + rememberme = 'rememberme' in form + forever = 'forever' in form + c = Cookie.SimpleCookie() c['uid'] = user.id c['identifier'] = hashlib.sha1(str(user.id) + password).hexdigest() dt = datetime.datetime.utcnow() + datetime.timedelta(days = 30) expires = dt.strftime('%a, %d-%b-%y %H:%M:%S GMT') - c['uid']['expires'] = expires - c['identifier']['expires'] = expires - - start_response('302 Found', [ + if rememberme: + c['uid']['expires'] = expires + c['identifier']['expires'] = expires + if forever: + c['forever'] = 1 + c['forever']['expires'] = expires + + headers = [ ('Location', next if next else (settings.virtual_root + 'u')), ('Set-Cookie', c['uid'].OutputString()), - ('Set-Cookie', c['identifier'].OutputString())]) + ('Set-Cookie', c['identifier'].OutputString())] + if 'forever' in c: + headers.append(('Set-Cookie', c['forever'].OutputString())) + start_response('302 Found', headers) return [] def register(self, environ, start_response, path): @@ -432,9 +442,12 @@ class Application(object): c['uid']['expires'] = expires c['identifier'] = '' c['identifier']['expires'] = expires + c['forever'] = 0 + c['forever']['expires'] = expires start_response('302 Found', [ ('Set-Cookie', c['uid'].OutputString()), ('Set-Cookie', c['identifier'].OutputString()), + ('Set-Cookie', c['forever'].OutputString()), ('Location', settings.virtual_root)]) return [] @@ -631,11 +644,21 @@ class Application(object): a = api def __call__(self, environ, start_response): + def never_forget_wrapper(status, headers, exc_info = None): + c = Cookie.SimpleCookie(environ['HTTP_COOKIE'] if 'HTTP_COOKIE' in environ else None) + if 'forever' in c and c['forever'].value == '1' and not any(x[0] == 'Set-Cookie' for x in headers): + dt = datetime.datetime.utcnow() + datetime.timedelta(days = 30) + expires = dt.strftime('%a, %d-%b-%y %H:%M:%S GMT') + for k in c.keys(): + c[k]['path'] = settings.virtual_root + c[k]['expires'] = expires + headers.append(('Set-Cookie', c[k].OutputString())) + return start_response(status, headers, exc_info) try: path = environ['PATH_INFO'].split('/')[1:] module = path[0] if len(path) else '' if len(module) and module in 'fulshmitorcda': - return getattr(self, module)(environ, start_response, path) + return getattr(self, module)(environ, never_forget_wrapper, path) elif path == ['favicon.ico']: return self.static(environ, start_response, ['s'] + path) else: diff --git a/templates/login.tmpl b/templates/login.tmpl index e55600d..af2f955 100644 --- a/templates/login.tmpl +++ b/templates/login.tmpl @@ -12,6 +12,9 @@ <p><input type="text" id="username" name="username" /></p> <p>password</p> <p><input type="password" id="password" name="password" /></p> + <p><input type="checkbox" id="rememberme" name="rememberme" checked="checked" /> + <label for="rememberme"> remember me</label></p> + <p><input type="checkbox" id="forever" name="forever" /><label for="forever"> .. forever</label></p> <p><input type="submit" value="Login" /></p> </form> #end def |