-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify_users_pending_approval.py
More file actions
41 lines (33 loc) · 1.18 KB
/
notify_users_pending_approval.py
File metadata and controls
41 lines (33 loc) · 1.18 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
from apps import mail
from flask_mail import Message
from apps.authentication.models import Users
import pytz
from datetime import datetime, timezone, timedelta
from apps import create_app
from apps.config import Config
from apps.audit_mixin import utcnow
def send_email():
app = create_app(Config)
if not app.config["MAIL_SENDTO"]:
return
with app.app_context():
# Consulta para pegar usuários pendentes de aprovação
users = Users.query.filter(
Users.category == "user",
Users.created_at <= utcnow() - timedelta(hours=1),
Users.active==True
).all()
if not users:
return "No users found."
body = "List of users pending approval:\n\n"
for user in users:
body += f"Name: {user.username}, Email: {user.email}, Created-At: {user.created_at}\n"
msg = Message(
subject="[Dashboard HackInSDN] Pending User Approvals",
sender=app.config['MAIL_USERNAME'],
recipients=[app.config['MAIL_SENDTO']],
body=body
)
mail.send(msg)
if __name__ == "__main__":
send_email()