Permalink
Browse files

Merge branch 'master' of github.com:brendonh/warp

  • Loading branch information...
2 parents 5ecf305 + 8dbce77 commit d35db9b5eb14df51981f0a60e26380d6293d628c @brendonh committed Aug 20, 2012
Showing with 28 additions and 13 deletions.
  1. +6 −0 warp/common/avatar.py
  2. +5 −3 warp/webserver/auth.py
  3. +2 −1 warp/webserver/resource.py
  4. +15 −9 warp/webserver/site.py
@@ -75,6 +75,8 @@ class DBSession(Storm):
avatar = Reference(avatar_id, Avatar.id)
touched = Int(default_factory=nowstamp)
+ isPersistent = Bool(default=False)
+
language = u"en_US"
messages = None
afterLogin = None
@@ -105,6 +107,10 @@ def getFlashMessages(self, clear=True):
def hasAvatar(self):
return self.avatar_id is not None
+ def setPersistent(self, isPersistent):
+ self.isPersistent = isPersistent
+ runtime.avatar_store.commit()
+
def setAvatarID(self, avatarID):
self.avatar_id = avatarID
runtime.avatar_store.commit()
@@ -33,15 +33,15 @@ class LoginHandler(LoginBase):
def doIt(self, request):
if request.method != 'POST':
- return
+ return False
[email] = request.args.get('email', [None])
[password] = request.args.get('password', [None])
if not (email and password):
request.session.addFlashMessage("Login failed: Email or password not given",
_domain="_warp:login")
- return
+ return False
avatar = avatar_store.find(Avatar,
Avatar.email == email.decode("utf-8")
@@ -52,11 +52,13 @@ def doIt(self, request):
if avatar is None or not checker(avatar, password):
request.session.addFlashMessage("Login failed: Email or password incorrect",
_domain="_warp:login")
- return
+ return False
request.session.setAvatarID(avatar.id)
request.avatar = request.session.avatar
+ return True
+
class LogoutHandler(LoginBase):
@@ -35,9 +35,10 @@ def __init__(self):
warpTemplateDir = self.warpTemplatePath.path
templateLookup.__init__(directories=[siteTemplateDir, warpTemplateDir], output_encoding="utf-8")
+ handle_login = config.get('loginHandler', self.handle_login)
self.dispatch = {
- '__login__': self.handle_login,
+ '__login__': handle_login,
'__logout__': self.handle_logout,
'_comet': self.handle_comet,
'_warp': self.handle_warpstatic,
@@ -11,15 +11,18 @@ class WarpRequest(Request):
def finish(self):
rv = Request.finish(self)
- # Roll back and then commit, so that no transaction
- # is left open between requests.
- self.store.rollback()
- self.store.commit()
-
- # Some use cases involve setting store.request in
- # getRequestStore, so remove request.store here to
- # avoid a circular reference GC.
- del self.store
+ # Some requests, like those for static files, don't have store
+ store = getattr(self, 'store', None)
+ if store:
+ # Roll back and then commit, so that no transaction
+ # is left open between requests.
+ store.rollback()
+ store.commit()
+
+ # Some use cases involve setting store.request in
+ # getRequestStore, so remove request.store here to
+ # avoid a circular reference GC.
+ del self.store
return rv
@@ -38,6 +41,9 @@ def getSession(self, uid):
if session is None:
raise KeyError(uid)
+ if session.isPersistent:
+ return session
+
if session.hasAvatar():
maxAge = config.get("sessionMaxAge")
if maxAge is not None and session.age() > maxAge:

0 comments on commit d35db9b

Please sign in to comment.