-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserhandler.py
94 lines (78 loc) · 2.55 KB
/
userhandler.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
import datetime
import jinja2
import logging
import os
import string
import webapp2
from utils import *
from dbmodels import *
from handlers import *
from google.appengine.ext import db
from google.appengine.api import images
from google.appengine.api import memcache
class UserHandler(ParentHandler):
def get(self, username):
if self.logged_in_user:
if self.logged_in_user.verified:
date_key = self.request.get('date')
if not date_key:
date_key = date_to_date_key(timezone_now().date())
user_done_list = DoneList.get_done_list(username, date_key)
this_user = User.get_user(username)
prev_date_key = DoneList.prev_date_key(this_user, date_key)
user_todo_list = TodoList.get_todo_list(this_user)
self.render_template('profile.html',
title = username,
user = self.logged_in_user,
this_user = this_user,
date_key = date_key,
start_date = date_to_date_key(this_user.date_created),
end_date = date_to_date_key(timezone_now().date()),
user_done_list = user_done_list,
user_todo_list = user_todo_list,
prev_date_key = prev_date_key)
else:
self.write_verify_page()
else:
self.redirect('/')
class VerifyHandler(ParentHandler):
def get(self, user_key):
if self.logged_in_user and not self.logged_in_user.verified:
if str(self.logged_in_user.key()) == user_key:
self.logged_in_user.verified = True
self.logged_in_user.put()
self.logged_in_user.set_user_caches()
self.redirect('/')
else:
self.redirect('/')
def post(self, user_key):
sendmail = self.request.get('sendmail')
if sendmail == "Yes":
self.logged_in_user.send_confirmation_mail()
self.redirect('/')
class ResetHandler(ParentHandler):
def write_reset_form(self, pwd_error = "", reset_msg = ""):
self.render_template('reset.html',
pwd_error = pwd_error,
reset_msg = reset_msg)
def get(self, user_key):
self.write_reset_form()
def post(self, user_key):
reset = self.request.get('reset')
password = self.request.get('password')
password_again = self.request.get('password_again')
if password != password_again:
pwd_error = "Passwords don't match."
self.write_reset_form(pwd_error = pwd_error)
elif not valid_password(password):
pwd_error = "That's not a valid password."
self.write_reset_form(pwd_error = pwd_error)
else:
logging.error(user_key)
user = db.get(user_key)
user.reset_pw(password)
user.put()
user.set_user_caches()
user.send_reset_success_mail()
reset_msg = "Password reset successful."
self.write_reset_form(reset_msg = reset_msg)