-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.py
More file actions
61 lines (48 loc) · 2.16 KB
/
user.py
File metadata and controls
61 lines (48 loc) · 2.16 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
import datetime
import smtplib
import os
import views.posts.post_database as pdb
import views.follow.follow_database as fdb
from views.email_verification.verification_database import *
class User:
def __init__(self, id, username, first_name, last_name, email):
self.id = id
self.username = username
self.first_name = first_name
self.last_name = last_name
self.email = email
self.fullname = self.first_name + ' ' + self.last_name
self.email_confirmed = email_confirmed(self)
self.posts = pdb.get_posts(self.id)
self.number_of_followers = fdb.count_followers(self.id)
def time_since_post(self, time_posted, current_time = int(datetime.datetime.now().timestamp())):
seconds_since_posted = current_time - time_posted
days_since_posted = int(seconds_since_posted/86400)
hours_since_posted = int(seconds_since_posted/3600)
minutes_since_posted = int(seconds_since_posted/60)
if days_since_posted:
return f"{days_since_posted} days"
elif hours_since_posted:
return f"{hours_since_posted} hours"
elif minutes_since_posted > 1:
return f"{minutes_since_posted} minutes"
elif minutes_since_posted == 1:
return f"{minutes_since_posted} minute"
else:
print('s', seconds_since_posted)
return "less than a minute"
def send_verification_email(self):
SLAKR_EMAIL_ADDRESS = os.environ.get('slakremail')
SLAKR_EMAIL_PASSWORD = os.environ.get('slakremailpassword')
with smtplib.SMTP('smtp.gmail.com', 587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(
SLAKR_EMAIL_ADDRESS,
SLAKR_EMAIL_PASSWORD
)
subject = 'Slakr Email Verification'
body = f'Verification Code:\n{vdb.get_verification_code(self)}'
msg = f'Subject: {subject}\n\n{body}'
smtp.sendmail(SLAKR_EMAIL_ADDRESS, self.email, msg)