]>
Commit | Line | Data |
---|---|---|
f065bc69 CP |
1 | from authgate import twisted as authgate |
2 | from twisted.web import resource, server, static | |
3 | import config, urlparse, urllib | |
4 | ||
5 | class AuthgateEngine(resource.Resource): | |
6 | isLeaf = True | |
7 | ||
8 | def __init__(self, prefix): | |
9 | self.__prefix = prefix | |
10 | ||
11 | def deleteCookie(self, request, key): | |
12 | request.addCookie(key, "", path="/", expires="Sat, 29 Jun 1996 01:44:48 GMT") | |
13 | ||
14 | def render_GET(self, request): | |
15 | if request.args.get("logout"): | |
16 | self.deleteCookie(request, "user") | |
17 | ||
18 | a = authgate(request, config.AUTHGATEDOMAIN) | |
19 | try: | |
20 | ticket = a.login_required(accepting=lambda x: True) | |
21 | except a.redirect_exception, e: | |
22 | pass | |
23 | else: | |
24 | # only used for informational purposes, the backend stores this seperately | |
25 | # so if the user changes it just their front end will be messed up! | |
26 | request.addCookie("user", ticket.username, path="/") | |
27 | ||
28 | location = request.getCookie("redirect") | |
29 | if location is None: | |
30 | location = "/" | |
31 | else: | |
32 | self.deleteCookie(request, "redirect") | |
33 | _, _, path, params, query, _ = urlparse.urlparse(urllib.unquote(location)) | |
34 | location = urlparse.urlunparse(("", "", path, params, query, "")) | |
35 | ||
36 | request.redirect(location) | |
37 | request.finish() | |
38 | ||
39 | return server.NOT_DONE_YET | |
40 | ||
41 | def getSessionData(request): | |
42 | return authgate.get_session_data(request) | |
43 | ||
44 | def login_optional(request): | |
45 | return authgate(request, config.AUTHGATEDOMAIN).login_optional() | |
46 |