diff --git a/user_managment/app.py b/user_managment/app.py index 42d9ead..4555605 100644 --- a/user_managment/app.py +++ b/user_managment/app.py @@ -189,6 +189,11 @@ def create_app(): def _after_user_registered_hook(sender, user, **extra): edit_user = User.query.filter(User.username == user.username).first() edit_user.dmr_ids = get_ids(user.username) + user_role = UserRoles( + user_id=edit_user.id, + role_id=2, + ) + db.session.add(user_role) db.session.commit() # The Home page is accessible to anyone @@ -330,18 +335,6 @@ def create_app(): @app.route('/members') @login_required # User must be authenticated def member_page(): - # String-based templates -## return render_template_string(""" -## {% extends "flask_user_layout.html" %} -## {% block content %} -##
Home page (accessible to anyone)
-##Member page (login required)
-## -## {% endblock %} -## """) content = 'Mem only' return render_template('flask_user_layout.html', markup_content = content) @@ -414,6 +407,21 @@ def create_app(): db.session.delete(delete_user) db.session.commit() content = '''Deleted user: ''' + str(delete_user.username) + '''
\n''' + + elif request.method == 'GET' and request.args.get('callsign') and request.args.get('make_user_admin') == 'true': + u = User.query.filter_by(username=request.args.get('callsign')).first() + u_role = UserRoles.query.filter_by(user_id=u.id).first() + u_role.role_id = 1 + db.session.commit() + content = '''User now Admin: ''' + str(request.args.get('callsign')) + '''
\n''' + + elif request.method == 'GET' and request.args.get('callsign') and request.args.get('make_user_admin') == 'false': + u = User.query.filter_by(username=request.args.get('callsign')).first() + u_role = UserRoles.query.filter_by(user_id=u.id).first() + u_role.role_id = 2 + db.session.commit() + content = '''Admin now a user: ''' + str(request.args.get('callsign')) + '''
\n''' + elif request.method == 'POST' and request.form.get('callsign') and not request.form.get('user_status') or request.method == 'GET' and request.args.get('callsign'): # and request.form.get('user_status') : if request.args.get('callsign'): @@ -421,6 +429,15 @@ def create_app(): if request.form.get('callsign'): callsign = request.form.get('callsign') u = User.query.filter_by(username=callsign).first() + u_role = UserRoles.query.filter_by(user_id=u.id).first() + if u_role.role_id == 2: + # Link to promote to Admin + role_link = '''Make Admin: ''' + str(u.username) + '''
\n''' + if u_role.role_id == 1: + # Link to promote to User + role_link = '''Revert to user: ''' + str(u.username) + '''
\n''' + + content = '''