Coverage for bc/kwai-bc-identity/src/kwai_bc_identity/tokens/user_log.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module that defines the UserLog entity.""" 

2 

3from dataclasses import dataclass, field 

4from typing import ClassVar, Type 

5 

6from kwai_core.domain.entity import DataclassEntity 

7from kwai_core.domain.value_objects.identifier import IntIdentifier 

8from kwai_core.domain.value_objects.timestamp import Timestamp 

9 

10from kwai_bc_identity.tokens.refresh_token import RefreshTokenEntity 

11from kwai_bc_identity.tokens.value_objects import IpAddress, OpenId 

12from kwai_bc_identity.users.user_account import UserAccountEntity 

13 

14 

15class UserLogIdentifier(IntIdentifier): 

16 """Identifier for a UserLog entity.""" 

17 

18 

19@dataclass(kw_only=True, eq=False, slots=True, frozen=True) 

20class UserLogEntity(DataclassEntity): 

21 """A UserLog entity. 

22 

23 Attributes: 

24 success: Was this user logged in successfully? 

25 email: Email used to log in. 

26 user_account: User account used to log in. 

27 refresh_token: Refresh token created for the login. 

28 client_ip: Client IP address 

29 user_agent: User agent string 

30 openid: OpenId information 

31 remark: A remark 

32 created_at: Timestamp of login 

33 """ 

34 

35 ID: ClassVar[Type] = UserLogIdentifier 

36 

37 success: bool = False 

38 email: str = "" 

39 user_account: UserAccountEntity | None = None 

40 refresh_token: RefreshTokenEntity | None = None 

41 client_ip: IpAddress 

42 user_agent: str 

43 openid: OpenId = field(default_factory=OpenId) 

44 remark: str = "" 

45 created_at: Timestamp = field(default_factory=Timestamp.create_now)