xn-auth 0.2.50__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-auth
3
- Version: 0.2.50
3
+ Version: 0.2.51
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -38,8 +38,7 @@ class Auth:
38
38
  )
39
39
 
40
40
  async def user_proc(user: WebAppUser) -> Response[XyncUser]:
41
- user_in = await user_model.tg2in(user)
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")
@@ -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, UniqBinaryField, UInt1Field, UInt2Field
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) -> BaseUpd:
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
- user = cls.validate(
66
- {
67
- "first_name": u.first_name,
68
- "last_name": u.last_name,
69
- "username_id": un.id,
70
- "lang": u.language_code and Lang[u.language_code],
71
- "pic": hasattr(u, "photo_url")
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
- user.blocked = blocked
78
- return user
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: cls.in_type() = await cls.tg2in(u, blocked)
87
- prms = user_in.df_unq()
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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-auth
3
- Version: 0.2.50
3
+ Version: 0.2.51
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
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