-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_capturio.py
More file actions
70 lines (51 loc) · 2.11 KB
/
delete_capturio.py
File metadata and controls
70 lines (51 loc) · 2.11 KB
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
import logging, email, re
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
from google.appengine.api import mail
from google.appengine.ext import db
from config import Config
from models.user import User
from encryption import Encryption
class DeleteCapturioHandler(InboundMailHandler):
def receive(self, message):
logging.info("delete@captur.io request")
self.mail = message
self.senderMail = None
self.existingUser = None
self.responseMail = None
# We extract mail information with a regex
mailRegexMatch = re.search(r'[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}',self.mail.sender)
self.senderMail = mailRegexMatch.group()
logging.info("Received a message from: " + self.senderMail)
# We look if this user is in our database
user_query = User.all().filter("mail", self.senderMail)
self.existingUser = user_query.get()
# If the user is in our database, we build and send him a confirmation URL to delete his account
if(self.existingUser):
existingUserID = str(self.existingUser.key().id())
encryptedID = Encryption.getEncryptedIDForDeletion(existingUserID)
config = Config()
site_url = config.site_url
url = site_url + "delete?id=%s&crypt=%s" %(existingUserID, encryptedID)
logging.info("%s" % url)
self.responseMail = mail.EmailMessage(
sender = "Capturio crew <crew@captur.io>",
to = self.senderMail,
subject = "[Deletion] Please confirm to remove your information from Captur.io",
body = """
Hey,
If you want to remove all your information from Captur.io, please click on the following link: %s
We hope to see you again soon!
Captur.io crew
""" % (url)
)
self.responseMail.send()
logging.info("responseMail sent")
else:
logging.info("User behind address email %s wants to be removed whereas he doesn't belong to our database." % self.senderMail)
application = webapp.WSGIApplication([DeleteCapturioHandler.mapping()], debug=True)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()