Mercurial > hg > bitsyauth
comparison bitsyauth/__init__.py @ 21:74b8a8793414
whitespace cleanup
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Thu, 17 Nov 2011 11:20:03 -0800 |
| parents | 9f4369b769d0 |
| children | 871c040668c0 |
comparison
equal
deleted
inserted
replaced
| 20:9f4369b769d0 | 21:74b8a8793414 |
|---|---|
| 60 # WSGI app securely wrapped | 60 # WSGI app securely wrapped |
| 61 self.wrapped_app = self.security_wrapper() | 61 self.wrapped_app = self.security_wrapper() |
| 62 | 62 |
| 63 if not CAPTCHA: | 63 if not CAPTCHA: |
| 64 self.captcha = False | 64 self.captcha = False |
| 65 | 65 |
| 66 ### WSGI/HTTP layer | 66 ### WSGI/HTTP layer |
| 67 | 67 |
| 68 def __call__(self, environ, start_response): | 68 def __call__(self, environ, start_response): |
| 69 | 69 |
| 70 orig_environ = dict(environ) | 70 orig_environ = dict(environ) |
| 142 in self.urls.items() ]) | 142 in self.urls.items() ]) |
| 143 if self.captcha: | 143 if self.captcha: |
| 144 retval.update(dict([(('/join/%s.png' % key), 'image_captcha') | 144 retval.update(dict([(('/join/%s.png' % key), 'image_captcha') |
| 145 for key in self.keys])) | 145 for key in self.keys])) |
| 146 return retval | 146 return retval |
| 147 | 147 |
| 148 def get_response(self, text, content_type='text/html'): | 148 def get_response(self, text, content_type='text/html'): |
| 149 res = Response(content_type=content_type, body=text) | 149 res = Response(content_type=content_type, body=text) |
| 150 res.content_length = len(res.body) | 150 res.content_length = len(res.body) |
| 151 return res | 151 return res |
| 152 | 152 |
| 161 | 161 |
| 162 handler = url_lookup[path] | 162 handler = url_lookup[path] |
| 163 function = getattr(self, handler) | 163 function = getattr(self, handler) |
| 164 | 164 |
| 165 if self.request.method == 'GET': | 165 if self.request.method == 'GET': |
| 166 # XXX could/should do this with decorators | 166 # XXX could/should do this with decorators |
| 167 return self.get_response(function(wrap=True), | 167 return self.get_response(function(wrap=True), |
| 168 content_type=self.content_type.get(handler,'text/html')) | 168 content_type=self.content_type.get(handler,'text/html')) |
| 169 if self.request.method == 'POST': | 169 if self.request.method == 'POST': |
| 170 post_func = getattr(self, handler + "_post") | 170 post_func = getattr(self, handler + "_post") |
| 171 errors = post_func() | 171 errors = post_func() |
| 182 def image_captcha(self, wrap=True): | 182 def image_captcha(self, wrap=True): |
| 183 """return data for the image""" | 183 """return data for the image""" |
| 184 key = self.request.path_info.split('/join/')[-1] | 184 key = self.request.path_info.split('/join/')[-1] |
| 185 key = int(key.split('.png')[0]) | 185 key = int(key.split('.png')[0]) |
| 186 return skimpyAPI.Png(self.keys[key], scale=3.0).data() | 186 return skimpyAPI.Png(self.keys[key], scale=3.0).data() |
| 187 | 187 |
| 188 ### forms and their display methods | 188 ### forms and their display methods |
| 189 | 189 |
| 190 ### login | 190 ### login |
| 191 | 191 |
| 192 def login_form(self, referer=None, action=None): | 192 def login_form(self, referer=None, action=None): |
| 203 if hasattr(self, 'request'): | 203 if hasattr(self, 'request'): |
| 204 referer = self.request.referer | 204 referer = self.request.referer |
| 205 form = self.login_form(action=action, referer=referer) | 205 form = self.login_form(action=action, referer=referer) |
| 206 join = self.urls.get('join') | 206 join = self.urls.get('join') |
| 207 retval = form(errors) | 207 retval = form(errors) |
| 208 if join: | 208 if join: |
| 209 retval += '<br/>\n' + markup.a('join', href="%s" % join) | 209 retval += '<br/>\n' + markup.a('join', href="%s" % join) |
| 210 retval = markup.div(retval) | 210 retval = markup.div(retval) |
| 211 if wrap: | 211 if wrap: |
| 212 title = 'login' | 212 title = 'login' |
| 213 if self.site: | 213 if self.site: |
