-
Notifications
You must be signed in to change notification settings - Fork 0
/
invite.py
45 lines (34 loc) · 1.11 KB
/
invite.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
import json
import webapp2
import uuid
from google.appengine.ext.webapp import util
from google.appengine.api import users
import mail
from model import InviteToken
import utils
class InviteHandler(webapp2.RequestHandler):
def post(self):
"""Send an invitation mail to the provided email address"""
user = utils.get_current_user()
if not user:
self.error(403)
return
email = self.request.get('email')
token = uuid.uuid1().hex
mail.send_invite_email(email, token)
m = InviteToken(
sender=user.key().id(),
email=email,
token=token
)
m.put()
self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
self.response.headers['Access-Control-Allow-Origin'] = '*'
self.response.out.write(json.dumps({
'message': 'An invitation email was sent to %s' % email,
'email': email,
'token': token,
}))
app = webapp2.WSGIApplication([
('/invite', InviteHandler),
], debug=True)