Working on user log in
This commit is contained in:
@@ -24,6 +24,7 @@ class Account_Base(BaseModel):
|
||||
|
||||
code: Optional[str]
|
||||
name: Optional[str]
|
||||
short_name: Optional[str]
|
||||
description: Optional[str]
|
||||
|
||||
enable: Optional[bool]
|
||||
|
||||
@@ -35,6 +35,8 @@ class User_New_Base(BaseModel):
|
||||
new_password: str
|
||||
password: Optional[str]
|
||||
|
||||
allow_auth_key: Optional[int]
|
||||
|
||||
enable: Optional[bool] = False
|
||||
enable_from: Optional[datetime.datetime]
|
||||
enable_to: Optional[datetime.datetime] = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=365)
|
||||
@@ -113,6 +115,8 @@ class User_Out_Base(BaseModel):
|
||||
email: Optional[str]
|
||||
email_verified: Optional[bool]
|
||||
password: Optional[str]
|
||||
|
||||
allow_auth_key: Optional[int]
|
||||
auth_key: Optional[str]
|
||||
|
||||
enable: Optional[bool]
|
||||
@@ -185,6 +189,8 @@ class User_Base(BaseModel):
|
||||
email: Optional[str]
|
||||
email_verified: Optional[bool]
|
||||
password: Optional[str]
|
||||
|
||||
allow_auth_key: Optional[int]
|
||||
auth_key: Optional[str]
|
||||
|
||||
enable: Optional[bool]
|
||||
|
||||
@@ -402,9 +402,85 @@ async def lookup_user_obj(
|
||||
return mk_resp(data=data)
|
||||
|
||||
|
||||
# Look up a user with an email addresss for an account
|
||||
@router.get('/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),
|
||||
x_account_id: str = Header(...),
|
||||
inc_roles: bool = False,
|
||||
inc_contact: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # 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) # Not Found
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
|
||||
data = {}
|
||||
data['account_id'] = account_id
|
||||
data['email'] = email
|
||||
log.debug(data)
|
||||
|
||||
if account_id:
|
||||
sql = f"""
|
||||
SELECT id AS 'user_id', id_random AS 'user_id_random'
|
||||
FROM `user` AS `user`
|
||||
WHERE `user`.account_id = :account_id AND `user`.email = :email
|
||||
"""
|
||||
else:
|
||||
sql = f"""
|
||||
SELECT id AS 'user_id', id_random AS 'user_id_random'
|
||||
FROM `user` AS `user`
|
||||
WHERE `user`.account_id IS NULL AND `user`.email = :email
|
||||
"""
|
||||
log.debug(sql)
|
||||
|
||||
# This will return a list if selecting by account ID
|
||||
user_obj_result = sql_select(data=data, sql=sql)
|
||||
if isinstance(user_obj_result, dict):
|
||||
user_id = user_obj_result.get('user_id', None)
|
||||
user_obj = load_user_obj(
|
||||
user_id=user_id,
|
||||
inc_roles=inc_roles,
|
||||
inc_contact=inc_contact,
|
||||
inc_organization=inc_organization,
|
||||
inc_person=inc_person
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
data = user_obj
|
||||
elif isinstance(user_obj_result, list):
|
||||
user_obj_li = []
|
||||
for user_obj in user_obj_result:
|
||||
user_id = user_obj.get('user_id', None)
|
||||
user_obj_li.append(
|
||||
load_user_obj(
|
||||
user_id=user_id,
|
||||
inc_roles=inc_roles,
|
||||
inc_contact=inc_contact,
|
||||
inc_organization=inc_organization,
|
||||
inc_person=inc_person,
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
)
|
||||
data = user_obj_li
|
||||
else:
|
||||
log.debug(user_obj_result)
|
||||
return mk_resp(data=None, status_code=404) # Not Found
|
||||
return mk_resp(data=data)
|
||||
|
||||
|
||||
# Look up is only for account or person records
|
||||
# Look up a user with a username for an account
|
||||
@router.get('/lookup_username', response_model=Resp_Body_Base)
|
||||
async def lookup_username_obj(
|
||||
async def lookup_username(
|
||||
account_id: Union[int,str],
|
||||
username: str = Query(..., min_length=2, max_length=50),
|
||||
x_account_id: str = Header(...),
|
||||
@@ -426,8 +502,6 @@ async def lookup_username_obj(
|
||||
return mk_resp(data=False, status_code=404) # Not Found
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
|
||||
|
||||
|
||||
data = {}
|
||||
data['account_id'] = account_id
|
||||
data['username'] = username
|
||||
|
||||
Reference in New Issue
Block a user