[core] Add update function
This commit is contained in:
parent
f1dc563846
commit
24aab36c9f
|
@ -104,11 +104,6 @@ async def admin_register(values: BodyAdmin):
|
|||
- **email**: E-Mail Address of new hood admin
|
||||
- **password**: Password of new hood admin
|
||||
"""
|
||||
if len(values.password) < 8:
|
||||
logger.debug('Password is too short')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST, detail='Password is too short'
|
||||
)
|
||||
register_token = to_token(**values.__dict__)
|
||||
logger.debug(f'register_token={register_token}')
|
||||
try:
|
||||
|
@ -237,6 +232,36 @@ async def admin_hood_read_all(admin=Depends(get_admin)):
|
|||
)
|
||||
|
||||
|
||||
@router.put(
|
||||
'/',
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
# TODO response_model,
|
||||
operation_id='update_admin',
|
||||
)
|
||||
async def admin_update(values: BodyAdmin, admin=Depends(get_admin)):
|
||||
try:
|
||||
if not admin:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||
if values.email:
|
||||
register_token = to_token(**values.__dict__)
|
||||
body = f'{config["frontend_url"]}/confirm?token={register_token}'
|
||||
logger.debug(body)
|
||||
email.send_email(
|
||||
to=values.email,
|
||||
subject='Confirm Account Change',
|
||||
body=body,
|
||||
)
|
||||
if values.password:
|
||||
passhash = argon2.hash(values.password)
|
||||
await admin.update(passhash=passhash)
|
||||
return {}
|
||||
except IntegrityError:
|
||||
raise HTTPException(status_code=status.HTTP_409_CONFLICT)
|
||||
except (ConnectionRefusedError, SMTPException):
|
||||
logger.exception('Email sending failed')
|
||||
raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY)
|
||||
|
||||
|
||||
@router.delete(
|
||||
'/',
|
||||
status_code=status.HTTP_204_NO_CONTENT,
|
||||
|
|
Loading…
Reference in a new issue