-
-
Notifications
You must be signed in to change notification settings - Fork 376
Expand file tree
/
Copy pathlogin_log_service.py
More file actions
64 lines (55 loc) · 1.95 KB
/
Copy pathlogin_log_service.py
File metadata and controls
64 lines (55 loc) · 1.95 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
62
63
64
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime
from fastapi import Request
from sqlalchemy import Select
from sqlalchemy.ext.asyncio import AsyncSession
from backend.app.admin.crud.crud_login_log import login_log_dao
from backend.app.admin.schema.login_log import CreateLoginLogParam
from backend.common.log import log
from backend.database.db_mysql import async_db_session
class LoginLogService:
@staticmethod
async def get_select(*, username: str, status: int, ip: str) -> Select:
return await login_log_dao.get_list(username=username, status=status, ip=ip)
@staticmethod
async def create(
*,
db: AsyncSession,
request: Request,
user_uuid: str,
username: str,
login_time: datetime,
status: int,
msg: str,
) -> None:
try:
obj_in = CreateLoginLogParam(
user_uuid=user_uuid,
username=username,
status=status,
ip=request.state.ip,
country=request.state.country,
region=request.state.region,
city=request.state.city,
user_agent=request.state.user_agent,
browser=request.state.browser,
os=request.state.os,
device=request.state.device,
msg=msg,
login_time=login_time,
)
await login_log_dao.create(db, obj_in)
except Exception as e:
log.error(f'登录日志创建失败: {e}')
@staticmethod
async def delete(*, pk: list[int]) -> int:
async with async_db_session.begin() as db:
count = await login_log_dao.delete(db, pk)
return count
@staticmethod
async def delete_all() -> int:
async with async_db_session.begin() as db:
count = await login_log_dao.delete_all(db)
return count
login_log_service = LoginLogService()