xn-auth 0.2.51.dev1__tar.gz → 0.2.52__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.51.dev1
3
+ Version: 0.2.52
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -1,3 +1,4 @@
1
+ import logging
1
2
  from base64 import b64encode
2
3
  from datetime import timedelta
3
4
 
@@ -38,8 +39,7 @@ class Auth:
38
39
  )
39
40
 
40
41
  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
42
+ db_user, cr = await user_model.tg_upsert(user) # on login: update user in db from tg
43
43
  if user.allows_write_to_pm is None:
44
44
  try:
45
45
  await Bot(sec).send_chat_action(user.id, "typing")
@@ -77,7 +77,9 @@ class Auth:
77
77
  try:
78
78
  twaid: WebAppInitData = safe_parse_webapp_init_data(self.jwt.token_secret, tid)
79
79
  except ValueError as e:
80
+ logging.error(e)
80
81
  raise NotAuthorizedException(detail=f"Tg Initdata invalid {e}")
82
+ logging.warning({tid: twaid})
81
83
  return await user_proc(twaid.user)
82
84
 
83
85
  self.tma_handler = tma
@@ -82,7 +82,7 @@ class User(Model):
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]:
85
+ async def tg_upsert(cls, u: PyroUser | AioUser | WebAppUser, blocked: bool = None) -> tuple["User", bool]:
86
86
  user_in: dict = await cls.tg2in(u, blocked)
87
87
  return await cls.update_or_create(user_in, username_id=u.id)
88
88
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-auth
3
- Version: 0.2.51.dev1
3
+ Version: 0.2.52
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