diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-05-15 07:12:06 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-05-15 07:12:06 +0200 |
commit | a14da171a0cd3f5023e97b6b36e6f8edee91376e (patch) | |
tree | 7f78690d2a7f118d66f1dbe00ac1261311cc17e0 /pyaggr3g470r/views.py | |
parent | Bugfix. (diff) | |
download | newspipe-a14da171a0cd3f5023e97b6b36e6f8edee91376e.tar.gz newspipe-a14da171a0cd3f5023e97b6b36e6f8edee91376e.tar.bz2 newspipe-a14da171a0cd3f5023e97b6b36e6f8edee91376e.zip |
test account activation by admin.
Diffstat (limited to 'pyaggr3g470r/views.py')
-rw-r--r-- | pyaggr3g470r/views.py | 30 |
1 files changed, 30 insertions, 0 deletions
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 |