forked from ticketfrei/ticketfrei
merge
This commit is contained in:
commit
10fb150c21
|
@ -21,7 +21,7 @@ class MastodonBot(Bot):
|
||||||
m = Mastodon(*user.get_masto_credentials())
|
m = Mastodon(*user.get_masto_credentials())
|
||||||
try:
|
try:
|
||||||
notifications = m.notifications()
|
notifications = m.notifications()
|
||||||
except: # mastodon.Mastodon.MastodonAPIError is unfortunately not in __init__.py
|
except Exception:
|
||||||
logger.error("Unknown Mastodon API Error.", exc_info=True)
|
logger.error("Unknown Mastodon API Error.", exc_info=True)
|
||||||
return mentions
|
return mentions
|
||||||
for status in notifications:
|
for status in notifications:
|
||||||
|
|
17
backend.py
17
backend.py
|
@ -4,7 +4,7 @@ import active_bots
|
||||||
from config import config
|
from config import config
|
||||||
from db import db
|
from db import db
|
||||||
import logging
|
import logging
|
||||||
import sendmail
|
from sendmail import sendmail
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,12 +30,9 @@ if __name__ == '__main__':
|
||||||
for bot2 in bots:
|
for bot2 in bots:
|
||||||
bot2.post(user, status)
|
bot2.post(user, status)
|
||||||
time.sleep(60) # twitter rate limit >.<
|
time.sleep(60) # twitter rate limit >.<
|
||||||
except:
|
except Exception:
|
||||||
logger.error('Shutdown', exc_info=True)
|
logger.error('Shutdown.', exc_info=True)
|
||||||
mailer = sendmail.Mailer()
|
try:
|
||||||
try:
|
sendmail(config['web']['contact'], 'Ticketfrei Shutdown')
|
||||||
mailer.send('', config['web']['contact'],
|
except Exception:
|
||||||
'Ticketfrei Crash Report',
|
logger.error('Could not inform admin.', exc_info=True)
|
||||||
attachment=config['logging']['logpath'])
|
|
||||||
except:
|
|
||||||
logger.error('Mail sending failed', exc_info=True)
|
|
||||||
|
|
2
db.py
2
db.py
|
@ -123,7 +123,7 @@ class DB(object):
|
||||||
return None # invalid token
|
return None # invalid token
|
||||||
if 'passhash' in json.keys():
|
if 'passhash' in json.keys():
|
||||||
# create user
|
# create user
|
||||||
self.execute("INSERT INTO user (passhash) VALUES(?, ?);",
|
self.execute("INSERT INTO user (passhash) VALUES(?);",
|
||||||
(json['passhash'], ))
|
(json['passhash'], ))
|
||||||
uid = self.cur.lastrowid
|
uid = self.cur.lastrowid
|
||||||
else:
|
else:
|
||||||
|
|
40
frontend.py
40
frontend.py
|
@ -5,9 +5,8 @@ from config import config
|
||||||
from db import db
|
from db import db
|
||||||
import logging
|
import logging
|
||||||
import tweepy
|
import tweepy
|
||||||
import sendmail
|
from sendmail import sendmail
|
||||||
from session import SessionPlugin
|
from session import SessionPlugin
|
||||||
import smtplib
|
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,18 +27,19 @@ def register_post():
|
||||||
if db.by_email(email):
|
if db.by_email(email):
|
||||||
return dict(error='Email address already in use.')
|
return dict(error='Email address already in use.')
|
||||||
# send confirmation mail
|
# send confirmation mail
|
||||||
confirm_link = request.url + "/../confirm/" + db.user_token(email, password)
|
|
||||||
send_confirmation_mail(confirm_link, email)
|
|
||||||
return dict(info='Confirmation mail sent.')
|
|
||||||
|
|
||||||
|
|
||||||
def send_confirmation_mail(confirm_link, email):
|
|
||||||
m = sendmail.Mailer()
|
|
||||||
try:
|
try:
|
||||||
m.send("Complete your registration here: " + confirm_link, email,
|
sendmail(
|
||||||
"[Ticketfrei] Confirm your account")
|
email,
|
||||||
except smtplib.SMTPRecipientsRefused:
|
"[Ticketfrei] Confirm your account",
|
||||||
return "Please enter a valid E-Mail address."
|
"Complete your registration here: %s://%s/confirm/%s" % (
|
||||||
|
request.urlparts.scheme,
|
||||||
|
request.urlparts.netloc,
|
||||||
|
db.user_token(email, password)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return dict(info='Confirmation mail sent.')
|
||||||
|
except Exception:
|
||||||
|
return dict(error='Could not send confirmation mail.')
|
||||||
|
|
||||||
|
|
||||||
@get('/confirm/<token>')
|
@get('/confirm/<token>')
|
||||||
|
@ -56,10 +56,14 @@ def confirm(token):
|
||||||
@view('template/login.tpl')
|
@view('template/login.tpl')
|
||||||
def login_post():
|
def login_post():
|
||||||
# check login
|
# check login
|
||||||
if db.by_email(request.forms.get('email', '')) \
|
try:
|
||||||
.check_password(request.forms.get('pass', '')):
|
if db.by_email(request.forms.get('email', '')) \
|
||||||
return redirect('/settings')
|
.check_password(request.forms.get('pass', '')):
|
||||||
return dict(error='Authentication failed.')
|
return redirect('/settings')
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
return dict(error='Authentication failed.')
|
||||||
|
|
||||||
|
|
||||||
@get('/settings')
|
@get('/settings')
|
||||||
|
@ -146,7 +150,7 @@ def login_mastodon(user):
|
||||||
return dict(
|
return dict(
|
||||||
info='Thanks for supporting decentralized social networks!'
|
info='Thanks for supporting decentralized social networks!'
|
||||||
)
|
)
|
||||||
except:
|
except Exception:
|
||||||
logger.error('Login to Mastodon failed.', exc_info=True)
|
logger.error('Login to Mastodon failed.', exc_info=True)
|
||||||
return dict(error='Login to Mastodon failed.')
|
return dict(error='Login to Mastodon failed.')
|
||||||
|
|
||||||
|
|
18
sendmail.py
18
sendmail.py
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import smtplib
|
|
||||||
import ssl
|
|
||||||
from config import config
|
from config import config
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.application import MIMEApplication
|
from email.mime.application import MIMEApplication
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
import logging
|
import logging
|
||||||
|
from getpass import getuser
|
||||||
|
import smtplib
|
||||||
|
from socket import getfqdn
|
||||||
|
import ssl
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -68,6 +69,17 @@ class Mailer(object):
|
||||||
return "Sent mail to " + recipient + ": " + subject
|
return "Sent mail to " + recipient + ": " + subject
|
||||||
|
|
||||||
|
|
||||||
|
def sendmail(to, subject, body=''):
|
||||||
|
msg = MIMEMultipart()
|
||||||
|
msg['From'] = '%s@%s' % (getuser(), getfqdn())
|
||||||
|
msg['To'] = to
|
||||||
|
msg['Subject'] = subject
|
||||||
|
msg.attach(MIMEText(body))
|
||||||
|
|
||||||
|
with smtplib.SMTP('localhost') as smtp:
|
||||||
|
smtp.send_message(msg)
|
||||||
|
|
||||||
|
|
||||||
# For testing:
|
# For testing:
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
m = Mailer()
|
m = Mailer()
|
||||||
|
|
Loading…
Reference in a new issue