| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- """密码历史CRUD"""
- from typing import Optional, List
- from sqlalchemy.orm import Session
- from app.models.models import SysPasswordHistory
- from app.crud.base import CRUDBase
- from app.core.utils import generate_id
- class PasswordHistoryCRUD(CRUDBase[SysPasswordHistory]):
- """密码历史CRUD操作"""
- def create_password_history(
- self,
- db: Session,
- user_id: str,
- operation_type: str,
- operator_id: str = None,
- operator_name: str = None,
- ip_address: str = None
- ) -> SysPasswordHistory:
- """创建密码修改历史"""
- history = SysPasswordHistory(
- id=generate_id(),
- user_id=user_id,
- operation_type=operation_type,
- operator_id=operator_id,
- operator_name=operator_name,
- ip_address=ip_address
- )
- db.add(history)
- db.commit()
- db.refresh(history)
- return history
- def get_user_history(self, db: Session, user_id: str, limit: int = 5) -> List[SysPasswordHistory]:
- """获取用户密码修改历史"""
- return db.query(SysPasswordHistory).filter(
- SysPasswordHistory.user_id == user_id,
- SysPasswordHistory.is_del == 0
- ).order_by(SysPasswordHistory.create_at.desc()).limit(limit).all()
- password_history_crud = PasswordHistoryCRUD(SysPasswordHistory)
|