Skip to content

Commit

Permalink
Updated for auth2 login (/ssologin)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmushtaq committed May 9, 2024
1 parent f1b3d55 commit 46952c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
29 changes: 14 additions & 15 deletions wildlifecompliance/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,23 @@ def belongs_to_list(user, group_names):
return user.groups.filter(name__in=group_names).exists()


def is_model_backend(request):
# Return True if user logged in via single sign-on (i.e. an internal)
logger.debug(
'helpers.is_model_backend(): {0}'.format(
request.session.get('_auth_user_backend')
))
return 'ModelBackend' in request.session.get('_auth_user_backend')
#def is_model_backend(request):
# # Return True if user logged in via single sign-on (i.e. an internal)
# logger.debug(
# 'helpers.is_model_backend(): {0}'.format(
# request.session.get('_auth_user_backend')
# ))
# return 'ModelBackend' in request.session.get('_auth_user_backend')


def is_email_auth_backend(request):
# Return True if user logged in via social_auth (i.e. an external user
# signing in with a login-token)
return 'EmailAuth' in request.session.get('_auth_user_backend')
#def is_email_auth_backend(request):
# # Return True if user logged in via social_auth (i.e. an external user
# # signing in with a login-token)
# return 'EmailAuth' in request.session.get('_auth_user_backend')


def is_wildlifecompliance_admin(request):
return request.user.is_authenticated() and \
is_model_backend(request) and \
in_dbca_domain(request) and \
(
request.user.has_perm('wildlifecompliance.system_administrator') or
Expand All @@ -100,7 +99,6 @@ def is_wildlifecompliance_payment_officer(request):
PAYMENTS_GROUP_NAME = 'Wildlife Compliance - Payment Officers'

is_payment_officer = request.user.is_authenticated() and \
is_model_backend(request) and \
in_dbca_domain(request) and \
(
request.user.groups.filter(name__in=[PAYMENTS_GROUP_NAME]).exists()
Expand All @@ -125,7 +123,7 @@ def in_dbca_domain(request):

def is_departmentUser(request):
return request.user.is_authenticated() and (
((is_model_backend(request) or settings.ALLOW_EMAIL_ADMINS) and in_dbca_domain(request)) or
(settings.ALLOW_EMAIL_ADMINS and in_dbca_domain(request)) or
is_compliance_management_approved_external_user(request)
)

Expand All @@ -146,7 +144,8 @@ def is_reception(request):


def is_customer(request):
return request.user.is_authenticated() and is_email_auth_backend(request)
#return request.user.is_authenticated() and is_email_auth_backend(request)
return request.user.is_authenticated() and not request.user.is_staff


def is_internal(request):
Expand Down
11 changes: 2 additions & 9 deletions wildlifecompliance/templates/wildlifecompliance/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,15 @@ <h3>
</strong></p>
-->
{% bootstrap_messages %}
<form method="post" action="{% url "social:complete" backend="email" %}">
{% csrf_token %}
{% bootstrap_form form %}
<div id="submit-container">
{% bootstrap_button 'Submit' button_class='btn-primary' %}
</div>
</form>
<p>Submit your email to login or start the new-user registration process.</p>
<a class="btn btn-primary" href="{{ request.get_full_path }}ssologin">Login</a>
<hr>
<h4>
Wildlife Licensing Password-less Logins
</h4>
<p>
At the Department of Biodiversity, Conservation and Attractions, we employ a password-less authentication system, meaning you never need to remember
a password. When you need to login to a site, such as Wildlife Licensing, simply enter your email and an
authentication link will be sent to your registered email address. From there, simply follow the link to complete the login process.
authentication code will be sent to your registered email address. From there, enter the code on screen to complete the login process.
</p>
</div>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions wildlifecompliance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from datetime import datetime, timedelta

from wildlifecompliance.helpers import is_internal, prefer_compliance_management, is_model_backend, in_dbca_domain, \
from wildlifecompliance.helpers import is_internal, prefer_compliance_management, in_dbca_domain, \
is_compliance_internal_user, is_wildlifecompliance_admin, is_compliance_management_callemail_readonly_user, belongs_to, \
is_compliance_management_approved_external_user, is_customer
from wildlifecompliance.forms import *
Expand Down Expand Up @@ -374,4 +374,4 @@ def getPrivateFile(request):

return HttpResponse(the_data, content_type=mimetypes.types_map['.'+str(extension)])

return HttpResponse()
return HttpResponse()

0 comments on commit 46952c9

Please sign in to comment.