fix problems with login

This commit is contained in:
Cayo Puigdefabregas 2024-01-12 17:22:28 +01:00
parent 1c37368d1f
commit d018c46bf4
2 changed files with 5 additions and 7 deletions

View file

@ -4,8 +4,6 @@
{% block login_content %}
<form action="{% url 'idhub:login' %}" role="form" method="post">
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}" />
<div id="div_id_username"
class="clearfix control-group {% if form.username.errors %}error{% endif %}">
<div class="form-group">

View file

@ -13,16 +13,16 @@ class LoginView(auth_views.LoginView):
}
def get(self, request, *args, **kwargs):
if request.GET.get('next'):
self.extra_context['success_url'] = request.GET.get('next')
self.extra_context['success_url'] = request.GET.get(
'next',
reverse_lazy('idhub:user_dashboard')
)
return super().get(request, *args, **kwargs)
def form_valid(self, form):
user = form.get_user()
if not user.is_anonymous and user.is_admin:
user_dashboard = reverse_lazy('idhub:user_dashboard')
admin_dashboard = reverse_lazy('idhub:admin_dashboard')
if self.extra_context['success_url'] == user_dashboard:
self.extra_context['success_url'] = admin_dashboard
self.extra_context['success_url'] = admin_dashboard
auth_login(self.request, user)
return HttpResponseRedirect(self.extra_context['success_url'])