xn-auth 0.2.50__py3-none-any.whl → 0.2.51.dev1__py3-none-any.whl

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.
x_auth/models.py CHANGED
@@ -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,28 +53,29 @@ 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:
@@ -83,12 +83,8 @@ class User(Model):
83
83
 
84
84
  @classmethod
85
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
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.dev1
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -0,0 +1,10 @@
1
+ x_auth/controller.py,sha256=IDyamZ-_tPxVb03lIn5ofYYyKeMc5klBru4x9mDKWcw,3773
2
+ x_auth/enums.py,sha256=pciVrb92S9YQFMhHe6pKNYwcvtevwfMXIiG1WxAEa-Q,761
3
+ x_auth/exceptions.py,sha256=2B4okJxhPyNqTJXlSTfblJUQJ60bLGXdgJIu6ue7S6w,162
4
+ x_auth/middleware.py,sha256=JfssQomDv0J_69GfS2a_2_uyRzs26zSY6IW1Vk7m8K0,2900
5
+ x_auth/models.py,sha256=FQcjtezPGLDv_jFDY1KOoXFvx-pSA8tdLSn2tgo1jLk,9198
6
+ x_auth/types.py,sha256=xVi1A8CrGfdfS2HbaxX-X3lEJWH_1TvTk-u8TeqKzQg,1514
7
+ xn_auth-0.2.51.dev1.dist-info/METADATA,sha256=XYiK8bpa63JT9xnxoeoPhhDGMV3pSlYSzOqiADs7fCk,828
8
+ xn_auth-0.2.51.dev1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ xn_auth-0.2.51.dev1.dist-info/top_level.txt,sha256=ydMDkzxgQPtW-E_MNDfUAroAFZvWSqU-x_kZSA7NSFo,7
10
+ xn_auth-0.2.51.dev1.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- x_auth/controller.py,sha256=IDyamZ-_tPxVb03lIn5ofYYyKeMc5klBru4x9mDKWcw,3773
2
- x_auth/enums.py,sha256=pciVrb92S9YQFMhHe6pKNYwcvtevwfMXIiG1WxAEa-Q,761
3
- x_auth/exceptions.py,sha256=2B4okJxhPyNqTJXlSTfblJUQJ60bLGXdgJIu6ue7S6w,162
4
- x_auth/middleware.py,sha256=JfssQomDv0J_69GfS2a_2_uyRzs26zSY6IW1Vk7m8K0,2900
5
- x_auth/models.py,sha256=MVd-iFG3CX6-5EVIedd8KBb3fNW_FuwHvKs7_SCwHl8,9312
6
- x_auth/types.py,sha256=xVi1A8CrGfdfS2HbaxX-X3lEJWH_1TvTk-u8TeqKzQg,1514
7
- xn_auth-0.2.50.dist-info/METADATA,sha256=iKIOk2FEcH_syE3jkIf5V8FZlUNbVkED6D6uABR4RMs,823
8
- xn_auth-0.2.50.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- xn_auth-0.2.50.dist-info/top_level.txt,sha256=ydMDkzxgQPtW-E_MNDfUAroAFZvWSqU-x_kZSA7NSFo,7
10
- xn_auth-0.2.50.dist-info/RECORD,,