xn-auth 0.2.46__tar.gz → 0.2.48__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.46/xn_auth.egg-info → xn_auth-0.2.48}/PKG-INFO +1 -1
- {xn_auth-0.2.46 → xn_auth-0.2.48}/x_auth/controller.py +18 -2
- {xn_auth-0.2.46 → xn_auth-0.2.48}/x_auth/models.py +5 -3
- {xn_auth-0.2.46 → xn_auth-0.2.48/xn_auth.egg-info}/PKG-INFO +1 -1
- {xn_auth-0.2.46 → xn_auth-0.2.48}/.env.dist +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/.gitignore +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/.pre-commit-config.yaml +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/README.md +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/makefile +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/pyproject.toml +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/setup.cfg +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/x_auth/enums.py +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/x_auth/exceptions.py +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/x_auth/middleware.py +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/x_auth/types.py +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/xn_auth.egg-info/SOURCES.txt +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/xn_auth.egg-info/dependency_links.txt +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/xn_auth.egg-info/requires.txt +0 -0
- {xn_auth-0.2.46 → xn_auth-0.2.48}/xn_auth.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from base64 import b64encode
|
|
2
2
|
from datetime import timedelta
|
|
3
3
|
|
|
4
|
+
from aiogram import Bot
|
|
5
|
+
from aiogram.exceptions import TelegramForbiddenError
|
|
4
6
|
from aiogram.utils.auth_widget import check_signature
|
|
5
7
|
from aiogram.utils.web_app import WebAppInitData, safe_parse_webapp_init_data, WebAppUser
|
|
6
8
|
from litestar import Response, post
|
|
@@ -18,7 +20,7 @@ async def retrieve_user_handler(token: Tok, _cn: ASGIConnection) -> AuthUser:
|
|
|
18
20
|
|
|
19
21
|
|
|
20
22
|
async def revoked_token_handler(token: Tok, _cn: ASGIConnection) -> bool:
|
|
21
|
-
return token.extras["blocked"]
|
|
23
|
+
return False # token.extras["blocked"]
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
class Auth:
|
|
@@ -38,11 +40,25 @@ class Auth:
|
|
|
38
40
|
async def user_proc(user: WebAppUser) -> Response[XyncUser]:
|
|
39
41
|
user_in = await user_model.tg2in(user)
|
|
40
42
|
db_user, cr = await user_model.update_or_create(**user_in.df_unq()) # on login: update user in db from tg
|
|
43
|
+
if user.allows_write_to_pm is None:
|
|
44
|
+
try:
|
|
45
|
+
await Bot(sec).send_chat_action(user.id, "typing")
|
|
46
|
+
db_user.blocked = False
|
|
47
|
+
except TelegramForbiddenError:
|
|
48
|
+
db_user.blocked = True
|
|
49
|
+
else:
|
|
50
|
+
db_user.blocked = not user.allows_write_to_pm
|
|
51
|
+
await db_user.save()
|
|
41
52
|
res = self.jwt.login(
|
|
42
53
|
identifier=str(db_user.id),
|
|
43
54
|
token_extras={"role": db_user.role, "blocked": db_user.blocked},
|
|
44
55
|
response_body=XyncUser.model_validate(
|
|
45
|
-
{
|
|
56
|
+
{
|
|
57
|
+
**user.model_dump(),
|
|
58
|
+
"xid": db_user.id,
|
|
59
|
+
"pub": db_user.pub and b64encode(db_user.pub),
|
|
60
|
+
"allows_write_to_pm": user.allows_write_to_pm or not db_user.blocked,
|
|
61
|
+
}
|
|
46
62
|
),
|
|
47
63
|
)
|
|
48
64
|
res.cookies[0].httponly = False
|
|
@@ -36,7 +36,7 @@ from x_auth.enums import Lang, Role, PeerType
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
class Username(TortModel):
|
|
39
|
-
id: int =
|
|
39
|
+
id: int = BigIntField(True, description="tg_id")
|
|
40
40
|
username: str = CharField(127, null=True)
|
|
41
41
|
phone = UInt8Field(null=True)
|
|
42
42
|
|
|
@@ -51,7 +51,7 @@ class User(Model):
|
|
|
51
51
|
first_name: str | None = CharField(63)
|
|
52
52
|
pic: str | None = CharField(127, null=True)
|
|
53
53
|
last_name: str | None = CharField(31, null=True)
|
|
54
|
-
blocked: bool = BooleanField(
|
|
54
|
+
blocked: bool = BooleanField(null=True)
|
|
55
55
|
lang: Lang | None = IntEnumField(Lang, default=Lang.ru, null=True)
|
|
56
56
|
role: Role = IntEnumField(Role, default=Role.READER)
|
|
57
57
|
prv = UniqBinaryField(unique=True, null=True) # len=32
|
|
@@ -68,7 +68,9 @@ class User(Model):
|
|
|
68
68
|
"last_name": u.last_name,
|
|
69
69
|
"username_id": un.id,
|
|
70
70
|
"lang": u.language_code and Lang[u.language_code],
|
|
71
|
-
"pic": hasattr(u, "photo_url")
|
|
71
|
+
"pic": hasattr(u, "photo_url")
|
|
72
|
+
and u.photo_url
|
|
73
|
+
and u.photo_url.replace("https://t.me/i/userpic/320/", "")[:-4],
|
|
72
74
|
}
|
|
73
75
|
)
|
|
74
76
|
if blocked is not None:
|
|
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
|