[email] Fix DB call to create Email row
This commit is contained in:
parent
a95306c1be
commit
513bff3fc7
|
@ -41,7 +41,7 @@ async def email_create(hood=Depends(get_hood)):
|
||||||
:return: Email row of the new email bot.
|
:return: Email row of the new email bot.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
emailbot = await Email.objects.create(hood=hood, secret=urandom(32))
|
emailbot = await Email.objects.create(hood=hood, secret=urandom(32).hex())
|
||||||
spawner.start(emailbot)
|
spawner.start(emailbot)
|
||||||
return emailbot
|
return emailbot
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
|
@ -127,7 +127,7 @@ async def email_message_create(message: BodyMessage, hood=Depends(get_hood)):
|
||||||
:return: returns status code 201 if the message is accepted by the censor.
|
:return: returns status code 201 if the message is accepted by the censor.
|
||||||
"""
|
"""
|
||||||
# get bot via "To:" header
|
# get bot via "To:" header
|
||||||
email_row = await Email.objects.get(hood=hood.id)
|
email_row = await Email.objects.get(hood=hood)
|
||||||
# check API secret
|
# check API secret
|
||||||
if message.secret is not email_row.secret:
|
if message.secret is not email_row.secret:
|
||||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||||
|
|
Loading…
Reference in a new issue