From 8bd5fd2106e0f34ee92d31da7a6df724fc8201f9 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Tue, 8 Apr 2025 15:34:58 -0400 Subject: [PATCH] Updated the user auth and user auth key email endpoints and functions. --- app/methods/user_methods.py | 14 ++++++++++---- app/routers/user.py | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/methods/user_methods.py b/app/methods/user_methods.py index e0851ab..396c3df 100644 --- a/app/methods/user_methods.py +++ b/app/methods/user_methods.py @@ -605,12 +605,13 @@ def get_user_rec_list( # ### BEGIN ### User Methods ### email_user_auth_key_url() ### -# This emails the actual one time use sign in URL for a user. -# Updated 2021-12-02 +# This generates a new auth_key token and emails the actual one time use sign in URL to the user's email. +# Updated 2025-04-08 def email_user_auth_key_url( account_id: int|str, user_id: int|str, root_url: str, + key_param_name: str = 'auth_key', ): log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) @@ -684,8 +685,13 @@ def email_user_auth_key_url( else: enable_to_str = '-- Not Set --' auth_key = user_obj.auth_key - user_login_url = f'{root_url}user/login?username={urllib.parse.quote(username)}&email={urllib.parse.quote(to_email)}' - user_login_auth_key_url = f'{root_url}?user_id={urllib.parse.quote(user_id_random)}&auth_key={urllib.parse.quote(new_auth_key)}&valid_email={True}' + user_login_url = f'{root_url}?username={urllib.parse.quote(username)}&user_email={urllib.parse.quote(to_email)}' + # user_login_url = f'{root_url}user/login?username={urllib.parse.quote(username)}&email={urllib.parse.quote(to_email)}' + + if key_param_name == 'auth_key': + user_login_auth_key_url = f'{root_url}?user_id={urllib.parse.quote(user_id_random)}&auth_key={urllib.parse.quote(new_auth_key)}&valid_email={True}' + elif key_param_name: + user_login_auth_key_url = f'{root_url}?user_id={urllib.parse.quote(user_id_random)}&{key_param_name}={urllib.parse.quote(new_auth_key)}&valid_email={True}' subject = f'{account_short_name}: One Time Use Sign In Link ({new_auth_key})' diff --git a/app/routers/user.py b/app/routers/user.py index 34e2c03..6e2f75d 100644 --- a/app/routers/user.py +++ b/app/routers/user.py @@ -796,12 +796,15 @@ async def lookup_username( # ### BEGIN ### API User ### email_auth_key_url() ### -# Updated 2021-12-02 +# This requires the user_id and root_url or base_url. +# This endpoint will generate a new user auth_key and send the email to the user's email address. +# Updated 2025-04-08 # @router.get('/user/email_auth_key_url', response_model=Resp_Body_Base) @router.get('/user/{user_id}/email_auth_key_url', response_model=Resp_Body_Base) async def email_auth_key_url( user_id: str = Path(min_length=11, max_length=22), root_url: Optional[str] = Query(None, min_length=10, max_length=100), # Absolute min = 7 + key_param_name: str = Query('auth_key', min_length=2, max_length=10), return_obj: bool = False, commons: Common_Route_Params = Depends(common_route_params), ): @@ -817,6 +820,7 @@ async def email_auth_key_url( account_id = account_id, user_id = user_id, root_url = root_url, + key_param_name = key_param_name, ): log.info('Email with auth key log in URL was sent.') return mk_resp(data=True, response=commons.response)