forked from HKCodeCamp/vocably
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvocably.py
50 lines (41 loc) · 1.22 KB
/
vocably.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
from bottle import route, run, debug, template, request, static_file, redirect
from utils import vocably_oauth as oauth
# Landing Page
@route('/')
def home():
output = template('home')
return output
@route('/login')
def login():
print "Logging in a user: redirecting to Google"
redirect(oauth.authorization_url())
@route('/logout')
def logout():
oauth.deauthorize()
@route('/oauth2callback')
def login_callback():
print "Login callback from Google"
if request.query.error:
print "There was an error: '%s'" % request.query.error
print "Redirecting back to root"
redirect('/')
else:
print "Successfully acquired an authentication token"
oauth.authorize(request.query.code)
redirect('/emails')
@route('/emails')
def fetch_mail():
email_text = oauth.fetch_mail()
# Process big string here
redirect('/words')
# Static Files
@route('/css/:path#.+#', name='css')
def css(path):
return static_file(path, root='css')
@route('/img/:path#.+#', name='img')
def img(path):
return static_file(path, root='img')
@route('/js/:path#.+#', name='js')
def js(path):
return static_file(path, root='js')
run(host='0.0.0.0', port=8080, debug=True, reloader=True)