xn-auth 0.2.32__tar.gz → 0.2.34__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xn_auth-0.2.32/xn_auth.egg-info → xn_auth-0.2.34}/PKG-INFO +1 -1
- {xn_auth-0.2.32 → xn_auth-0.2.34}/x_auth/models.py +32 -9
- {xn_auth-0.2.32 → xn_auth-0.2.34/xn_auth.egg-info}/PKG-INFO +1 -1
- {xn_auth-0.2.32 → xn_auth-0.2.34}/.env.dist +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/.gitignore +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/.pre-commit-config.yaml +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/README.md +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/makefile +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/pyproject.toml +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/setup.cfg +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/x_auth/controller.py +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/x_auth/enums.py +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/x_auth/exceptions.py +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/x_auth/middleware.py +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/x_auth/types.py +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/xn_auth.egg-info/SOURCES.txt +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/xn_auth.egg-info/dependency_links.txt +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/xn_auth.egg-info/requires.txt +0 -0
- {xn_auth-0.2.32 → xn_auth-0.2.34}/xn_auth.egg-info/top_level.txt +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
|
|
3
|
-
from aiogram.types import User as TgUser
|
|
4
|
-
from aiogram.utils.web_app import WebAppUser
|
|
5
3
|
from aiohttp import ClientSession
|
|
6
4
|
from msgspec import convert
|
|
5
|
+
from pyrogram.enums.client_platform import ClientPlatform
|
|
6
|
+
from pyrogram.types import User as TgUser
|
|
7
7
|
from tortoise.fields import (
|
|
8
8
|
BigIntField,
|
|
9
9
|
BooleanField,
|
|
@@ -14,6 +14,7 @@ from tortoise.fields import (
|
|
|
14
14
|
IntField,
|
|
15
15
|
BinaryField,
|
|
16
16
|
OneToOneRelation,
|
|
17
|
+
OneToOneNullableRelation,
|
|
17
18
|
OneToOneField,
|
|
18
19
|
SmallIntField,
|
|
19
20
|
BackwardOneToOneRelation,
|
|
@@ -21,6 +22,8 @@ from tortoise.fields import (
|
|
|
21
22
|
ForeignKeyNullableRelation,
|
|
22
23
|
JSONField,
|
|
23
24
|
)
|
|
25
|
+
from tortoise.fields.data import CharEnumFieldInstance
|
|
26
|
+
|
|
24
27
|
from x_auth import types
|
|
25
28
|
from x_model.field import DatetimeSecField
|
|
26
29
|
from x_model.models import Model, TsTrait
|
|
@@ -38,7 +41,7 @@ class Username(TortModel):
|
|
|
38
41
|
|
|
39
42
|
user: BackwardOneToOneRelation["User"]
|
|
40
43
|
peers: BackwardFKRelation["Peer"]
|
|
41
|
-
|
|
44
|
+
session: BackwardOneToOneRelation["Session"]
|
|
42
45
|
|
|
43
46
|
|
|
44
47
|
class User(Model):
|
|
@@ -56,9 +59,15 @@ class User(Model):
|
|
|
56
59
|
return AuthUser.model_validate(self, from_attributes=True)
|
|
57
60
|
|
|
58
61
|
@classmethod
|
|
59
|
-
async def tg2in(cls, u: TgUser
|
|
62
|
+
async def tg2in(cls, u: TgUser, blocked: bool = None) -> BaseUpd:
|
|
63
|
+
un, _ = await cls._meta.fields_map["username"].related_model.update_or_create({"username": u.username}, id=u.id)
|
|
60
64
|
user = cls.validate(
|
|
61
|
-
{
|
|
65
|
+
{
|
|
66
|
+
"first_name": u.first_name,
|
|
67
|
+
"last_name": u.last_name,
|
|
68
|
+
"username_id": un.id,
|
|
69
|
+
"lang": u.language_code and Lang[u.language_code],
|
|
70
|
+
}
|
|
62
71
|
)
|
|
63
72
|
if blocked is not None:
|
|
64
73
|
user.blocked = blocked
|
|
@@ -68,8 +77,15 @@ class User(Model):
|
|
|
68
77
|
async def is_blocked(cls, sid: str) -> bool:
|
|
69
78
|
return (await cls[int(sid)]).blocked
|
|
70
79
|
|
|
71
|
-
class Meta:
|
|
72
|
-
|
|
80
|
+
# class Meta:
|
|
81
|
+
# abstract = True
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# @pre_save(User)
|
|
85
|
+
# async def username(_meta, user: User, _db, _updated: dict) -> None:
|
|
86
|
+
# if user.username_id:
|
|
87
|
+
# return
|
|
88
|
+
# user.username = await Username.create(name=user.username)
|
|
73
89
|
|
|
74
90
|
|
|
75
91
|
class Country(Model):
|
|
@@ -144,6 +160,9 @@ class Proxy(Model, TsTrait):
|
|
|
144
160
|
reps = [convert(r, types.Replacement) for r in lst]
|
|
145
161
|
return reps
|
|
146
162
|
|
|
163
|
+
def dict(self):
|
|
164
|
+
return dict(scheme="socks5", hostname=self.host, port=self.port, username=self.username, password=self.password)
|
|
165
|
+
|
|
147
166
|
|
|
148
167
|
class Dc(TortModel):
|
|
149
168
|
id: int = SmallIntField(True)
|
|
@@ -151,6 +170,7 @@ class Dc(TortModel):
|
|
|
151
170
|
pub = CharField(495, null=True)
|
|
152
171
|
|
|
153
172
|
apps: BackwardFKRelation["App"]
|
|
173
|
+
sessions: BackwardFKRelation["App"]
|
|
154
174
|
|
|
155
175
|
|
|
156
176
|
class Fcm(TortModel):
|
|
@@ -169,7 +189,8 @@ class App(Model):
|
|
|
169
189
|
ver = CharField(18, default="0.0.1")
|
|
170
190
|
fcm: ForeignKeyNullableRelation[Fcm] = ForeignKeyField("models.Fcm", "apps", null=True)
|
|
171
191
|
fcm_id: int
|
|
172
|
-
|
|
192
|
+
platform: ClientPlatform = CharEnumFieldInstance(ClientPlatform)
|
|
193
|
+
owner: OneToOneNullableRelation["User"] = OneToOneField("models.User", "app", null=True)
|
|
173
194
|
|
|
174
195
|
sessions: BackwardFKRelation["Session"]
|
|
175
196
|
|
|
@@ -178,10 +199,12 @@ class Session(TortModel):
|
|
|
178
199
|
id = CharField(85, primary_key=True)
|
|
179
200
|
api: ForeignKeyRelation[App] = ForeignKeyField("models.App", "sessions")
|
|
180
201
|
api_id: int
|
|
202
|
+
dc: ForeignKeyRelation[Dc] = ForeignKeyField("models.Dc", "sessions", default=2)
|
|
203
|
+
dc_id: int
|
|
181
204
|
test_mode = BooleanField(default=False)
|
|
182
205
|
auth_key = BinaryField(null=True)
|
|
183
206
|
date = IntField(default=0) # todo: refact to datetime?
|
|
184
|
-
user:
|
|
207
|
+
user: OneToOneNullableRelation[Username] = OneToOneField("models.Username", "session", null=True)
|
|
185
208
|
user_id: int
|
|
186
209
|
is_bot = CharField(42, null=True)
|
|
187
210
|
state: dict = JSONField(default={})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|