File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from typing import Optional
2- from pydantic import BaseModel , Field , root_validator
2+ from pydantic import BaseModel , root_validator
33from assets .database import openDBConnection
44
55
66class apikey (BaseModel ):
7- ID : Optional [int ] = Field ( None , description = "" )
7+ ID : Optional [int ]
88 NAME : Optional [str ]
99 APIKEY : str
1010 PERMISSION : Optional [int ]
Original file line number Diff line number Diff line change 1+ from typing import Optional
2+ from pydantic import BaseModel , root_validator , ValidationError
3+ from assets .database import openDBConnection
4+
5+
6+ class SessionKey (BaseModel ):
7+ key : str
8+ valid : Optional [bool ] = False
9+
10+ @root_validator
11+ def check_session_key (cls , values ):
12+ db = openDBConnection ()
13+ cursor = db .cursor ()
14+
15+ cursor .execute ("SELECT SESSION_KEY FROM USERDATA WHERE SESSION_KEY = %s" , (values ['key' ],))
16+ data = cursor .fetchone ()
17+
18+ if data [0 ] is not None :
19+ values ['valid' ] = True
20+ return values
21+
22+ raise ValidationError ('SessionKey is not valid' )
23+
24+
25+ rakic = SessionKey (key = "d2587b14f80e1f07c1335184e89e7a6c2e6200626ae05d6b99c4d2354d789edd" )
26+
27+ print (rakic .valid )
You can’t perform that action at this time.
0 commit comments