mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +00:00
chg: [user_management] add user role_management
This commit is contained in:
parent
64ff94ce5f
commit
1dac8177fe
5 changed files with 39 additions and 21 deletions
|
@ -216,6 +216,10 @@ def login():
|
||||||
print(next_page)
|
print(next_page)
|
||||||
return render_template("login.html", next_page=next_page)
|
return render_template("login.html", next_page=next_page)
|
||||||
|
|
||||||
|
@app.route('/role', methods=['POST', 'GET'])
|
||||||
|
def role():
|
||||||
|
return 'ERROR role'
|
||||||
|
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
@login_required
|
@login_required
|
||||||
def logout():
|
def logout():
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
# -*-coding:UTF-8 -*
|
|
||||||
|
|
||||||
from functools import wraps
|
|
||||||
from flask_login import LoginManager, current_user, login_user, logout_user, login_required
|
|
||||||
|
|
||||||
from flask import request
|
|
||||||
|
|
||||||
def login_required(role="ANY"):
|
|
||||||
@wraps(role)
|
|
||||||
def decorated_view(*args, **kwargs):
|
|
||||||
if not current_user.is_authenticated:
|
|
||||||
return current_app.login_manager.unauthorized()
|
|
||||||
elif (not current_user.is_in_role(role)) and (role != "ANY"):
|
|
||||||
return login_manager.unauthorized()
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
return decorated_view
|
|
30
var/www/modules/Role_Manager.py
Normal file
30
var/www/modules/Role_Manager.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*-coding:UTF-8 -*
|
||||||
|
|
||||||
|
from functools import wraps
|
||||||
|
from flask_login import LoginManager, current_user, login_user, logout_user, login_required
|
||||||
|
|
||||||
|
from flask import request, current_app
|
||||||
|
|
||||||
|
login_manager = LoginManager()
|
||||||
|
login_manager.login_view = 'role'
|
||||||
|
|
||||||
|
def login_admin(func):
|
||||||
|
@wraps(func)
|
||||||
|
def decorated_view(*args, **kwargs):
|
||||||
|
if not current_user.is_authenticated:
|
||||||
|
return login_manager.unauthorized()
|
||||||
|
elif (not current_user.is_in_role('admin')):
|
||||||
|
return login_manager.unauthorized()
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
return decorated_view
|
||||||
|
|
||||||
|
def login_analyst(func):
|
||||||
|
@wraps(func)
|
||||||
|
def decorated_view(*args, **kwargs):
|
||||||
|
if not current_user.is_authenticated:
|
||||||
|
return login_manager.unauthorized()
|
||||||
|
elif (not current_user.is_in_role('analyst')):
|
||||||
|
return login_manager.unauthorized()
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
return decorated_view
|
|
@ -5,7 +5,9 @@
|
||||||
Flask functions and routes for the trending modules page
|
Flask functions and routes for the trending modules page
|
||||||
'''
|
'''
|
||||||
import redis
|
import redis
|
||||||
from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for
|
from flask import Flask, render_template, jsonify, request, Blueprint, current_app, redirect, url_for
|
||||||
|
|
||||||
|
from Role_Manager import login_admin, login_analyst
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
@ -220,6 +222,7 @@ def update_tag_last_seen(tag, tag_first_seen, tag_last_seen):
|
||||||
|
|
||||||
@Tags.route("/tags/", methods=['GET'])
|
@Tags.route("/tags/", methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
|
@login_admin
|
||||||
def Tags_page():
|
def Tags_page():
|
||||||
date_from = request.args.get('date_from')
|
date_from = request.args.get('date_from')
|
||||||
date_to = request.args.get('date_to')
|
date_to = request.args.get('date_to')
|
||||||
|
@ -469,6 +472,7 @@ def remove_tag():
|
||||||
|
|
||||||
@Tags.route("/Tags/confirm_tag")
|
@Tags.route("/Tags/confirm_tag")
|
||||||
@login_required
|
@login_required
|
||||||
|
@login_analyst
|
||||||
def confirm_tag():
|
def confirm_tag():
|
||||||
|
|
||||||
#TODO verify input
|
#TODO verify input
|
||||||
|
|
|
@ -17,8 +17,6 @@ from flask_login import login_required
|
||||||
from Date import Date
|
from Date import Date
|
||||||
from HiddenServices import HiddenServices
|
from HiddenServices import HiddenServices
|
||||||
|
|
||||||
from Decorator import login_required
|
|
||||||
|
|
||||||
# ============ VARIABLES ============
|
# ============ VARIABLES ============
|
||||||
import Flask_config
|
import Flask_config
|
||||||
|
|
||||||
|
@ -236,7 +234,6 @@ def delete_auto_crawler(url):
|
||||||
# ============= ROUTES ==============
|
# ============= ROUTES ==============
|
||||||
|
|
||||||
@hiddenServices.route("/crawlers/", methods=['GET'])
|
@hiddenServices.route("/crawlers/", methods=['GET'])
|
||||||
#@login_required(role="ADMIN")
|
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard():
|
def dashboard():
|
||||||
crawler_metadata_onion = get_crawler_splash_status('onion')
|
crawler_metadata_onion = get_crawler_splash_status('onion')
|
||||||
|
|
Loading…
Reference in a new issue