mail subscription confirm functions;

confirmation code & mail template still missing
This commit is contained in:
b3yond 2018-08-07 15:10:28 +02:00
parent 9beb864a2f
commit d002969377
2 changed files with 21 additions and 3 deletions

9
db.py
View file

@ -196,6 +196,15 @@ u\d\d?
return None
return User(uid)
def by_city(self, city):
from user import User
self.execute("SELECT user_id FROM cities WHERE city=?", (city, ))
try:
uid, = self.cur.fetchone()
except TypeError:
return None
return User(uid)
def user_facing_properties(self, city):
self.execute("""SELECT city, markdown, masto_link, twit_link
FROM cities

View file

@ -89,14 +89,23 @@ def city_page(city):
@get('/city/mail/<city>')
@view('template/mail.tpl')
def display_mail_page(city, user):
def display_mail_page(city):
user = db.by_city(city)
return user.state()
@post('/city/mail/submit/<city>')
def subscribe_mail(user, city):
def subscribe_mail(city):
email = request.forms['mailaddress']
# add confirmation mail workflow
code = generate_code(email, city)
# send mail with code to email
@get('/city/mail/confirm/<code>')
@view('template/city.tpl')
def confirm_subscribe(code):
email, city = parse_code(code)
user = db.by_city(city)
user.add_subscriber(email)
redirect('/city/' + city)