forked from jeztek/imok_appengine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewuser.py
154 lines (131 loc) · 4.87 KB
/
newuser.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import os, datetime, sys
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template, util
from google.appengine.ext.webapp.util import login_required
from google.appengine.api import mail
# must import template before importing django stuff
from google.appengine.ext.db import djangoforms
try:
from django import newforms as forms
except ImportError:
from django import forms
import django.core.exceptions
import settings
from datastore import *
from imokutils import *
from imokforms import *
class NewUserProfileHandler(RequestHandlerPlus):
@login_required
def get(self):
newUser = True # hide some header links
user = users.get_current_user()
profile = getProfile(True)
phone = getPhone()
if phone:
initial = dict(phoneNumber=phone.number_str())
else:
initial = None
form = UserProfileForm(instance=profile, initial=initial)
turnOnSelection1 = "selectedNavItem"
self.render('newUserProfile.html', self.getContext(locals()))
def post(self):
user = users.get_current_user()
profile = getProfile(True)
form = UserProfileForm(data=self.request.POST, instance=profile)
if form.is_valid():
# Save the data and redirect to home
form.saveWithPhone()
self.redirect('/newuser/verifyPhone')
else:
# Reprint the form
turnOnSelection1 = "selectedNavItem"
self.render('newUserProfile.html', self.getContext(locals()))
class NewUserVerifyPhoneHandler(RequestHandlerPlus):
@login_required
def get(self):
newUser = True # hide some header links
phone = getPhone()
if not phone:
self.redirect('/newuser/profile')
return
turnOnSelection2 = "selectedNavItem"
self.render('newUserVerifyPhone.html', self.getContext(locals()))
def post(self):
self.redirect('/newuser/contacts')
class NewUserConfirmPhoneHandler(RequestHandlerPlus):
@login_required
def get(self):
newUser = True # hide some header links
phone = getPhone()
if not phone:
self.redirect('/newuser/profile')
return
turnOnSelection2 = "selectedNavItem"
self.render('newUserConfirmPhone.html', self.getContext(locals()))
def post(self):
if not users.get_current_user():
self.redirect('/')
return
phone = getPhone()
if not phone:
self.redirect('/newuser/profile')
return
errorlist = []
code = self.request.get('code', '')
if not code:
errorlist.append('Must enter a code')
elif len(code) != 4:
errorlist.append('Code is only 4 digits')
elif code != phone.code:
errorlist.append('Incorrect code')
if errorlist:
turnOnSelection2 = "selectedNavItem"
self.render('newUserConfirmPhone.html', self.getContext(locals()))
return
phone.code = ''
phone.verified = True
phone.put()
self.redirect('/newuser/contacts')
class NewUserContactsHandler(RequestHandlerPlus):
@login_required
def get(self):
newUser = True # hide some header links
registeredEmailQuery = RegisteredEmail.all().filter('userName =', users.get_current_user()).filter('blocked =', False).order('emailAddress')
registeredEmailList = registeredEmailQuery.fetch(100)
turnOnSelection3 = "selectedNavItem"
self.render('newUserContacts.html', self.getContext(locals()))
def post(self):
if not users.get_current_user():
self.redirect('/')
emailString = self.request.get('emailAddress')
emailError = getEmailErrorIfAny(emailString)
if not emailError:
if RegisteredEmail.all().filter('userName =', users.get_current_user()).filter('emailAddress =', emailString).count() > 0:
emailError = 'Email address already registered or unsubscribed.'
if not emailError:
newEmail = RegisteredEmail(userName=users.get_current_user(),
emailAddress=emailString,
uniqueId=RegisteredEmail.gen_unique_key())
newEmail.put()
registeredEmailQuery = RegisteredEmail.all().filter('userName =', users.get_current_user()).filter('blocked =', False).order('emailAddress')
registeredEmailList = registeredEmailQuery.fetch(100)
turnOnSelection3 = "selectedNavItem"
self.render('newUserContacts.html', self.getContext(locals()))
class NewUserDownloadHandler(RequestHandlerPlus):
@login_required
def get(self):
newUser = True # hide some header links
turnOnSelection4 = "selectedNavItem"
self.render('newUserDownload.html', self.getContext(locals()))
def main():
application = webapp.WSGIApplication([
('/newuser/profile', NewUserProfileHandler),
('/newuser/verifyPhone', NewUserVerifyPhoneHandler),
('/newuser/confirmPhone', NewUserConfirmPhoneHandler),
('/newuser/contacts', NewUserContactsHandler),
('/newuser/download', NewUserDownloadHandler),
], debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()