|
Revision 676, 2.0 kB
(checked in by sylvain, 7 months ago)
|
updated for CherryPy? 3.1
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
import cherrypy |
|---|
| 4 |
import oidtool |
|---|
| 5 |
|
|---|
| 6 |
class Auth: |
|---|
| 7 |
@cherrypy.expose |
|---|
| 8 |
def login(self): |
|---|
| 9 |
return """<html> |
|---|
| 10 |
<head /> |
|---|
| 11 |
<body> |
|---|
| 12 |
<p>Enter your OpenID:</p> |
|---|
| 13 |
<form method="get" action="/"> |
|---|
| 14 |
<input type="text" name="openid_url" value="" /> |
|---|
| 15 |
<input type="submit" /> |
|---|
| 16 |
</form> |
|---|
| 17 |
</body> |
|---|
| 18 |
</html> |
|---|
| 19 |
""" |
|---|
| 20 |
|
|---|
| 21 |
@cherrypy.expose |
|---|
| 22 |
def logout(self): |
|---|
| 23 |
|
|---|
| 24 |
del cherrypy.session[oidtool.DEFAULT_SESSION_NAME] |
|---|
| 25 |
return "Disconnected" |
|---|
| 26 |
|
|---|
| 27 |
@cherrypy.expose |
|---|
| 28 |
def failure(self): |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
info = cherrypy.session[oidtool.DEFAULT_SESSION_NAME]['info'] |
|---|
| 32 |
return "Verification of %s failed." % info.identiy_url |
|---|
| 33 |
|
|---|
| 34 |
@cherrypy.expose |
|---|
| 35 |
def cancelled(self): |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
return "Verification cancelled" |
|---|
| 39 |
|
|---|
| 40 |
@cherrypy.expose |
|---|
| 41 |
def error(self): |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
return "An error happened during the authentication" |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
class Root: |
|---|
| 48 |
def __init__(self): |
|---|
| 49 |
|
|---|
| 50 |
self.connect = Auth() |
|---|
| 51 |
|
|---|
| 52 |
@cherrypy.expose |
|---|
| 53 |
def index(self): |
|---|
| 54 |
return "hello" |
|---|
| 55 |
|
|---|
| 56 |
@cherrypy.expose |
|---|
| 57 |
def echo(self, msg): |
|---|
| 58 |
return msg |
|---|
| 59 |
|
|---|
| 60 |
class Sub: |
|---|
| 61 |
@cherrypy.expose |
|---|
| 62 |
def index(self): |
|---|
| 63 |
return "meow" |
|---|
| 64 |
|
|---|
| 65 |
if __name__ == '__main__': |
|---|
| 66 |
from openid.store import filestore |
|---|
| 67 |
import tempfile |
|---|
| 68 |
store = filestore.FileOpenIDStore(tempfile.gettempdir()) |
|---|
| 69 |
|
|---|
| 70 |
cherrypy.tools.openid = oidtool.OpenIDTool(store, '/connect') |
|---|
| 71 |
|
|---|
| 72 |
conf = {'/': {'tools.sessions.on': True, |
|---|
| 73 |
'tools.sessions.storage_type': 'ram', |
|---|
| 74 |
'tools.openid.on': True}} |
|---|
| 75 |
|
|---|
| 76 |
root = Root() |
|---|
| 77 |
root.sub = Sub() |
|---|
| 78 |
cherrypy.quickstart(root, '/', config=conf) |
|---|