Skip to content
Permalink
Browse files

#254 implemented optional webapp-access authentication

  • Loading branch information...
justb4 committed Jun 17, 2019
1 parent 8e123f9 commit 50ea5873127f51e92c727f250cdc0a0cd2994e76
@@ -31,6 +31,7 @@ ENV LC_ALL="en_US.UTF-8" \
GHC_WWW_LINK_EXCEPTION_CHECK=False \
GHC_ADMIN_EMAIL='you@example.com' \
GHC_RUNNER_IN_WEBAPP=False \
GHC_REQUIRE_WEBAPP_AUTH=False \
GHC_LOG_LEVEL=30 \
GHC_LOG_FORMAT='%(asctime)s - %(name)s - %(levelname)s - %(message)s' \
GHC_NOTIFICATIONS_EMAIL='you2@example.com,them@example.com' \
@@ -104,6 +104,26 @@ def before_request():
if not hasattr(g, 'current_lang'):
g.current_lang = 'en'

if CONFIG['GHC_REQUIRE_WEBAPP_AUTH'] is True:
# Login is required to access GHC Webapp.
# We need to pass-through static resources like CSS.
if any(['/static/' in request.path,
request.path.endswith('.ico'),
g.user.is_authenticated(), # This is from Flask-Login
(request.endpoint is not None
and getattr(APP.view_functions[request.endpoint],
'is_public', False))]):
return # Access granted
else:
return redirect(url_for('login'))


# Marks (endpoint-) function as always to be accessible
# (used for GHC_REQUIRE_WEBAPP_AUTH)
def public_route(decorated_function):
decorated_function.is_public = True
return decorated_function


@APP.teardown_appcontext
def shutdown_session(exception=None):
@@ -814,6 +834,7 @@ def get_check_edit_form(check_class):


@APP.route('/login', methods=['GET', 'POST'])
@public_route
def login():
"""login"""
if request.method == 'GET':
@@ -858,6 +879,7 @@ def logout():


@APP.route('/reset_req', methods=['GET', 'POST'])
@public_route
def reset_req():
"""
Reset password request handling.
@@ -914,6 +936,7 @@ def reset_req():


@APP.route('/reset/<token>', methods=['GET', 'POST'])
@public_route
def reset(token=None):
"""
Reset password submit form handling.
@@ -49,6 +49,7 @@
GHC_SITE_TITLE = 'GeoHealthCheck Demonstration'
GHC_SITE_URL = 'http://host'
GHC_RUNNER_IN_WEBAPP = True
GHC_REQUIRE_WEBAPP_AUTH = False
# 10=DEBUG 20=INFO 30=WARN(ING) 40=ERROR 50=FATAL/CRITICAL
GHC_LOG_LEVEL = 30
GHC_LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
@@ -10,12 +10,19 @@ <h2>{{ _('Login') }} <i class="fa fa-sign-in fa-fw"></i></h2>
<div class="form-group">
<button type="submit" class="btn btn-success">{{ _('Sign in') }}</button>
</div>
{% if not config['GHC_REQUIRE_WEBAPP_AUTH'] %}
<div>
<a href="{{ url_for('register', lang=g.current_lang) }}">{{ _('Register') }}</a>
</div>
{% endif %}
<div>
<a href="{{ url_for('reset_req', lang=g.current_lang) }}">{{ _('Forgot password?') }}</a>
</div>
{% if config['GHC_REQUIRE_WEBAPP_AUTH'] %}
<div>
<strong>{{ _('This app requires an authenticated user') }}</strong>
</div>
{% endif %}
</form>
</div>
{% endblock %}

0 comments on commit 50ea587

Please sign in to comment.
You can’t perform that action at this time.