add login
This commit is contained in:
parent
73303bdd8f
commit
d0926a8f86
|
@ -115,6 +115,8 @@
|
|||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<input name="next" type="hidden" value="{{ success_url }}">
|
||||
|
||||
<div class="form-actions-no-box">
|
||||
<input type="submit" name="submit" value="{% trans 'Log in' %}"
|
||||
class="btn btn-primary form-control" id="submit-id-submit">
|
||||
|
|
|
@ -15,6 +15,7 @@ from django.views.generic.base import RedirectView, TemplateView
|
|||
from django.views.generic.detail import DetailView
|
||||
from django.views.generic.edit import DeleteView, FormView
|
||||
from django.views.generic.list import ListView
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from .forms import LoginForm
|
||||
|
@ -24,11 +25,10 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
|
||||
# class UserDashboardView(LoginRequiredMixin, TemplateView):
|
||||
class UserDashboardView(TemplateView):
|
||||
class UserDashboardView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "idhub/user_dashboard.html"
|
||||
title = _('Dashboard')
|
||||
#login_url = "/login/"
|
||||
login_url = "/login/"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
@ -42,31 +42,14 @@ class AdminDashboardView(UserDashboardView):
|
|||
template_name = "idhub/admin_dashboard.html"
|
||||
|
||||
|
||||
class LoginView(FormView):
|
||||
class LoginView(auth_views.LoginView):
|
||||
template_name = 'auth/login.html'
|
||||
form_class = LoginForm
|
||||
success_url = reverse_lazy('idhub:user_dashboard')
|
||||
extra_context = {
|
||||
'title': _('Login'),
|
||||
'success_url': reverse_lazy('idhub:user_dashboard'),
|
||||
}
|
||||
|
||||
def form_valid(self, form):
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class LogoutView(RedirectView):
|
||||
"""
|
||||
Log out the user.
|
||||
"""
|
||||
permanent = False
|
||||
pattern_name = 'login'
|
||||
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
"""
|
||||
Logs out the user.
|
||||
"""
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""Logout may be done via POST."""
|
||||
return self.get(request, *args, **kwargs)
|
||||
def get(self, request):
|
||||
if request.GET.get('next'):
|
||||
self.extra_context['success_url'] = request.GET.get('next')
|
||||
return super().get(request)
|
||||
|
|
Loading…
Reference in a new issue