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 %} -##

Members page

-##

Register

-##

Sign in

-##

Home page (accessible to anyone)

-##

Member page (login required)

-##

Sign out

-## {% 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 = '''
@@ -470,6 +487,9 @@ def create_app():

 

Deleted user: ''' + str(u.username) + '''

\n

 

+''' + role_link + ''' +

 

+ ''' else: content = ''' @@ -536,7 +556,18 @@ def create_app(): @app.route('/test') def test_peer(): - u = User.query.filter_by(username='kf7eel').first() + #user = User( + # username='admin3', + # email_confirmed_at=datetime.datetime.utcnow(), + # password=user_manager.hash_password('admin'), + # ) + #user.roles.append(Role(name='Admin')) + #user.roles.append(Role(name='User')) + #user.add_roles('Admin') + #db.session.add(user) + #db.session.commit() + #u = User.query.filter_by(username='kf7eel').first() + #u = Role.query.all() ## u = User.query.filter(User.dmr_ids.contains('3153591')).first() #u = User.query.all() ## #tu = User.query().all() @@ -571,9 +602,33 @@ def create_app(): #db.session.commit() #db.session.add(u) #db.session.commit() - print(u.active) +## admin_role = UserRoles( +## user_id=3, +## role_id=1, +## ) +## user_role = UserRoles( +## user_id=3, +## role_id=2, +## ) +## db.session.add(user_role) +## db.session.add(admin_role) +## db.session.commit() + #print(role) ## for i in u: ## print(i.username) + u = User.query.filter_by(username='kf7eel').first() + print(u.id) + u_role = UserRoles.query.filter_by(user_id=u.id).first() + #if u_role.role_id == 2: + # print('userhasjkdhfdsejksfdahjkdhjklhjkhjkl') +## print(u.has_roles('Admin')) + u_role.role_id = 1 + print(u_role.user_id) + #u_role = UserRoles.query.filter_by(id=2).first().role_id + #u_role = 1 + db.session.commit() + #u_role = UserRoles.query.filter_by(id=u.id).first().role_id + #print(u_role) return str(u) @app.route('/add_admin', methods=['POST', 'GET'])