Skip to content

Commit

Permalink
Fixes #10337: Display SSO links when local authentication fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Sep 15, 2022
1 parent 157a45b commit e05696d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/version-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [#10305](https://github.com/netbox-community/netbox/issues/10305) - Fix Virtual Chassis master field cannot be null according to the API
* [#10307](https://github.com/netbox-community/netbox/issues/10307) - Correct value for "Passive 48V (4-pair)" PoE type selection
* [#10333](https://github.com/netbox-community/netbox/issues/10333) - Show available values for `ui_visibility` field of CustomField for CSV import
* [#10337](https://github.com/netbox-community/netbox/issues/10337) - Display SSO links when local authentication fails
* [#10362](https://github.com/netbox-community/netbox/issues/10362) - Correct display of custom fields when editing an L2VPN termination

---
Expand Down
20 changes: 10 additions & 10 deletions netbox/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
</div>
{% endif %}

{# Login form errors #}
{% if form.non_field_errors %}
<div class="alert alert-danger" role="alert">
<h4 class="alert-heading">Errors</h4>
<p>
{{ form.non_field_errors }}
</p>
</div>
{% endif %}

{# Login form #}
<div class="form-login">
<form action="{% url 'login' %}" method="post">
Expand Down Expand Up @@ -48,16 +58,6 @@ <h5>
</h5>
{% endfor %}
{% endif %}

{# Login form errors #}
{% if form.non_field_errors %}
<div class="alert alert-danger" role="alert">
<h4 class="alert-heading">Errors</h4>
<p>
{{ form.non_field_errors }}
</p>
</div>
{% endif %}
</main>

{# Page footer #}
Expand Down
27 changes: 15 additions & 12 deletions netbox/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,14 @@ def gen_auth_data(self, name, url, params):
'url': f'{url}?{urlencode(params)}',
}

def get(self, request):
form = LoginForm(request)

if request.user.is_authenticated:
logger = logging.getLogger('netbox.auth.login')
return self.redirect_to_next(request, logger)

def get_auth_backends(self, request):
auth_backends = []
saml_idps = get_saml_idps()

for name in load_backends(settings.AUTHENTICATION_BACKENDS).keys():
url = reverse('social:begin', args=[name, ])
url = reverse('social:begin', args=[name])
params = {}
next = request.GET.get('next')
if next:
if next := request.GET.get('next'):
params['next'] = next
if name.lower() == 'saml' and saml_idps:
for idp in saml_idps:
Expand All @@ -71,9 +65,18 @@ def get(self, request):
else:
auth_backends.append(self.gen_auth_data(name, url, params))

return auth_backends

def get(self, request):
form = LoginForm(request)

if request.user.is_authenticated:
logger = logging.getLogger('netbox.auth.login')
return self.redirect_to_next(request, logger)

return render(request, self.template_name, {
'form': form,
'auth_backends': auth_backends,
'auth_backends': self.get_auth_backends(request),
})

def post(self, request):
Expand Down Expand Up @@ -107,7 +110,7 @@ def post(self, request):

return render(request, self.template_name, {
'form': form,
'auth_backends': load_backends(settings.AUTHENTICATION_BACKENDS),
'auth_backends': self.get_auth_backends(request),
})

def redirect_to_next(self, request, logger):
Expand Down

0 comments on commit e05696d

Please sign in to comment.