forked from ticketfrei/ticketfrei
you can now subscribe to mail notifications! Also db bugfixes.
This commit is contained in:
parent
d002969377
commit
cc0b3378a9
27
db.py
27
db.py
|
@ -135,6 +135,14 @@ class DB(object):
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def user_token(self, email, password):
|
def user_token(self, email, password):
|
||||||
|
"""
|
||||||
|
This function is called by the register confirmation process. It wants
|
||||||
|
to write an email to the email table and a passhash to the user table.
|
||||||
|
|
||||||
|
:param email: a string with an E-Mail address.
|
||||||
|
:param password: a string with a passhash.
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
return jwt.encode({
|
return jwt.encode({
|
||||||
'email': email,
|
'email': email,
|
||||||
'passhash': scrypt_mcf(
|
'passhash': scrypt_mcf(
|
||||||
|
@ -142,6 +150,25 @@ class DB(object):
|
||||||
).decode('ascii')
|
).decode('ascii')
|
||||||
}, self.secret).decode('ascii')
|
}, self.secret).decode('ascii')
|
||||||
|
|
||||||
|
def mail_subscription_token(self, email, city):
|
||||||
|
"""
|
||||||
|
This function is called by the mail subscription process. It wants
|
||||||
|
to write an email to the mailinglist table.
|
||||||
|
|
||||||
|
:param email: string
|
||||||
|
:param city: string
|
||||||
|
:return: a token with an encoded json dict { email: x, city: y }
|
||||||
|
"""
|
||||||
|
return jwt.encode({
|
||||||
|
'email': email,
|
||||||
|
'city': city
|
||||||
|
}, self.secret).decode('ascii')
|
||||||
|
|
||||||
|
def confirm_subscription(self, token):
|
||||||
|
json = jwt.decode(token, self.secret)
|
||||||
|
return json['email'], json['city']
|
||||||
|
|
||||||
|
|
||||||
def confirm(self, token, city):
|
def confirm(self, token, city):
|
||||||
from user import User
|
from user import User
|
||||||
try:
|
try:
|
||||||
|
|
14
frontend.py
14
frontend.py
|
@ -97,14 +97,20 @@ def display_mail_page(city):
|
||||||
@post('/city/mail/submit/<city>')
|
@post('/city/mail/submit/<city>')
|
||||||
def subscribe_mail(city):
|
def subscribe_mail(city):
|
||||||
email = request.forms['mailaddress']
|
email = request.forms['mailaddress']
|
||||||
code = generate_code(email, city)
|
token = db.mail_subscription_token(email, city)
|
||||||
|
confirm_link = url('city/mail/confirm/' + token)
|
||||||
|
print(confirm_link) # only for local testing
|
||||||
# send mail with code to email
|
# send mail with code to email
|
||||||
|
sendmail(email, "Subscribe to Ticketfrei " + city + " Mail Notifications",
|
||||||
|
body="To subscribe to the mail notifications for Ticketfrei " + city + ", click on this link: " + token)
|
||||||
|
|
||||||
|
|
||||||
@get('/city/mail/confirm/<code>')
|
@get('/city/mail/confirm/<token>')
|
||||||
@view('template/city.tpl')
|
@view('template/city.tpl')
|
||||||
def confirm_subscribe(code):
|
def confirm_subscribe(token):
|
||||||
email, city = parse_code(code)
|
email, city = db.confirm_subscription(token)
|
||||||
|
print(email) # debug
|
||||||
|
print(city) # debug
|
||||||
user = db.by_city(city)
|
user = db.by_city(city)
|
||||||
user.add_subscriber(email)
|
user.add_subscriber(email)
|
||||||
redirect('/city/' + city)
|
redirect('/city/' + city)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import markdown as md
|
||||||
html = md.markdown(markdown)
|
html = md.markdown(markdown)
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<form action="/city/mail/submit/<% print(city) %>" method="post">
|
<form action="/city/mail/submit/{{!city}}" method="post">
|
||||||
<input type="text" name="mailaddress" placeholder="E-Mail address" id="mailaddress">
|
<input type="text" name="mailaddress" placeholder="E-Mail address" id="mailaddress">
|
||||||
<input name='confirm' value='Subscribe to E-Mail notifications' type='submit'/>
|
<input name='confirm' value='Subscribe to E-Mail notifications' type='submit'/>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -65,6 +65,9 @@
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<%
|
||||||
|
# todo: hide this part, if there is already a telegram bot connected.
|
||||||
|
%>
|
||||||
<div>
|
<div>
|
||||||
<h2>Connect with Telegram</h2>
|
<h2>Connect with Telegram</h2>
|
||||||
<p>
|
<p>
|
||||||
|
|
11
user.py
11
user.py
|
@ -74,6 +74,7 @@ slut
|
||||||
hure
|
hure
|
||||||
jude
|
jude
|
||||||
schwuchtel
|
schwuchtel
|
||||||
|
schlampe
|
||||||
fag
|
fag
|
||||||
faggot
|
faggot
|
||||||
nigger
|
nigger
|
||||||
|
@ -116,6 +117,7 @@ schlitz
|
||||||
def save_seen_toot(self, toot_id):
|
def save_seen_toot(self, toot_id):
|
||||||
db.execute("UPDATE seen_toots SET toot_id = ? WHERE user_id = ?;",
|
db.execute("UPDATE seen_toots SET toot_id = ? WHERE user_id = ?;",
|
||||||
(toot_id, self.uid))
|
(toot_id, self.uid))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def get_seen_tweet(self):
|
def get_seen_tweet(self):
|
||||||
db.execute("SELECT tweet_id FROM seen_tweets WHERE user_id = ?;",
|
db.execute("SELECT tweet_id FROM seen_tweets WHERE user_id = ?;",
|
||||||
|
@ -125,6 +127,7 @@ schlitz
|
||||||
def save_seen_tweet(self, tweet_id):
|
def save_seen_tweet(self, tweet_id):
|
||||||
db.execute("UPDATE seen_tweets SET tweet_id = ? WHERE user_id = ?;",
|
db.execute("UPDATE seen_tweets SET tweet_id = ? WHERE user_id = ?;",
|
||||||
(tweet_id, self.uid))
|
(tweet_id, self.uid))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def get_seen_dm(self):
|
def get_seen_dm(self):
|
||||||
db.execute("SELECT message_id FROM seen_dms WHERE user_id = ?;",
|
db.execute("SELECT message_id FROM seen_dms WHERE user_id = ?;",
|
||||||
|
@ -134,6 +137,7 @@ schlitz
|
||||||
def save_seen_dm(self, tweet_id):
|
def save_seen_dm(self, tweet_id):
|
||||||
db.execute("UPDATE seen_dms SET message_id = ? WHERE user_id = ?;",
|
db.execute("UPDATE seen_dms SET message_id = ? WHERE user_id = ?;",
|
||||||
(tweet_id, self.uid))
|
(tweet_id, self.uid))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def get_mailinglist(self):
|
def get_mailinglist(self):
|
||||||
db.execute("SELECT email FROM mailinglist WHERE user_id = ? AND active = 1;", (self.uid, ))
|
db.execute("SELECT email FROM mailinglist WHERE user_id = ? AND active = 1;", (self.uid, ))
|
||||||
|
@ -146,10 +150,12 @@ schlitz
|
||||||
def save_seen_mail(self, mail_date):
|
def save_seen_mail(self, mail_date):
|
||||||
db.execute("UPDATE seen_mail SET mail_date = ? WHERE user_id = ?;",
|
db.execute("UPDATE seen_mail SET mail_date = ? WHERE user_id = ?;",
|
||||||
(mail_date, self.uid))
|
(mail_date, self.uid))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def set_trigger_words(self, patterns):
|
def set_trigger_words(self, patterns):
|
||||||
db.execute("UPDATE triggerpatterns SET patterns = ? WHERE user_id = ?;",
|
db.execute("UPDATE triggerpatterns SET patterns = ? WHERE user_id = ?;",
|
||||||
(patterns, self.uid))
|
(patterns, self.uid))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def get_trigger_words(self):
|
def get_trigger_words(self):
|
||||||
db.execute("SELECT patterns FROM triggerpatterns WHERE user_id = ?;",
|
db.execute("SELECT patterns FROM triggerpatterns WHERE user_id = ?;",
|
||||||
|
@ -157,11 +163,13 @@ schlitz
|
||||||
return db.cur.fetchone()[0]
|
return db.cur.fetchone()[0]
|
||||||
|
|
||||||
def add_subscriber(self, email):
|
def add_subscriber(self, email):
|
||||||
db.execute("INSERT INTO mailinglist(user_id, email, active VALUES(?, ?, ?);", (self.uid, email, 1))
|
db.execute("INSERT INTO mailinglist(user_id, email, active) VALUES(?, ?, ?);", (self.uid, email, 1))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def set_badwords(self, words):
|
def set_badwords(self, words):
|
||||||
db.execute("UPDATE badwords SET words = ? WHERE user_id = ?;",
|
db.execute("UPDATE badwords SET words = ? WHERE user_id = ?;",
|
||||||
(words, self.uid))
|
(words, self.uid))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def get_badwords(self):
|
def get_badwords(self):
|
||||||
db.execute("SELECT words FROM badwords WHERE user_id = ?;",
|
db.execute("SELECT words FROM badwords WHERE user_id = ?;",
|
||||||
|
@ -237,6 +245,7 @@ schlitz
|
||||||
def set_markdown(self, markdown):
|
def set_markdown(self, markdown):
|
||||||
db.execute("UPDATE cities SET markdown = ? WHERE user_id = ?;",
|
db.execute("UPDATE cities SET markdown = ? WHERE user_id = ?;",
|
||||||
(markdown, self.uid))
|
(markdown, self.uid))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def get_city(self):
|
def get_city(self):
|
||||||
db.execute("SELECT city FROM cities WHERE user_id == ?;", (self.uid, ))
|
db.execute("SELECT city FROM cities WHERE user_id == ?;", (self.uid, ))
|
||||||
|
|
Loading…
Reference in a new issue