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 %} {% block login_content %}
<form action="{% url 'idhub:login' %}" role="form" method="post"> <form action="{% url 'idhub:login' %}" role="form" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="next" value="{{ next }}" />
<div id="div_id_username" <div id="div_id_username"
class="clearfix control-group {% if form.username.errors %}error{% endif %}"> class="clearfix control-group {% if form.username.errors %}error{% endif %}">
<div class="form-group"> <div class="form-group">

View File

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