-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppUser.py
109 lines (90 loc) · 3.23 KB
/
AppUser.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
from datetime import datetime
from datetime import timedelta
import urllib
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.api import mail
class AppUser(db.Model):
"""Stores extra User data for validation of events and features"""
id = db.UserProperty(auto_current_user=True)
verified = db.BooleanProperty(indexed=False)
banned = db.BooleanProperty(indexed=False)
premium = db.BooleanProperty(indexed=False)
goodEventsCount = db.IntegerProperty(indexed=False)
badEventsCount = db.IntegerProperty(indexed=False)
@staticmethod
def registerUser():
"""Constructor for the AppUser class"""
id=users.get_current_user()
key=id.email().split('@')[0]
user = AppUser(key_name=key)
user.id = id
user.verified=False
user.banned=False
user.premium=False
user.goodEventsCount=0
user.badEventsCount=0
user.put()
return user
@staticmethod
def getUser():
"""Gets the AppUser object of the current user. If they're not registered, this registers them"""
user = users.get_current_user()
userList = db.GqlQuery("SELECT * FROM AppUser WHERE id = :1 LIMIT 1",
user).fetch(1)
if userList == []: # Wasn't found
return AppUser.registerUser()
return userList[0]
@property
def getUserLink(self):
return """/User/"""+str(self.key().name())
@staticmethod
def getUserFromKey(key):
""" Retrieves an AppUser object from the """
#get(Key(key))
#return None if no user found
def banUser(self):
"""Initiates the banhammer"""
#ensure they're supposed to be here
if self.badEventsCount >= 3 and not self.banned:
self.banned=True
self.put()
message = mail.EmailMessage(
sender="Friends with Food Admin <[email protected]>",
subject="Your account has been flagged to be banned")
message.to = self.id.email()
message.cc = "[email protected]"
message.body = """
Dear %s:
Your account on Friends with Food has been flagged for
banning after being reported for several consecutive fake
events. Your account has been banned from creating new events.
If you feel that this is in error, please reply-all to this
message with an explanation.
Thanks,
The Friends with Food Team
""" % self.id.nickname()
message.send()
def promoteUser(self):
"""Users are rewarded with verified user status whenever they pay up or
make 3 good Events"""
#ensure they're supposed to be here and haven't been here before
if self.goodEventsCount >= 3 and not self.verified:
self.verifiedUser=True
self.put()
message = mail.EmailMessage(
sender="Friends with Food Admin <[email protected]>",
subject="Your account has been verified!")
message.to = self.id.email()
message.cc = "[email protected]"
message.body = """
Dear %s:
Your account on Friends with Food has been verified! Because you've
shown us so many good events, we've upgraded your account. Now, you'll
get notified of free food on campus ASAP! You'll also be able to verify
events so that everyone knows they're legit.
*With great power comes great responsibility*
Thanks,
The Friends with Food Team
""" % self.id.nickname()
message.send()