Skip to content

Commit f62f6e0

Browse files
Update models.py
1 parent ef1fb45 commit f62f6e0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

app/models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pyotp
55
import base64
66
import os
7+
from datetime import datetime
78

89
db = SQLAlchemy()
910

@@ -13,6 +14,9 @@ class User(UserMixin, db.Model):
1314
password_hash = db.Column(db.String(120), nullable=False)
1415
totp_secret = db.Column(db.String(32), nullable=True)
1516
totp_enabled = db.Column(db.Boolean, default=False)
17+
is_admin = db.Column(db.Boolean, default=False)
18+
created_at = db.Column(db.DateTime, default=datetime.utcnow)
19+
last_login = db.Column(db.DateTime, nullable=True)
1620

1721
def set_password(self, password):
1822
self.password_hash = generate_password_hash(password)
@@ -36,3 +40,13 @@ def get_totp_uri(self):
3640
name=self.username,
3741
issuer_name='DirectAdmin Email Forwarder'
3842
)
43+
44+
def to_dict(self):
45+
return {
46+
'id': self.id,
47+
'username': self.username,
48+
'is_admin': self.is_admin,
49+
'totp_enabled': self.totp_enabled,
50+
'created_at': self.created_at.isoformat() if self.created_at else None,
51+
'last_login': self.last_login.isoformat() if self.last_login else None
52+
}

0 commit comments

Comments
 (0)