Initial commit: enterprise digital platform with portal SSO, DigiServer, IT Assets, NetworkView, Server Monitor
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""User model for authentication and authorization."""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from flask_login import UserMixin
|
||||
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
class User(db.Model, UserMixin):
|
||||
"""User model for application authentication.
|
||||
|
||||
Attributes:
|
||||
id: Primary key
|
||||
username: Unique username for login
|
||||
password: Bcrypt hashed password
|
||||
role: User role (user or admin)
|
||||
theme: UI theme preference (light or dark)
|
||||
created_at: Account creation timestamp
|
||||
last_login: Last successful login timestamp
|
||||
"""
|
||||
__tablename__ = 'user'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
username = db.Column(db.String(80), unique=True, nullable=False, index=True)
|
||||
password = db.Column(db.String(120), nullable=False)
|
||||
role = db.Column(db.String(20), nullable=False, default='user', index=True)
|
||||
theme = db.Column(db.String(20), default='light')
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
||||
last_login = db.Column(db.DateTime, nullable=True)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""String representation of User."""
|
||||
return f'<User {self.username} (role={self.role})>'
|
||||
|
||||
@property
|
||||
def is_admin(self) -> bool:
|
||||
"""Check if user has admin role."""
|
||||
return self.role == 'admin'
|
||||
|
||||
def update_last_login(self) -> None:
|
||||
"""Update last login timestamp."""
|
||||
self.last_login = datetime.utcnow()
|
||||
Reference in New Issue
Block a user