Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect when not connected #174

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 27 additions & 81 deletions clockwork_web/browser_routes/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,13 @@ def route_set_nbr_items_per_page():
# Check if nbr_items_per_page is a positive integer
if type(nbr_items_per_page) == int and nbr_items_per_page > 0:

if current_user.is_authenticated():
# If it is, update this number in the current user's settings and
# retrieve the status code and status message associated to this
# operation
(
status_code,
status_message,
) = current_user.settings_nbr_items_per_page_set(nbr_items_per_page)
else:
# Otherwise, return an error
return (
render_template_with_user_settings(
"error.html",
error_msg=gettext("The user is not authenticated."),
previous_request_args=previous_request_args,
),
403, # Forbidden
)
# If it is, update this number in the current user's settings and
# retrieve the status code and status message associated to this
# operation
(
status_code,
status_message,
) = current_user.settings_nbr_items_per_page_set(nbr_items_per_page)

if status_code == 200:
# If a success has been return, redirect to the settings page
Expand Down Expand Up @@ -195,18 +184,7 @@ def route_set_dark_mode():

# Set the dark mode value to True in the current user's web settings and
# retrieve the status code and status message associated to the operation
if current_user.is_authenticated():
(status_code, status_message) = current_user.settings_dark_mode_enable()
else:
# Otherwise, return an error
return (
render_template_with_user_settings(
"error.html",
error_msg=gettext("The user is not authenticated."),
previous_request_args=previous_request_args,
),
403, # Forbidden
)
(status_code, status_message) = current_user.settings_dark_mode_enable()

if status_code == 200:
# If a success has been returned
Expand Down Expand Up @@ -237,20 +215,10 @@ def route_unset_dark_mode():

# Initialize the request arguments (it is further transferred to the HTML)
previous_request_args = {}
if current_user.is_authenticated():
# Set the dark mode value to False in the current user's web settings and
# retrieve the status code and status message associated to the operation
(status_code, status_message) = current_user.settings_dark_mode_disable()
else:
# Otherwise, return an error
return (
render_template_with_user_settings(
"error.html",
error_msg=gettext("The user is not authenticated."),
previous_request_args=previous_request_args,
),
403, # Forbidden
)

# Set the dark mode value to False in the current user's web settings and
# retrieve the status code and status message associated to the operation
(status_code, status_message) = current_user.settings_dark_mode_disable()

if status_code == 200:
# If a success has been returned
Expand Down Expand Up @@ -496,25 +464,13 @@ def route_set_date_format():
if date_format:
# Check if the date format is supported
if date_format in get_available_date_formats():
if current_user.is_authenticated():
# If the requested date format is expected, update the preferred
# date format of the current user and retrieve the status code
# and status message associated to this operation
(
status_code,
status_message,
) = current_user.settings_date_format_set(date_format)

else:
# Otherwise, return an error
return (
render_template_with_user_settings(
"error.html",
error_msg=gettext("The user is not authenticated."),
previous_request_args=previous_request_args,
),
403, # Forbidden
)
# If the requested date format is expected, update the preferred
# date format of the current user and retrieve the status code
# and status message associated to this operation
(
status_code,
status_message,
) = current_user.settings_date_format_set(date_format)

if status_code == 200:
# If a success has been return, redirect to the home page
Expand Down Expand Up @@ -578,24 +534,14 @@ def route_set_time_format():
if time_format:
# Check if the date format is supported
if time_format in get_available_time_formats():
if current_user.is_authenticated():
# If the requested time format is expected, update the preferred
# time format of the current user and retrieve the status code
# and status message associated to this operation
(
status_code,
status_message,
) = current_user.settings_time_format_set(time_format)
else:
# Otherwise, return an error
return (
render_template_with_user_settings(
"error.html",
error_msg=gettext("The user is not authenticated."),
previous_request_args=previous_request_args,
),
403, # Forbidden
)

# If the requested time format is expected, update the preferred
# time format of the current user and retrieve the status code
# and status message associated to this operation
(
status_code,
status_message,
) = current_user.settings_time_format_set(time_format)

if status_code == 200:
# If a success has been return, redirect to the home page
Expand Down
4 changes: 2 additions & 2 deletions clockwork_web/login_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ def route_callback():
from flask import current_app

current_app.logger.debug(
"called login_user(user) for user with email %s, user.is_authenticated() is %s",
"called login_user(user) for user with email %s, user.is_authenticated is %s",
user.mila_email_username,
user.is_authenticated(),
user.is_authenticated,
)
# Send user back to homepage
return redirect(url_for("index"))
Expand Down
4 changes: 2 additions & 2 deletions clockwork_web/server_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def have_same_users(user1: str, user2: str):
@babel.localeselector
def get_locale():
# If the user is authenticated
if current_user and current_user.is_authenticated():
if current_user and current_user.is_authenticated:

return current_user.get_language()

Expand Down Expand Up @@ -251,7 +251,7 @@ def index():
where people can click on the "login" button on the web interface.
"""

if current_user.is_authenticated():
if current_user.is_authenticated:
app.logger.debug("in route for '/'; redirecting to jobs/")
return redirect("jobs/")
else:
Expand Down
4 changes: 2 additions & 2 deletions clockwork_web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h4><span>{{ gettext("Alpha version!") }}</span></h4>
{% endif %}
</a>
</div>
{% if current_user.is_authenticated() %}
{% if current_user.is_authenticated %}
<div class="col">
<nav class="navbar-expand-lg">
<div class="container-fluid">
Expand Down Expand Up @@ -126,7 +126,7 @@ <h4><span>{{ gettext("Alpha version!") }}</span></h4>
</div>

{% block form %}
{% if request.path != '/jobs/dashboard' and current_user.is_authenticated() %}
{% if request.path != '/jobs/dashboard' and current_user.is_authenticated %}
<!-- Search jobs form -->
<div id="formBlock">
<div class="search_button formCollapse {{ 'collapse' if request.path != '/jobs/search' }} {{ 'show' if request.path == '/jobs/search' }}" id="mainCollapse">
Expand Down
12 changes: 0 additions & 12 deletions clockwork_web/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ def boolean(value):
"actions"
] = False

# If we don't set those two values ourselves, we are going
# to have users being asked to login every time they click
# on a link or refresh the pages.
def is_authenticated(self):
return True

def is_active(self):
return self.status == "enabled"

def get_id(self):
return self.mila_email_username

Expand Down Expand Up @@ -350,6 +341,3 @@ def get_web_settings(self):
A dictionary presenting the default web settings.
"""
return self.web_settings

def is_authenticated(self):
return False
Loading
Loading