Allow adding users from the admin panel

This commit is contained in:
David Hoppenbrouwers
2022-10-09 14:55:49 +02:00
parent 650130d33c
commit f4e543b1f7
3 changed files with 46 additions and 2 deletions

14
main.py
View File

@@ -335,7 +335,7 @@ def register():
request.form['answer'],
):
flash('CAPTCHA answer is incorrect', 'error')
elif not db.add_user(username, hash_password(password), time.time_ns()):
elif not db.register_user(username, hash_password(password), time.time_ns()):
flash('Failed to create account (username may already be taken)', 'error')
else:
flash('Account has been created. You can login now.', 'success')
@@ -491,6 +491,18 @@ def admin_unban_user(user_id):
flash(str(e), 'error')
return redirect(url_for('admin'))
@app.route('/admin/user/new/', methods = ['POST'])
def admin_new_user():
try:
name, password = request.form['name'], request.form['password']
if db.add_user(name, hash_password(password), time.time_ns()):
flash('Added user', 'success')
else:
flash('Failed to add user', 'error')
except Exception as e:
flash(str(e), 'error')
return redirect(url_for('admin'))
@app.route('/admin/restart/', methods = ['POST'])
def admin_restart():
chk, user = _admin_check()