[email] Coding style fix

This commit is contained in:
maike 2020-07-06 21:26:32 +02:00 committed by dl6tom
parent 0068558efb
commit 43b8ec8373
2 changed files with 7 additions and 1 deletions

View file

@ -8,6 +8,7 @@ from ormantic import Integer, ForeignKey, Model, Text
class EmailSubscribers(Model):
""" This table stores all subscribers, who want to receive messages via email. """
id: Integer(primary_key=True) = None
hood: ForeignKey(Hood)
email: Text()
@ -18,6 +19,7 @@ class EmailSubscribers(Model):
class Email(Model):
""" This table is used to track the hood ID. It also stores the token secret. """
id: Integer(primary_key=True) = None
hood: ForeignKey(Hood)
secret: Text()

View file

@ -20,6 +20,7 @@ from os import urandom
class BodyMessage(BaseModel):
""" This model shows which values are supplied by the MDA listener script. """
text: str
to: str
author: str
@ -28,6 +29,7 @@ class BodyMessage(BaseModel):
class Subscriber(BaseModel):
""" This model holds the email address of a fresh subscriber. """
email: str
@ -86,7 +88,9 @@ async def email_subscribe(subscriber: Subscriber, hood=Depends(get_hood)):
:return: Returns status code 200 after sending confirmation email.
"""
secretbox = SecretBox(Email.secret)
token = secretbox.encrypt({'email': subscriber.email, }, encoder=URLSafeBase64Encoder)
token = secretbox.encrypt(
{'email': subscriber.email,}, encoder=URLSafeBase64Encoder
)
asciitoken = token.decode('ascii')
confirm_link = (
config['root_url'] + "api/" + hood.id + "/email/subscribe/confirm/" + asciitoken