Skip to content
This repository
Browse code

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

  • Loading branch information...
commit d35db9b5eb14df51981f0a60e26380d6293d628c 2 parents 5ecf305 + 8dbce77
Brendon Hogger authored August 20, 2012
6  warp/common/avatar.py
@@ -75,6 +75,8 @@ class DBSession(Storm):
75 75
     avatar = Reference(avatar_id, Avatar.id)
76 76
     touched = Int(default_factory=nowstamp)
77 77
 
  78
+    isPersistent = Bool(default=False)
  79
+
78 80
     language = u"en_US"
79 81
     messages = None
80 82
     afterLogin = None
@@ -105,6 +107,10 @@ def getFlashMessages(self, clear=True):
105 107
     def hasAvatar(self):
106 108
         return self.avatar_id is not None
107 109
 
  110
+    def setPersistent(self, isPersistent):
  111
+        self.isPersistent = isPersistent
  112
+        runtime.avatar_store.commit()
  113
+
108 114
     def setAvatarID(self, avatarID):
109 115
         self.avatar_id = avatarID
110 116
         runtime.avatar_store.commit()
8  warp/webserver/auth.py
@@ -33,7 +33,7 @@ class LoginHandler(LoginBase):
33 33
 
34 34
     def doIt(self, request):
35 35
         if request.method != 'POST':
36  
-            return
  36
+            return False
37 37
 
38 38
         [email] = request.args.get('email', [None])
39 39
         [password] = request.args.get('password', [None])
@@ -41,7 +41,7 @@ def doIt(self, request):
41 41
         if not (email and password):
42 42
             request.session.addFlashMessage("Login failed: Email or password not given",
43 43
                                             _domain="_warp:login")
44  
-            return
  44
+            return False
45 45
 
46 46
         avatar = avatar_store.find(Avatar,
47 47
                                    Avatar.email == email.decode("utf-8")
@@ -52,11 +52,13 @@ def doIt(self, request):
52 52
         if avatar is None or not checker(avatar, password):
53 53
             request.session.addFlashMessage("Login failed: Email or password incorrect",
54 54
                                             _domain="_warp:login")
55  
-            return
  55
+            return False
56 56
 
57 57
         request.session.setAvatarID(avatar.id)
58 58
         request.avatar = request.session.avatar
59 59
 
  60
+        return True
  61
+
60 62
 
61 63
 class LogoutHandler(LoginBase):
62 64
 
3  warp/webserver/resource.py
@@ -35,9 +35,10 @@ def __init__(self):
35 35
         warpTemplateDir = self.warpTemplatePath.path
36 36
         templateLookup.__init__(directories=[siteTemplateDir, warpTemplateDir], output_encoding="utf-8")
37 37
 
  38
+        handle_login = config.get('loginHandler', self.handle_login)
38 39
 
39 40
         self.dispatch =  {
40  
-            '__login__': self.handle_login,
  41
+            '__login__': handle_login,
41 42
             '__logout__': self.handle_logout,
42 43
             '_comet': self.handle_comet,
43 44
             '_warp': self.handle_warpstatic,
24  warp/webserver/site.py
@@ -11,15 +11,18 @@ class WarpRequest(Request):
11 11
     def finish(self):
12 12
         rv = Request.finish(self)
13 13
 
14  
-        # Roll back and then commit, so that no transaction
15  
-        # is left open between requests.
16  
-        self.store.rollback()
17  
-        self.store.commit()
18  
-        
19  
-        # Some use cases involve setting store.request in
20  
-        # getRequestStore, so remove request.store here to
21  
-        # avoid a circular reference GC.
22  
-        del self.store
  14
+        # Some requests, like those for static files, don't have store
  15
+        store = getattr(self, 'store', None)
  16
+        if store:
  17
+            # Roll back and then commit, so that no transaction
  18
+            # is left open between requests.
  19
+            store.rollback()
  20
+            store.commit()
  21
+
  22
+            # Some use cases involve setting store.request in
  23
+            # getRequestStore, so remove request.store here to
  24
+            # avoid a circular reference GC.
  25
+            del self.store
23 26
 
24 27
         return rv
25 28
 
@@ -38,6 +41,9 @@ def getSession(self, uid):
38 41
         if session is None:
39 42
             raise KeyError(uid)
40 43
 
  44
+        if session.isPersistent:
  45
+            return session
  46
+
41 47
         if session.hasAvatar():
42 48
             maxAge = config.get("sessionMaxAge")
43 49
             if maxAge is not None and session.age() > maxAge:

0 notes on commit d35db9b

Please sign in to comment.
Something went wrong with that request. Please try again.