aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyaggr3g470r/emails.py22
-rw-r--r--pyaggr3g470r/templates/admin/dashboard.html5
-rw-r--r--pyaggr3g470r/views.py30
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 @@
<td>
<a href="/admin/user/{{ user.id }}/"><i class="glyphicon glyphicon-user" title="{{ _('View this user') }}<"></i></a>
<a href="/admin/edit_user/{{ user.id }}/"><i class="glyphicon glyphicon-edit" title="{{ _('Edit this user') }}"></i></a>
+ {% if user.apikey == "" %}
+ <a href="/admin/enable_user/{{ user.id }}/"><i class="glyphicon glyphicon-ok-circle" title="Disable API key of this user"></i></a>
+ {% else %}
+ <a href="/admin/disable_user/{{ user.id }}/"><i class="glyphicon glyphicon-ban-circle" title="Enable API key of this user"></i></a>
+ {% endif %}
<a href="/admin/delete_user/{{ user.id }}/"><i class="glyphicon glyphicon-remove" title="{{ _('Delete this user') }}" onclick="return confirm('{{ _('You are going to delete this account.') }}');"></i></a>
</td>
</tr>
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/<int:user_id>/', methods=['GET'])
+@app.route('/admin/disable_user/<int:user_id>/', 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
bgstack15