Commit 3b0d5feb2c205b0a07dadbd5121c91f7abc8a4d2

Authored by hitier
1 parent 08d06308

New Site_Login capability

app/auth/routes.py
... ... @@ -20,7 +20,7 @@ def role_required(role):
20 20 if current_app.config['ROLE_DISABLED']:
21 21 return f(*args, **kwargs)
22 22 except KeyError:
23   - # no such config
  23 + # no such config, juste ignore
24 24 pass
25 25 # first check use is logged in
26 26 if not current_user or not current_user.is_authenticated:
... ...
app/main/routes.py
1 1 import json
2 2  
3   -from flask import render_template, make_response, current_app
4   -from flask_login import login_required
  3 +from flask import render_template, make_response, current_app, redirect, url_for, request
  4 +from flask_login import login_required, current_user
5 5  
6 6 from . import bp
7 7  
... ... @@ -10,6 +10,21 @@ from app import db_mgr
10 10 from app.auth.routes import role_required
11 11  
12 12  
  13 +@bp.before_request
  14 +def site_login():
  15 + try:
  16 + if current_app.config['SITE_LOGIN'] \
  17 + and not current_user.is_authenticated:
  18 + return redirect(url_for('auth.login'))
  19 + except KeyError:
  20 + # no such config, juste ignore
  21 + pass
  22 +
  23 +@bp.before_request
  24 +def catch_all_route():
  25 + current_app.logger.info(f"{request.method} {request.path}")
  26 +
  27 +
13 28 @bp.route('/')
14 29 def index():
15 30 return render_template('index.html', subtitle="Page d'accueil")
... ... @@ -40,7 +55,6 @@ def projects():
40 55 @bp.route('/agents')
41 56 @role_required('project')
42 57 def agents():
43   - current_app.logger.info("Accessing agents page")
44 58 # get agents list
45 59 all_agents = Agent.query.order_by(Agent.firstname).all()
46 60 num_agents = len(all_agents)
... ... @@ -80,7 +94,6 @@ def charge_add():
80 94 @bp.route('/charge/agent/<agent_id>')
81 95 @role_required('service')
82 96 def charge_agent(agent_id):
83   - current_app.logger.info("Accessing agent {} page".format(agent_id))
84 97 agent_charges = []
85 98 for [period, charge] in db_mgr.charges_by_agent(agent_id):
86 99 agent_charges.append({"charge": charge, "periode": period})
... ...
resources/pdc_config.py
... ... @@ -20,7 +20,17 @@ class Config(object):
20 20 PDC_LOGS_DIR = os.path.join(root_dir, 'logs')
21 21 PDC_LOGS_FILE = os.path.join(PDC_LOGS_DIR, 'pdc.log')
22 22  
23   - # ROLE_DISABLED = False # Override for role access control
  23 + # Uncomment for role access control
  24 + # if True, will disable any role control on routes
  25 + # note that this doesnt disable the @login_required
  26 + #
  27 + # ROLE_DISABLED = False
  28 +
  29 + # Uncomment for site access control
  30 + # if True, will force login access on any site page
  31 + # note that this doesnt disable the @login_required
  32 + #
  33 + # SITE_LOGIN = False
24 34  
25 35 #
26 36 # No need to Edit below
... ...