From d00296937704dbdeae5a3cad18e943f0e8b6aaa0 Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 7 Aug 2018 15:10:28 +0200 Subject: [PATCH] mail subscription confirm functions; confirmation code & mail template still missing --- db.py | 9 +++++++++ frontend.py | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/db.py b/db.py index f96927e..9409fe9 100644 --- a/db.py +++ b/db.py @@ -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 diff --git a/frontend.py b/frontend.py index 943a62a..badd203 100755 --- a/frontend.py +++ b/frontend.py @@ -89,14 +89,23 @@ def city_page(city): @get('/city/mail/') @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/') -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/') +@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)