-
Notifications
You must be signed in to change notification settings - Fork 10
/
utilities.py
31 lines (26 loc) · 970 Bytes
/
utilities.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
import random
from flask_mail import Message
from apps import App
import string
class Utilities:
app = App()
mail = app.mail
mongo = app.mongo
def send_email(self, email):
msg = Message()
msg.subject = "BURNOUT - Reset Password Request"
msg.sender = '[email protected]'
msg.recipients = [email]
random = str(self.get_random_string(8))
msg.body = 'Please use the following password to login to your account: ' + random
self.mongo.db.ath.update({'email': email}, {'$set': {'temp': random}})
if self.mail.send(msg):
return "success"
else:
return "failed"
def get_random_string(self, length):
# choose from all lowercase letter
letters = string.ascii_lowercase
result_str = ''.join(random.choice(letters) for i in range(length))
print("Random string of length", length, "is:", result_str)
return result_str