square-authentication 3.0.0__py3-none-any.whl → 4.0.0__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.
@@ -13,6 +13,7 @@ class LoginUsernameV0(BaseModel):
13
13
  username: str
14
14
  password: str
15
15
  app_id: int
16
+ assign_app_id_if_missing: bool = False
16
17
 
17
18
 
18
19
  class DeleteUserV0(BaseModel):
@@ -5,6 +5,7 @@ import bcrypt
5
5
  import jwt
6
6
  from fastapi import APIRouter, status, Header, HTTPException
7
7
  from fastapi.responses import JSONResponse
8
+ from requests import HTTPError
8
9
  from square_commons import get_api_output_in_standard_format
9
10
  from square_database.pydantic_models.pydantic_models import (
10
11
  FiltersV0,
@@ -276,7 +277,6 @@ async def get_user_details_v0(
276
277
  ),
277
278
  )["data"]["main"]
278
279
  )
279
- # not putting filter for expiry refresh tokens
280
280
  local_list_response_user_sessions = (
281
281
  global_object_square_database_helper.get_rows_v0(
282
282
  database_name=global_string_database_name,
@@ -285,6 +285,9 @@ async def get_user_details_v0(
285
285
  filters=FiltersV0(
286
286
  {
287
287
  UserSession.user_id.name: FilterConditionsV0(eq=user_id),
288
+ UserSession.user_session_expiry_time.name: FilterConditionsV0(
289
+ gte=datetime.now(timezone.utc).isoformat()
290
+ ),
288
291
  }
289
292
  ),
290
293
  )["data"]["main"]
@@ -303,7 +306,7 @@ async def get_user_details_v0(
303
306
  "sessions": [
304
307
  {
305
308
  "app_id": x[UserApp.app_id.name],
306
- "sessions": len(
309
+ "active_sessions": len(
307
310
  [
308
311
  y
309
312
  for y in local_list_response_user_sessions
@@ -497,12 +500,13 @@ async def update_user_app_ids_v0(
497
500
  )
498
501
 
499
502
 
500
- @router.get("/login_username/v0")
503
+ @router.post("/login_username/v0")
501
504
  @global_object_square_logger.async_auto_logger
502
505
  async def login_username_v0(body: LoginUsernameV0):
503
506
  username = body.username
504
507
  password = body.password
505
508
  app_id = body.app_id
509
+ assign_app_id_if_missing = body.assign_app_id_if_missing
506
510
  username = username.lower()
507
511
  try:
508
512
  """
@@ -548,14 +552,36 @@ async def login_username_v0(body: LoginUsernameV0):
548
552
  }
549
553
  ),
550
554
  )["data"]["main"]
551
- if len(local_list_user_app_response) != 1:
552
- output_content = get_api_output_in_standard_format(
553
- message=messages["GENERIC_400"],
554
- log=f"user_id {local_str_user_id}({username}) not assigned to app {app_id}.",
555
- )
556
- return JSONResponse(
557
- status_code=status.HTTP_400_BAD_REQUEST, content=output_content
558
- )
555
+ if len(local_list_user_app_response) == 0:
556
+ if assign_app_id_if_missing:
557
+ try:
558
+ global_object_square_database_helper.insert_rows_v0(
559
+ database_name=global_string_database_name,
560
+ schema_name=global_string_schema_name,
561
+ table_name=UserApp.__tablename__,
562
+ data=[
563
+ {
564
+ UserApp.user_id.name: local_str_user_id,
565
+ UserApp.app_id.name: app_id,
566
+ }
567
+ ],
568
+ )
569
+ except HTTPError as he:
570
+ output_content = get_api_output_in_standard_format(
571
+ message=messages["GENERIC_400"],
572
+ log=str(he),
573
+ )
574
+ return JSONResponse(
575
+ status_code=he.response.status_code, content=output_content
576
+ )
577
+ else:
578
+ output_content = get_api_output_in_standard_format(
579
+ message=messages["GENERIC_400"],
580
+ log=f"user_id {local_str_user_id}({username}) not assigned to app {app_id}.",
581
+ )
582
+ return JSONResponse(
583
+ status_code=status.HTTP_400_BAD_REQUEST, content=output_content
584
+ )
559
585
 
560
586
  # validate password
561
587
  if not (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: square-authentication
3
- Version: 3.0.0
3
+ Version: 4.0.0
4
4
  Summary: authentication layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_authentication
6
6
  Author: thePmSquare
@@ -43,6 +43,12 @@ pip install square_authentication
43
43
 
44
44
  ## changelog
45
45
 
46
+ ### v4.0.0
47
+
48
+ - /login_username/v0 is now POST method.
49
+ - new flag in /login_username/v0 assign_app_id_if_missing.
50
+ - bugfix: /get_user_details/v0 now only returns number of active sessions.
51
+
46
52
  ### v3.0.0
47
53
 
48
54
  - added new endpoints
@@ -4,14 +4,14 @@ square_authentication/main.py,sha256=JK9KBmN73KL8EpKrXrjrwwf37bmC4AXrFHtfl2roYwQ
4
4
  square_authentication/messages.py,sha256=BA9KC0vW9UD1ZXT4VneVqVNLlgdbMdsAwAgxhJISLf4,1175
5
5
  square_authentication/data/config.ini,sha256=_740RvKpL5W2bUDGwZ7ePwuP-mAasr5cXXB81yq_Jv8,906
6
6
  square_authentication/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- square_authentication/pydantic_models/core.py,sha256=Bd6BPFPCV5PPA0KDKXUghIpoQA_w9MCSMY6ldSxM1qw,388
7
+ square_authentication/pydantic_models/core.py,sha256=Hwzr-YJH6GVGLp4Z29iHItOEhiEvk65MjsttmCaDTe4,431
8
8
  square_authentication/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- square_authentication/routes/core.py,sha256=ijTmFDi8wg0oFycQRqxpXk4j4t6IqXq0FHffjecAnkQ,43303
9
+ square_authentication/routes/core.py,sha256=o9FeIGMdQbkBLZ0d9GdyEOJJkRMBsYRyUKOO9l5vWgA,44551
10
10
  square_authentication/routes/utility.py,sha256=Kx4S4tZ1GKsPoC8CoZ4fkLEebvr02KeFEPePtTHtpnQ,75
11
11
  square_authentication/utils/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
12
12
  square_authentication/utils/encryption.py,sha256=T6BShoUr_xeGpbfPgTK-GxTlXPwcjwU4c4KW7KPzrF8,1865
13
13
  square_authentication/utils/token.py,sha256=Y_arg5LegX-aprMj9YweUK8jjNZLGDjLUGgxbUA12w4,560
14
- square_authentication-3.0.0.dist-info/METADATA,sha256=6ahIoM0u8VAAGmp48nmRWwNMBj9tnN5X2q8oMr-G3Tc,2622
15
- square_authentication-3.0.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
16
- square_authentication-3.0.0.dist-info/top_level.txt,sha256=wDssVJIl9KIEJPj5rR3rv4uRI7yCndMBrvHd_6BGXQA,22
17
- square_authentication-3.0.0.dist-info/RECORD,,
14
+ square_authentication-4.0.0.dist-info/METADATA,sha256=spjL_EnrXbwC-em5JgyrzlCq0HD0QHDzXEagx9DzLHM,2810
15
+ square_authentication-4.0.0.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
16
+ square_authentication-4.0.0.dist-info/top_level.txt,sha256=wDssVJIl9KIEJPj5rR3rv4uRI7yCndMBrvHd_6BGXQA,22
17
+ square_authentication-4.0.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.44.0)
2
+ Generator: bdist_wheel (0.45.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5