-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·125 lines (105 loc) · 3.64 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
#coding: utf-8
# Copyright 2011 ZYYX Inc.
#
# import GAE libraries
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import channel
from google.appengine.api import mail
# import std libs
import time
import random
import datetime
import pprint
import hashlib
# import application libs
import model
# import 3rd party libs
import tenjin
from tenjin.helpers import *
SERVICE_DOMAIN = "http://link-snap.appspot.com"
class Main(webapp.RequestHandler):
def get(self):
self.response.out.write(tenjin.Template('view/index.tenjin').render())
class PhoneFrame(webapp.RequestHandler):
def get(self):
hash = self.request.get('hash')
if hash.strip() == "":
self.response.out.write('"hash" parameter missing.')
return
vars = {"hash": hash}
self.response.out.write(tenjin.Template('view/phone_frame.tenjin').render(vars))
class Token(webapp.RequestHandler):
def get(self):
uname = self.request.get('user')
token = channel.create_channel(uname)
self.response.out.write('{"token": "' + token + '"}')
class Update(webapp.RequestHandler):
def get(self):
hash = self.request.get('hash')
if hash.strip() == "":
self.response.out.write('"hash" parameter missing.')
return
url = self.request.get('url')
if url.strip() == "":
self.response.out.write('"url" paramter missing.')
return
channel.send_message(hash, '{"url": "' + url + '"}')
class HashGen(webapp.RequestHandler):
def get(self):
hash = hashlib.md5(str(random.random()).encode('base64')).hexdigest()
self.response.out.write('{"hash": "' + hash + '"}')
class MailAddr(webapp.RequestHandler):
def get(self):
email = self.request.get('email')
if email.strip() == "":
self.response.out.write('"email" parameter missing.')
return
hash = self.request.get('hash')
if hash.strip() == "":
self.response.out.write('"hash" parameter missing.')
return
mail.send_mail(
sender = "noreply@link-snap.appspotmail.com",
to = email,
subject = "LinkSnap 待ち受け画面アドレス",
body = tenjin.Template('view/mail_body.tenjin').render({
"domain": SERVICE_DOMAIN,
"hash": str(hash)
})
)
self.response.out.write('{"result": 1}')
class LinkSnap(webapp.RequestHandler):
def get(self):
hash = self.request.get('hash')
if hash.strip() == "":
self.response.out.write('"hash" parameter missing.')
return
vars = {"hash": hash}
self.response.out.write(tenjin.Template('view/linksnap.tenjin').render(vars))
class Receiver(webapp.RequestHandler):
def get(self):
hash = self.request.get('hash')
if hash.strip() == "":
self.response.out.write('"hash" parameter missing.')
return
vars = {"hash": hash}
self.response.out.write(tenjin.Template('view/receiver.tenjin').render(vars))
def main():
application = webapp.WSGIApplication(
[
('/', Main),
('/phone_frame', PhoneFrame),
('/update', Update),
('/token', Token),
('/hashgen', HashGen),
('/mailaddr', MailAddr),
('/linksnap', LinkSnap),
('/receiver', Receiver),
],
debug = True
)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()