A lot of route common params clean up

This commit is contained in:
Scott Idem
2022-01-05 15:44:06 -05:00
parent e5d80908ce
commit 104bc8d08a
2 changed files with 17 additions and 34 deletions

View File

@@ -208,7 +208,7 @@ async def user_new_auth_key(
# Updated 2021-10-06
@router.get('/user/authenticate', response_model=Resp_Body_Base)
async def user_authenticate(
account_id: Optional[Union[int,str]] = None,
null_account_id: bool = False,
user_id: Optional[str] = Query(None, min_length=11, max_length=22),
username: Optional[str] = Query(None, min_length=3, max_length=50),
password: Optional[str] = Query(None, min_length=8, max_length=100),
@@ -224,8 +224,7 @@ async def user_authenticate(
log.debug(locals())
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=commons.response) # Not Found
account_id = commons.x_account_id
user_data = {}
user_data['account_id'] = account_id
@@ -387,8 +386,7 @@ async def user_verify_password(
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
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=commons.response) # Not Found
account_id = commons.x_account_id
if password := user_obj.password: pass
else: return mk_resp(data=False, status_code=400, status_message='The password to verify is required.', response=commons.response) # Bad Request
@@ -616,8 +614,8 @@ async def lookup_user_obj(
# Look up a user with an email address for an account
@router.get('/user/lookup_email', response_model=Resp_Body_Base)
async def lookup_email(
account_id: Union[int,str],
email: str = Query(..., min_length=2, max_length=50),
null_account_id: bool = False,
inc_user_role_list: bool = False,
inc_contact: bool = False,
inc_organization: bool = False,
@@ -627,12 +625,7 @@ async def lookup_email(
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if account_id == '':
account_id = None
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=commons.response) # Not Found
account_id = commons.x_account_id
data = {}
data['account_id'] = account_id
@@ -655,7 +648,7 @@ async def lookup_email(
log.debug(data)
if account_id:
if not null_account_id:
sql = f"""
SELECT id AS 'user_id', id_random AS 'user_id_random'
FROM `user` AS `user`
@@ -711,8 +704,8 @@ async def lookup_email(
# Look up a user with a username for an account
@router.get('/user/lookup_username', response_model=Resp_Body_Base)
async def lookup_username(
account_id: Union[int,str],
username: str = Query(..., min_length=2, max_length=50),
null_account_id: bool = False,
inc_address: bool = False,
inc_contact: bool = False,
inc_organization: bool = False,
@@ -723,19 +716,14 @@ async def lookup_username(
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if account_id == '':
account_id = None
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=commons.response) # Not Found
account_id = commons.x_account_id
data = {}
data['account_id'] = account_id
data['username'] = username
log.debug(data)
if account_id:
if not null_account_id:
sql = f"""
SELECT id AS 'user_id', id_random AS 'user_id_random'
FROM `user` AS `user`
@@ -794,8 +782,7 @@ async def email_auth_key_url(
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
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=commons.response) # Not Found
account_id = commons.x_account_id
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=commons.response) # Not Found