use local mail daemon for confirmation links
This commit is contained in:
parent
2b6b3a2263
commit
4850860f82
23
frontend.py
23
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,20 +27,18 @@ 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)
|
sendmail(
|
||||||
send_confirmation_mail(confirm_link, email)
|
email,
|
||||||
|
"[Ticketfrei] Confirm your account",
|
||||||
|
"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.')
|
return dict(info='Confirmation mail sent.')
|
||||||
|
|
||||||
|
|
||||||
def send_confirmation_mail(confirm_link, email):
|
|
||||||
m = sendmail.Mailer()
|
|
||||||
try:
|
|
||||||
m.send("Complete your registration here: " + confirm_link, email,
|
|
||||||
"[Ticketfrei] Confirm your account")
|
|
||||||
except smtplib.SMTPRecipientsRefused:
|
|
||||||
return "Please enter a valid E-Mail address."
|
|
||||||
|
|
||||||
|
|
||||||
@get('/confirm/<token>')
|
@get('/confirm/<token>')
|
||||||
@view('template/propaganda.tpl')
|
@view('template/propaganda.tpl')
|
||||||
def confirm(token):
|
def confirm(token):
|
||||||
|
|
18
sendmail.py
18
sendmail.py
|
@ -1,11 +1,12 @@
|
||||||
#!/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
|
||||||
|
from getpass import getuser
|
||||||
|
import smtplib
|
||||||
|
from socket import getfqdn
|
||||||
|
import ssl
|
||||||
|
|
||||||
|
|
||||||
class Mailer(object):
|
class Mailer(object):
|
||||||
|
@ -63,6 +64,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