aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/emails.py20
-rw-r--r--pyaggr3g470r/views.py24
2 files changed, 40 insertions, 4 deletions
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