xn-auth 0.2.49__tar.gz → 0.2.51__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.49/xn_auth.egg-info → xn_auth-0.2.51}/PKG-INFO +1 -1
- {xn_auth-0.2.49 → xn_auth-0.2.51}/x_auth/controller.py +3 -4
- {xn_auth-0.2.49 → xn_auth-0.2.51}/x_auth/enums.py +1 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/x_auth/models.py +20 -24
- {xn_auth-0.2.49 → xn_auth-0.2.51/xn_auth.egg-info}/PKG-INFO +1 -1
- {xn_auth-0.2.49 → xn_auth-0.2.51}/.env.dist +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/.gitignore +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/.pre-commit-config.yaml +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/README.md +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/makefile +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/pyproject.toml +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/setup.cfg +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/x_auth/exceptions.py +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/x_auth/middleware.py +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/x_auth/types.py +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/xn_auth.egg-info/SOURCES.txt +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/xn_auth.egg-info/dependency_links.txt +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/xn_auth.egg-info/requires.txt +0 -0
- {xn_auth-0.2.49 → xn_auth-0.2.51}/xn_auth.egg-info/top_level.txt +0 -0
|
@@ -2,7 +2,7 @@ from base64 import b64encode
|
|
|
2
2
|
from datetime import timedelta
|
|
3
3
|
|
|
4
4
|
from aiogram import Bot
|
|
5
|
-
from aiogram.exceptions import TelegramForbiddenError
|
|
5
|
+
from aiogram.exceptions import TelegramForbiddenError, TelegramBadRequest
|
|
6
6
|
from aiogram.utils.auth_widget import check_signature
|
|
7
7
|
from aiogram.utils.web_app import WebAppInitData, safe_parse_webapp_init_data, WebAppUser
|
|
8
8
|
from litestar import Response, post
|
|
@@ -38,13 +38,12 @@ class Auth:
|
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
async def user_proc(user: WebAppUser) -> Response[XyncUser]:
|
|
41
|
-
|
|
42
|
-
db_user, cr = await user_model.update_or_create(**user_in.df_unq()) # on login: update user in db from tg
|
|
41
|
+
db_user, cr = await user_model.tg_upsert(user) # on login: update user in db from tg
|
|
43
42
|
if user.allows_write_to_pm is None:
|
|
44
43
|
try:
|
|
45
44
|
await Bot(sec).send_chat_action(user.id, "typing")
|
|
46
45
|
db_user.blocked = False
|
|
47
|
-
except TelegramForbiddenError:
|
|
46
|
+
except (TelegramForbiddenError, TelegramBadRequest):
|
|
48
47
|
db_user.blocked = True
|
|
49
48
|
else:
|
|
50
49
|
db_user.blocked = not user.allows_write_to_pm
|
|
@@ -27,10 +27,9 @@ from tortoise.fields import (
|
|
|
27
27
|
from tortoise.fields.data import CharEnumFieldInstance
|
|
28
28
|
|
|
29
29
|
from x_auth import types
|
|
30
|
-
from x_model.field import DatetimeSecField, UInt8Field,
|
|
30
|
+
from x_model.field import DatetimeSecField, UInt8Field, UInt1Field, UInt2Field
|
|
31
31
|
from x_model.models import Model, TsTrait
|
|
32
32
|
from tortoise import Model as TortModel
|
|
33
|
-
from x_model.types import BaseUpd
|
|
34
33
|
|
|
35
34
|
from x_auth.enums import Lang, Role, PeerType
|
|
36
35
|
|
|
@@ -54,41 +53,38 @@ class User(Model):
|
|
|
54
53
|
blocked: bool = BooleanField(null=True)
|
|
55
54
|
lang: Lang | None = IntEnumField(Lang, default=Lang.ru, null=True)
|
|
56
55
|
role: Role = IntEnumField(Role, default=Role.READER)
|
|
57
|
-
prv = UniqBinaryField(unique=True, null=True) # len=32
|
|
58
|
-
pub = UniqBinaryField(unique=True, null=True) # len=32
|
|
59
56
|
|
|
60
57
|
app: BackwardOneToOneRelation["App"]
|
|
61
58
|
|
|
62
59
|
@classmethod
|
|
63
|
-
async def tg2in(cls, u: PyroUser | AioUser | WebAppUser, blocked: bool = None) ->
|
|
60
|
+
async def tg2in(cls, u: PyroUser | AioUser | WebAppUser, blocked: bool = None) -> dict:
|
|
64
61
|
un, _ = await cls._meta.fields_map["username"].related_model.update_or_create({"username": u.username}, id=u.id)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
and u.photo_url
|
|
73
|
-
and u.photo_url.replace("https://t.me/i/userpic/320/", "")[:-4],
|
|
74
|
-
}
|
|
62
|
+
pic = hasattr(u, "photo_url") and u.photo_url and u.photo_url.replace("https://t.me/i/userpic/320/", "")[:-4]
|
|
63
|
+
pic = (
|
|
64
|
+
pic
|
|
65
|
+
or isinstance(u, AioUser)
|
|
66
|
+
and (photos := (await u.bot.get_user_profile_photos(u.id)).photos)
|
|
67
|
+
and photos[0][-1].file_id
|
|
68
|
+
or None
|
|
75
69
|
)
|
|
70
|
+
user_dict = {
|
|
71
|
+
"first_name": u.first_name,
|
|
72
|
+
"last_name": u.last_name,
|
|
73
|
+
"lang": u.language_code and Lang[u.language_code],
|
|
74
|
+
"pic": pic,
|
|
75
|
+
}
|
|
76
76
|
if blocked is not None:
|
|
77
|
-
|
|
78
|
-
return
|
|
77
|
+
user_dict["blocked"] = blocked
|
|
78
|
+
return user_dict
|
|
79
79
|
|
|
80
80
|
@classmethod
|
|
81
81
|
async def is_blocked(cls, sid: str) -> bool:
|
|
82
82
|
return (await cls[int(sid)]).blocked
|
|
83
83
|
|
|
84
84
|
@classmethod
|
|
85
|
-
async def tg_upsert(cls, u: PyroUser | AioUser, blocked: bool = None) -> tuple["User", bool]:
|
|
86
|
-
user_in:
|
|
87
|
-
|
|
88
|
-
return await cls.update_or_create(**prms)
|
|
89
|
-
|
|
90
|
-
# class Meta:
|
|
91
|
-
# abstract = True
|
|
85
|
+
async def tg_upsert(cls, u: PyroUser | AioUser | WebAppUser, blocked: bool = None) -> tuple["User", bool]:
|
|
86
|
+
user_in: dict = await cls.tg2in(u, blocked)
|
|
87
|
+
return await cls.update_or_create(user_in, username_id=u.id)
|
|
92
88
|
|
|
93
89
|
|
|
94
90
|
class Country(Model):
|
|
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
|