Updated the user auth and user auth key email endpoints and functions.

This commit is contained in:
Scott Idem
2025-04-08 15:34:58 -04:00
parent 573f054ee2
commit 8bd5fd2106
2 changed files with 15 additions and 5 deletions

View File

@@ -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})'

View File

@@ -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)