aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-05-13 19:09:10 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-05-13 19:09:10 +0200
commit559f14ed074a6d3f52f1acf62c4c74b0ff0c257e (patch)
tree189ed58a259f4c65dd5d13e98daf058dbff9e1d1
parentUpdated translations. (diff)
downloadnewspipe-559f14ed074a6d3f52f1acf62c4c74b0ff0c257e.tar.gz
newspipe-559f14ed074a6d3f52f1acf62c4c74b0ff0c257e.tar.bz2
newspipe-559f14ed074a6d3f52f1acf62c4c74b0ff0c257e.zip
Integration of mailgun.
-rw-r--r--conf.py4
-rw-r--r--pyaggr3g470r/emails.py20
-rw-r--r--pyaggr3g470r/views.py24
3 files changed, 43 insertions, 5 deletions
diff --git a/conf.py b/conf.py
index a5ebd2e2..f423f69e 100644
--- a/conf.py
+++ b/conf.py
@@ -77,7 +77,9 @@ else:
WEBSERVER_HOST = '0.0.0.0'
WEBSERVER_PORT = int(os.environ.get('PORT', 5000))
- MAIL_ENABLED = False
+ MAIL_ENABLED = True
+ MAILGUN_DOMAIN = "pyaggr3g470r.herokuapp.com"
+ MAILGUN_KEY = os.environ.get('MAILGUN_API_KEY', '')
WEBZINE_ROOT = "/tmp/"
diff --git a/pyaggr3g470r/emails.py b/pyaggr3g470r/emails.py
index 65f89de3..5cd10464 100644
--- a/pyaggr3g470r/emails.py
+++ b/pyaggr3g470r/emails.py
@@ -5,6 +5,8 @@ import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
+import requests
+
import log
import utils
import conf
@@ -63,8 +65,22 @@ def send_email(mfrom, mto, feed, article):
#
# Notifications
#
-def new_account_notification(user, password):
- pass
+def new_account_notification(user):
+ html = """<html>\n<head>\n<title>[pyAggr3g470r] Account activation</title>\n</head>\n<body>\nYour account has been created. Clink on the following to confirm it:%s\n</body>\n</html>""" % \
+ (conf.PLATFORM_URL + 'confirm_account/' + user.activation_key)
+ plaintext = utils.clear_string(html)
+
+ r = requests.post("https://api.mailgun.net/v2/%s/messages" % conf.MAILGUN_DOMAIN,
+ auth=("api", conf.MAILGUN_KEY),
+ data={
+ "from": conf.ADMIN_EMAIL,
+ "to": user.email,
+ "subject": subject,
+ "text": plaintext,
+ "html": html
+ }
+ )
+ return r
def new_article_notification(user, feed, article):
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index 2efa5bf2..db5cd64b 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -184,8 +184,14 @@ def signup():
flash(gettext('Email already used.'), 'warning')
return render_template('signup.html', form=form)
- flash(gettext('Your account has been created. You can now sign in.'), 'success')
- return redirect(url_for('home'))
+ # Send the confirmation email
+ result = emails.new_account_notification(user)
+
+ if result.status_code != 200:
+ flash(gettext('Problem while sending activation email.'), 'danger')
+ else:
+ flash(gettext('Your account has been created. Check your mail to confirm it.'), 'success')
+ return redirect(url_for('home'))
return render_template('signup.html', form=form)
@@ -656,6 +662,20 @@ def delete_account():
flash(gettext('This user does not exist.'), 'danger')
return redirect(url_for('login'))
+@app.route('/confirm_account/<string:activation_key>', methods=['GET'])
+def confirm_account(activation_key=None):
+ """
+ Confirm the account of a user.
+ """
+ if activation_key != "":
+ user = User.query.filter(User.activation_key == activation_key).first()
+ if user is not None:
+ user.activation_key = ""
+ db.session.commit()
+ flash(gettext('Your account has been confirmed.'), 'success')
+ else:
+ flash(gettext('Impossible to confirm this account.'), 'danger')
+ return redirect(url_for('login'))
#
# Views dedicated to administration tasks.
bgstack15