A lot of route common params clean up
This commit is contained in:
@@ -57,7 +57,7 @@ async def post_user_obj_new(
|
||||
else: return False
|
||||
|
||||
if create_user_obj_result := create_user_obj(account_id=account_id_random, user_obj_new=user_obj, allow_update=allow_update, avoid_dup_username=avoid_dup_username): pass
|
||||
else: return mk_resp(data=False, status_code=400, response=response, status_message='The user account was not created. This is likely because that username already exists for this account.')
|
||||
else: return mk_resp(data=False, status_code=400, response=commons.response, status_message='The user account was not created. This is likely because that username already exists for this account.')
|
||||
|
||||
if isinstance(create_user_obj_result, int):
|
||||
user_id = create_user_obj_result
|
||||
@@ -72,9 +72,9 @@ async def post_user_obj_new(
|
||||
data = {}
|
||||
data['user_id'] = user_id
|
||||
data['user_id_random'] = user_id_random
|
||||
return mk_resp(data=data, response=response, status_message='The user account was created.')
|
||||
return mk_resp(data=data, response=commons.response, status_message='The user account was created.')
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create a user account was unexpected.')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message='The result from trying to create a user account was unexpected.')
|
||||
# ### END ### API User ### post_user_obj_new() ###
|
||||
|
||||
|
||||
@@ -94,21 +94,21 @@ async def user_obj_change_password(
|
||||
log.debug(locals())
|
||||
|
||||
if password := user_obj.password: pass
|
||||
else: return mk_resp(data=False, status_code=400, status_message='The new password is required.', response=response) # Bad Request
|
||||
else: return mk_resp(data=False, status_code=400, status_message='The new password is required.', response=commons.response) # Bad Request
|
||||
|
||||
generated_password = None
|
||||
|
||||
if password and len(password) >= 10: pass
|
||||
elif password and len(password) < 10:
|
||||
log.warning(f'The password given must be at least 10 characters. User ID: {user_id}')
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message=f'The password given must be at least 10 characters. User ID: {user_id}') # Bad Request
|
||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message=f'The password given must be at least 10 characters. User ID: {user_id}') # Bad Request
|
||||
else:
|
||||
log.warning('No password was given. Generating a new random password.')
|
||||
generated_password = secrets.token_urlsafe(default_num_bytes)
|
||||
password = generated_password
|
||||
|
||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
else: return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
else: return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
user_data = {}
|
||||
#user_data['user_id'] = user_id
|
||||
@@ -117,7 +117,7 @@ async def user_obj_change_password(
|
||||
|
||||
table_name = 'user'
|
||||
if user_rec_update_result := sql_update(data=user_data, table_name=table_name, record_id=user_id, id_random_length=None): pass
|
||||
else: mk_resp(data=False, status_code=500, status_message='Something went wrong while trying to update the password record.', response=response)
|
||||
else: mk_resp(data=False, status_code=500, status_message='Something went wrong while trying to update the password record.', response=commons.response)
|
||||
|
||||
if return_obj:
|
||||
user_obj = load_user_obj(
|
||||
@@ -126,15 +126,15 @@ async def user_obj_change_password(
|
||||
# inc_contact = inc_contact,
|
||||
# inc_organization = inc_organization,
|
||||
# inc_person = inc_person
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = user_obj
|
||||
else:
|
||||
data = True
|
||||
if generated_password:
|
||||
return mk_resp(data=data, status_message='Generated password: fake-testing-12345', response=response)
|
||||
return mk_resp(data=data, status_message='Generated password: fake-testing-12345', response=commons.response)
|
||||
else:
|
||||
return mk_resp(data=data, status_message='The password has been changed.', response=response)
|
||||
#return mk_resp(data=None, status_code=501, response=response) # Not Implemented
|
||||
return mk_resp(data=data, status_message='The password has been changed.', response=commons.response)
|
||||
#return mk_resp(data=None, status_code=501, response=commons.response) # Not Implemented
|
||||
# ### END ### API User ### user_obj_change_password() ###
|
||||
|
||||
|
||||
@@ -187,17 +187,17 @@ async def user_new_auth_key(
|
||||
inc_contact=False,
|
||||
inc_organization=False,
|
||||
inc_person=False
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = user_obj
|
||||
else:
|
||||
user_obj = {}
|
||||
user_obj['auth_key'] = update_user_data['auth_key']
|
||||
return mk_resp(data=user_obj, response=response)
|
||||
return mk_resp(data=user_obj, response=commons.response)
|
||||
else:
|
||||
log.info('The user record was not updated with a new auth_key')
|
||||
log.debug(user_rec_update_result)
|
||||
|
||||
return mk_resp(data=False, status_code=404, response=response)
|
||||
return mk_resp(data=False, status_code=404, response=commons.response)
|
||||
|
||||
|
||||
# ### BEGIN ### API User Routers ### user_authenticate() ###
|
||||
@@ -225,7 +225,7 @@ async def user_authenticate(
|
||||
|
||||
if account_id and username and password:
|
||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
else: return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
else: return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
user_data = {}
|
||||
user_data['account_id'] = account_id
|
||||
@@ -250,13 +250,13 @@ async def user_authenticate(
|
||||
# The user account will be checked if it is enabled below.
|
||||
else:
|
||||
log.info(f'The username was found, but the password did not match. Not allowed to log in. Account ID: {account_id}, Username: {username}')
|
||||
return mk_resp(data=False, status_message=f'The username was found, but the password did not match. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=response)
|
||||
return mk_resp(data=False, status_message=f'The username was found, but the password did not match. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=commons.response)
|
||||
else:
|
||||
log.warning(f'The password hash has was not found. Not allowed to log in. Account ID: {account_id}, Username: {username}')
|
||||
return mk_resp(data=False, status_code=400, status_message=f'The password hash has was not found. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=response)
|
||||
return mk_resp(data=False, status_code=400, status_message=f'The password hash has was not found. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=commons.response)
|
||||
else:
|
||||
log.info(f'A user account was not found with the account and username given. Not allowed to log in. Account ID: {account_id}, Username: {username}')
|
||||
return mk_resp(data=None, status_code=404, status_message=f'A user account was not found with the account and username given. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=response) # Not Found
|
||||
return mk_resp(data=None, status_code=404, status_message=f'A user account was not found with the account and username given. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=commons.response) # Not Found
|
||||
elif user_id and auth_key:
|
||||
# NOTE: Since the user_id (which is required to be unique in the DB table), the account_id is not really needed.
|
||||
user_data = {}
|
||||
@@ -296,9 +296,9 @@ async def user_authenticate(
|
||||
log.info(f'The user ID and auth key combination was not found. Not allowed to log in. User ID: {user_id}, Auth Key: {auth_key}')
|
||||
log.debug(user_data)
|
||||
log.debug(sql)
|
||||
return mk_resp(data=None, status_code=404, status_message=f'The user ID and auth key combination was not found. Not allowed to log in. User ID: {user_id}, Auth Key: {auth_key}', response=response) # Not Found
|
||||
return mk_resp(data=None, status_code=404, status_message=f'The user ID and auth key combination was not found. Not allowed to log in. User ID: {user_id}, Auth Key: {auth_key}', response=commons.response) # Not Found
|
||||
else:
|
||||
return mk_resp(data=None, status_code=400, status_message='One more user account fields was missing or unexpected.', response=response) # Bad Request
|
||||
return mk_resp(data=None, status_code=400, status_message='One more user account fields was missing or unexpected.', response=commons.response) # Bad Request
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_rec_result)
|
||||
|
||||
@@ -312,7 +312,7 @@ async def user_authenticate(
|
||||
log.info('The user account is enabled')
|
||||
else:
|
||||
log.info('The user account is not enabled')
|
||||
return mk_resp(data=False, status_message='This user account is not enabled', response=response)
|
||||
return mk_resp(data=False, status_message='This user account is not enabled', response=commons.response)
|
||||
|
||||
if user_rec_result.get('enable_from', None):
|
||||
#if user_enable_from := user_rec_result.get('enable_from', None).astimezone(pytz.UTC):
|
||||
@@ -322,7 +322,7 @@ async def user_authenticate(
|
||||
log.info('Enable from datetime is valid')
|
||||
else:
|
||||
log.info(f'Enable from datetime is in the future. The user account has not been enabled yet. User Enabled From: {user_enable_from}')
|
||||
return mk_resp(data=False, status_message=f'This user account is not yet enabled. User Enabled From: {user_enable_from}', response=response)
|
||||
return mk_resp(data=False, status_message=f'This user account is not yet enabled. User Enabled From: {user_enable_from}', response=commons.response)
|
||||
else:
|
||||
log.warning('The enable_from datetime was not set. Ignoring this check.')
|
||||
|
||||
@@ -334,7 +334,7 @@ async def user_authenticate(
|
||||
log.info('Enable to datetime is valid')
|
||||
else:
|
||||
log.info(f'Enable to datetime is in the past. The user account has been disabled. User Enabled To: {user_enable_to}')
|
||||
return mk_resp(data=False, status_message=f'This user account is not enabled because the expiratation date has passed. User Enabled To: {user_enable_to}', response=response)
|
||||
return mk_resp(data=False, status_message=f'This user account is not enabled because the expiratation date has passed. User Enabled To: {user_enable_to}', response=commons.response)
|
||||
else:
|
||||
log.warning('The enable_to datetime was not set. Ignoring this check.')
|
||||
|
||||
@@ -360,16 +360,16 @@ async def user_authenticate(
|
||||
inc_person = inc_person,
|
||||
):
|
||||
log.info(f'The user account was loaded. Account ID: {account_id} Username: {username}')
|
||||
user_obj_dict = user_obj_result.dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
return mk_resp(data=user_obj_dict, response=response)
|
||||
user_obj_dict = user_obj_result.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
return mk_resp(data=user_obj_dict, response=commons.response)
|
||||
else:
|
||||
log.warning(f'Something went wrong while trying to load the user account. Account ID: {account_id} Username: {username}')
|
||||
log.debug(user_obj_result)
|
||||
return mk_resp(data=False, status_code=500, status_message=f'Something went wrong while trying to load the user account. Account ID: {account_id} Username: {username}', response=response) # Internal Server Error
|
||||
return mk_resp(data=False, status_code=500, status_message=f'Something went wrong while trying to load the user account. Account ID: {account_id} Username: {username}', response=commons.response) # Internal Server Error
|
||||
else:
|
||||
log.error(f'SQL result was unexpected. A dict result type was expected. This should not happen. Account ID: {account_id} Username: {username}')
|
||||
log.debug(user_rec_result)
|
||||
return mk_resp(data=False, status_code=500, status_message=f'The database lookup result was unexpected. This should not happen. Account ID: {account_id} Username: {username}', response=response)
|
||||
return mk_resp(data=False, status_code=500, status_message=f'The database lookup result was unexpected. This should not happen. Account ID: {account_id} Username: {username}', response=commons.response)
|
||||
# ### END ### API User Routers ### user_authenticate() ###
|
||||
|
||||
|
||||
@@ -388,10 +388,10 @@ async def user_verify_password(
|
||||
log.debug(locals())
|
||||
|
||||
if account_id := redis_lookup_id_random(record_id_random=x_account_id, table_name='account'): pass
|
||||
else: return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
else: return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
if password := user_obj.password: pass
|
||||
else: return mk_resp(data=False, status_code=400, status_message='The password to verify is required.', response=response) # Bad Request
|
||||
else: return mk_resp(data=False, status_code=400, status_message='The password to verify is required.', response=commons.response) # Bad Request
|
||||
|
||||
if user_id_random := user_obj.id_random: # Use id_random instead of user_id_random when getting from User model.
|
||||
log.info(f'Using the user ID to look up the user. User ID: {user_id_random}')
|
||||
@@ -414,17 +414,17 @@ async def user_verify_password(
|
||||
if verify_secure_hash_string(string=password, string_hash=password_hash):
|
||||
log.info(f'The username was found, and the password matched. Log in allowed if the account is enabled. Account ID: {account_id}, Username: {username}')
|
||||
|
||||
return mk_resp(data=True, response=response)
|
||||
return mk_resp(data=True, response=commons.response)
|
||||
else:
|
||||
log.info(f'The username was found, but the password did not match. Not allowed to log in. Account ID: {account_id}, Username: {username}')
|
||||
# NOTE: Returning a 404 instead of 200 even though the actual user record was found.
|
||||
return mk_resp(data=False, status_code=404, status_message=f'The username was found, but the password did not match. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=response) # Not Found
|
||||
return mk_resp(data=False, status_code=404, status_message=f'The username was found, but the password did not match. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=commons.response) # Not Found
|
||||
else:
|
||||
log.warning(f'The password hash has was not found. Not allowed to log in. Account ID: {account_id}, Username: {username}')
|
||||
return mk_resp(data=False, status_code=400, status_message=f'The password hash has was not found. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=response)
|
||||
return mk_resp(data=False, status_code=400, status_message=f'The password hash has was not found. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=commons.response)
|
||||
else:
|
||||
log.info(f'A user account was not found with the account and username given. Not allowed to log in. Account ID: {account_id}, Username: {username}')
|
||||
return mk_resp(data=None, status_code=404, status_message=f'A user account was not found with the account and username given. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=response) # Not Found
|
||||
return mk_resp(data=None, status_code=404, status_message=f'A user account was not found with the account and username given. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=commons.response) # Not Found
|
||||
|
||||
elif username := user_obj.username:
|
||||
log.info(f'Using the username to look up the user. User ID: {username}')
|
||||
@@ -447,19 +447,19 @@ async def user_verify_password(
|
||||
if verify_secure_hash_string(string=password, string_hash=password_hash):
|
||||
log.info(f'The username was found, and the password matched. Log in allowed if the account is enabled. Account ID: {account_id}, Username: {username}')
|
||||
|
||||
return mk_resp(data=True, response=response)
|
||||
return mk_resp(data=True, response=commons.response)
|
||||
else:
|
||||
log.info(f'The username was found, but the password did not match. Not allowed to log in. Account ID: {account_id}, Username: {username}')
|
||||
return mk_resp(data=False, status_message=f'The username was found, but the password did not match. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=response)
|
||||
return mk_resp(data=False, status_message=f'The username was found, but the password did not match. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=commons.response)
|
||||
else:
|
||||
log.warning(f'The password hash has was not found. Not allowed to log in. Account ID: {account_id}, Username: {username}')
|
||||
return mk_resp(data=False, status_code=400, status_message=f'The password hash has was not found. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=response)
|
||||
return mk_resp(data=False, status_code=400, status_message=f'The password hash has was not found. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=commons.response)
|
||||
else:
|
||||
log.info(f'A user account was not found with the account and username given. Not allowed to log in. Account ID: {account_id}, Username: {username}')
|
||||
return mk_resp(data=None, status_code=404, status_message=f'A user account was not found with the account and username given. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=response) # Not Found
|
||||
return mk_resp(data=None, status_code=404, status_message=f'A user account was not found with the account and username given. Not allowed to log in. Account ID: {account_id}, Username: {username}', response=commons.response) # Not Found
|
||||
else:
|
||||
log.warning(f'A user ID or username is required. Can not verify password.')
|
||||
return mk_resp(data=False, status_code=400, status_message=f'A user ID or username is required. Can not verify password.', response=response)
|
||||
return mk_resp(data=False, status_code=400, status_message=f'A user ID or username is required. Can not verify password.', response=commons.response)
|
||||
# ### END ### API User ### user_verify_password() ###
|
||||
|
||||
|
||||
@@ -479,28 +479,28 @@ async def get_account_user_obj_li(
|
||||
log.debug(locals())
|
||||
|
||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=response)
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response)
|
||||
|
||||
# Updated 2021-12-13
|
||||
if user_rec_list_result := get_user_rec_list(
|
||||
account_id = account_id,
|
||||
hidden = hidden, # hidden, not_hidden, all
|
||||
enabled = enabled,
|
||||
limit = limit,
|
||||
enabled = commons.enabled,
|
||||
limit = commons.limit,
|
||||
):
|
||||
user_result_list = []
|
||||
for user_rec in user_rec_list_result:
|
||||
if load_user_result := load_user_obj(
|
||||
user_id = user_rec.get('user_id', None),
|
||||
enabled = enabled,
|
||||
enabled = commons.enabled,
|
||||
# hidden = hidden,
|
||||
limit = limit,
|
||||
limit = commons.limit,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_person = inc_person,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
by_alias = commons.by_alias,
|
||||
exclude_unset = commons.exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
):
|
||||
user_result_list.append(load_user_result)
|
||||
@@ -509,12 +509,12 @@ async def get_account_user_obj_li(
|
||||
response_data = user_result_list
|
||||
elif isinstance(user_rec_list_result, list) or user_rec_list_result is None: # Empty list or None
|
||||
log.info('No results')
|
||||
return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data, response=response)
|
||||
return mk_resp(data=response_data, response=commons.response)
|
||||
# ### END ### API User ### get_account_user_obj_li() ###
|
||||
|
||||
|
||||
@@ -556,7 +556,7 @@ async def lookup_user_obj(
|
||||
base_name = User_Out_Base
|
||||
|
||||
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
|
||||
else: return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
else: return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
|
||||
data = {}
|
||||
@@ -572,7 +572,7 @@ async def lookup_user_obj(
|
||||
sql_limit = 'LIMIT 1'
|
||||
else:
|
||||
log.debug(f'Object type={for_obj_type}; Object ID={for_obj_id}')
|
||||
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
sql = f"""
|
||||
SELECT id AS 'user_id', id_random AS 'user_id_random'
|
||||
@@ -586,12 +586,12 @@ async def lookup_user_obj(
|
||||
if isinstance(user_rec_result, dict):
|
||||
user_id = user_rec_result.get('user_id', None)
|
||||
user_obj = load_user_obj(
|
||||
user_id=user_id,
|
||||
inc_user_role_list=inc_user_role_list,
|
||||
inc_contact=inc_contact,
|
||||
inc_organization=inc_organization,
|
||||
inc_person=inc_person
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
user_id = user_id,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
inc_contact = inc_contact,
|
||||
inc_organization = inc_organization,
|
||||
inc_person = inc_person
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = user_obj
|
||||
elif isinstance(user_rec_result, list):
|
||||
user_obj_li = []
|
||||
@@ -599,18 +599,18 @@ async def lookup_user_obj(
|
||||
user_id = user_obj.get('user_id', None)
|
||||
user_obj_li.append(
|
||||
load_user_obj(
|
||||
user_id=user_id,
|
||||
inc_user_role_list=inc_user_role_list,
|
||||
inc_contact=inc_contact,
|
||||
inc_organization=inc_organization,
|
||||
inc_person=inc_person,
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
user_id = user_id,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
inc_contact = inc_contact,
|
||||
inc_organization = inc_organization,
|
||||
inc_person = inc_person,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
)
|
||||
data = user_obj_li
|
||||
else:
|
||||
log.debug(user_rec_result)
|
||||
return mk_resp(data=None, status_code=404, response=response) # Not Found
|
||||
return mk_resp(data=data, response=response)
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
|
||||
|
||||
# Look up a user with an email address for an account
|
||||
@@ -632,7 +632,7 @@ async def lookup_email(
|
||||
elif account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'):
|
||||
pass
|
||||
else:
|
||||
return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
data = {}
|
||||
data['account_id'] = account_id
|
||||
@@ -648,9 +648,9 @@ async def lookup_email(
|
||||
elif enabled == 'all':
|
||||
sql_enabled = ''
|
||||
else:
|
||||
return mk_resp(data=None, status_code=400, response=response) # Bad Request
|
||||
return mk_resp(data=None, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
data['limit'] = limit
|
||||
data['limit'] = commons.limit
|
||||
sql_limit = f'LIMIT :limit'
|
||||
|
||||
log.debug(data)
|
||||
@@ -683,7 +683,7 @@ async def lookup_email(
|
||||
inc_contact=inc_contact,
|
||||
inc_organization=inc_organization,
|
||||
inc_person=inc_person
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = user_obj
|
||||
elif isinstance(user_obj_result, list):
|
||||
user_obj_li = []
|
||||
@@ -696,15 +696,15 @@ async def lookup_email(
|
||||
inc_contact=inc_contact,
|
||||
inc_organization=inc_organization,
|
||||
inc_person=inc_person,
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
)
|
||||
data = user_obj_li
|
||||
else:
|
||||
log.debug(user_obj_result)
|
||||
return mk_resp(data=None, status_code=404, response=response) # Not Found
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
log.debug(data)
|
||||
return mk_resp(data=data, response=response)
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
|
||||
|
||||
# Look up is only for account or person records
|
||||
@@ -728,7 +728,7 @@ async def lookup_username(
|
||||
elif account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'):
|
||||
pass
|
||||
else:
|
||||
return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
data = {}
|
||||
data['account_id'] = account_id
|
||||
@@ -759,7 +759,7 @@ async def lookup_username(
|
||||
inc_contact = inc_contact,
|
||||
inc_person = inc_person,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
).dict(by_alias = by_alias, exclude_unset=exclude_unset)
|
||||
).dict(by_alias = commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = user_obj
|
||||
elif isinstance(user_obj_result, list):
|
||||
user_obj_li = []
|
||||
@@ -772,13 +772,13 @@ async def lookup_username(
|
||||
inc_contact = inc_contact,
|
||||
inc_person = inc_person,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
)
|
||||
data = user_obj_li
|
||||
else:
|
||||
log.debug(user_obj_result)
|
||||
return mk_resp(data=None, status_code=404, response=response) # Not Found
|
||||
return mk_resp(data=data, response=response)
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
|
||||
|
||||
# ### BEGIN ### API User ### email_auth_key_url() ###
|
||||
@@ -795,10 +795,10 @@ async def email_auth_key_url(
|
||||
log.debug(locals())
|
||||
|
||||
if account_id := redis_lookup_id_random(record_id_random=x_account_id, table_name='account'): pass
|
||||
else: return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
else: return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
else: return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
else: return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
if result := email_user_auth_key_url(
|
||||
account_id = account_id,
|
||||
@@ -806,16 +806,15 @@ async def email_auth_key_url(
|
||||
root_url = root_url,
|
||||
):
|
||||
log.info('Email with auth key log in URL was sent.')
|
||||
return mk_resp(data=True, response=response)
|
||||
return mk_resp(data=True, response=commons.response)
|
||||
else:
|
||||
log.warning('Email with auth key log in URL was not sent.')
|
||||
return mk_resp(data=False, status_code=500, response=response)
|
||||
return mk_resp(data=False, status_code=500, response=commons.response)
|
||||
# ### END ### API User ### email_auth_key_url() ###
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API User ### get_user_obj() ###
|
||||
# Working well as of 2021-06-25. Using as a template for other routes.
|
||||
# Updated 2022-01-05
|
||||
@router.get('/user/{user_id}', response_model=Resp_Body_Base)
|
||||
async def get_user_obj(
|
||||
user_id: str = Query(..., min_length=11, max_length=22),
|
||||
@@ -844,13 +843,13 @@ async def get_user_obj(
|
||||
log.debug(locals())
|
||||
|
||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=response)
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response)
|
||||
|
||||
if user_result := load_user_obj(
|
||||
user_id = user_id,
|
||||
limit = limit,
|
||||
limit = commons.limit,
|
||||
model_as_dict = True, # NOTE: returning model as a dict
|
||||
enabled = enabled,
|
||||
enabled = commons.enabled,
|
||||
inc_address = inc_address,
|
||||
# inc_archive_list = inc_archive_list,
|
||||
inc_contact = inc_contact,
|
||||
@@ -873,9 +872,9 @@ async def get_user_obj(
|
||||
):
|
||||
response_data = user_result
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data, response=response)
|
||||
return mk_resp(data=response_data, response=commons.response)
|
||||
# ### END ### API User ### get_user_obj() ###
|
||||
|
||||
|
||||
@@ -907,14 +906,14 @@ async def get_user_obj(
|
||||
|
||||
# if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
# else:
|
||||
# return mk_resp(data=None, status_code=404, response=response)
|
||||
# return mk_resp(data=None, status_code=404, response=commons.response)
|
||||
|
||||
# # Updated 2021-12-13
|
||||
# if order_rec_list_result := get_order_rec_list(
|
||||
# for_obj_type = 'user',
|
||||
# for_obj_id = user_id,
|
||||
# limit = limit,
|
||||
# enabled = enabled,
|
||||
# limit = commons.limit,
|
||||
# enabled = commons.enabled,
|
||||
# from_datetime = from_datetime,
|
||||
# to_datetime = to_datetime,
|
||||
# status = status,
|
||||
@@ -923,10 +922,10 @@ async def get_user_obj(
|
||||
# for order_rec in order_rec_list_result:
|
||||
# if load_order_result := load_order_obj(
|
||||
# order_id = order_rec.get('order_id', None),
|
||||
# limit = limit,
|
||||
# enabled = enabled,
|
||||
# by_alias = by_alias,
|
||||
# exclude_unset = exclude_unset,
|
||||
# limit = commons.limit,
|
||||
# enabled = commons.enabled,
|
||||
# by_alias = commons.by_alias,
|
||||
# exclude_unset = commons.exclude_unset,
|
||||
# # model_as_dict = model_as_dict,
|
||||
# inc_order_cfg = inc_order_cfg,
|
||||
# inc_order_line_list = inc_order_line_list,
|
||||
@@ -937,12 +936,12 @@ async def get_user_obj(
|
||||
# response_data = order_result_list
|
||||
# elif event_location_rec_list_result is None:
|
||||
# log.info('No results')
|
||||
# return mk_resp(data=None, status_code=404, response=response) # Not Found
|
||||
# return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
# else:
|
||||
# log.warning('Likely bad request')
|
||||
# return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
||||
# return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
# return mk_resp(data=response_data, response=response)
|
||||
# return mk_resp(data=response_data, response=commons.response)
|
||||
# # ### END ### API User ### get_user_obj_order_list() ###
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user