/
yoweb.py
executable file
·63 lines (54 loc) · 1.44 KB
/
yoweb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
import web
from yoracle import YOracle
class YOracleWebAuth:
"""YOracleWebAuth
Webpy handler for authenticating.
"""
def __init__(self):
self.db = web.database(dbn='sqlite',
db='yoracle.sqlite')
self.yoracle = YOracle(self.db)
def GET(self):
"""YOracleWebAuth.GET()
Handler for /auth/0/?token=%s
"""
token = web.input()['token']
try:
self.yoracle.verify(token)
return "OK"
except YOracle.ErrNOTICE, e:
if e.err is None:
web.ctx.status = '409 Conflict'
print "Notice:",e
return "NOTICE %s" % (e.args)
except YOracle.ErrBase, e:
web.ctx.status = '401 Unauthorized'
return "FAIL"
class Index:
def GET(self):
"""Index.GET()
Just present a form.
"""
return """
<html>
<head>
<title>YOracle web authentication</title>
</head>
<body>
<h1>YOracle web authentication</h1>
<form method='get' action='/auth/0/'>
<input type='password' name='token' />
</form>
</body>
</html>
"""
def webpy():
urls = (
r'/', Index,
r'/auth/0/', YOracleWebAuth,
)
app = web.application(urls, globals())
app.run()
if __name__ == '__main__':
webpy()