From a14da171a0cd3f5023e97b6b36e6f8edee91376e Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Thu, 15 May 2014 07:12:06 +0200 Subject: test account activation by admin. --- pyaggr3g470r/emails.py | 22 ++++++++++++++++++--- pyaggr3g470r/templates/admin/dashboard.html | 5 +++++ pyaggr3g470r/views.py | 30 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/pyaggr3g470r/emails.py b/pyaggr3g470r/emails.py index c4bcb61f..9507d3ae 100644 --- a/pyaggr3g470r/emails.py +++ b/pyaggr3g470r/emails.py @@ -70,7 +70,25 @@ def new_account_notification(user): try: plaintext = """Hello,\n\nYour account has been created. Click on the following link to confirm it:\n%s\n\nSee you,""" % \ (conf.PLATFORM_URL + 'confirm_account/' + user.activation_key) - + + message = PMMail(api_key = conf.POSTMARK_API_KEY, + subject = "[pyAggr3g470r] Account activation", + sender = conf.ADMIN_EMAIL, + to = user.email, + text_body = plaintext) + + message.send() + except Exception as e: + raise e + else: + pass + +def new_account_activation(user): + if conf.ON_HEROKU: + try: + plaintext = """Hello,\n\nYour account has been activated. You can now connect to the platform:\n%s\n\nSee you,""" % \ + (conf.PLATFORM_URL) + message = PMMail(api_key = conf.POSTMARK_API_KEY, subject = "[pyAggr3g470r] Account activation", sender = conf.ADMIN_EMAIL, @@ -82,8 +100,6 @@ def new_account_notification(user): raise e else: pass - - def new_article_notification(user, feed, article): send_email(conf.ADMIN_EMAIL, user.email, feed, article) \ No newline at end of file diff --git a/pyaggr3g470r/templates/admin/dashboard.html b/pyaggr3g470r/templates/admin/dashboard.html index 4e60ad1d..2a158df9 100644 --- a/pyaggr3g470r/templates/admin/dashboard.html +++ b/pyaggr3g470r/templates/admin/dashboard.html @@ -23,6 +23,11 @@ + {% if user.apikey == "" %} + + {% else %} + + {% endif %} diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 301cd7db..ee610840 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -771,3 +771,33 @@ def delete_user(user_id=None): else: flash(gettext('This user does not exist.'), 'danger') return redirect(redirect_url()) + +@app.route('/admin/enable_user//', methods=['GET']) +@app.route('/admin/disable_user//', methods=['GET']) +@login_required +@admin_permission.require() +def disable_user(user_id=None): + """ + Enable or disable the API key of a user. + """ + user = User.query.filter(User.id == user_id).first() + if user is not None: + if True: + user.activation_key = "" + + # Send the confirmation email + try: + emails.new_account_activation(user) + except Exception as e: + flash(gettext('Problem while sending activation email') + ': ' + str(e), 'danger') + + flash('Account of the user "' + user.nickname + '" successfully activated.', 'success') + else: + import random, base64, hashlib + user.apikey = base64.b64encode(hashlib.sha512( str(random.getrandbits(256)) ).digest(), + random.choice(['rA','aZ','gQ','hH','hG','aR','DD'])).rstrip('==') + flash('Account of the user A"' + user.nickname + '" successfully disabled.', 'success') + db.session.commit() + else: + flash('This user does not exist.', 'danger') + return redirect(redirect_url()) \ No newline at end of file -- cgit