2019-10-30 13:06:55 +00:00
|
|
|
|
2019-10-30 12:05:46 +00:00
|
|
|
from django.http import HttpResponseRedirect
|
2019-10-10 07:18:34 +00:00
|
|
|
from django.shortcuts import render
|
2019-10-29 09:58:54 +00:00
|
|
|
from django.urls import reverse_lazy
|
2019-10-30 12:05:46 +00:00
|
|
|
from django.views.generic.base import RedirectView, TemplateView
|
2019-10-29 09:58:54 +00:00
|
|
|
from django.views.generic.edit import FormView
|
2019-10-10 07:18:34 +00:00
|
|
|
|
2019-10-29 09:58:54 +00:00
|
|
|
from . import api, get_version
|
2019-10-30 13:06:55 +00:00
|
|
|
from .auth import login as auth_login
|
|
|
|
from .auth import logout as auth_logout
|
2019-10-29 09:58:54 +00:00
|
|
|
from .forms import LoginForm
|
2019-10-30 13:06:55 +00:00
|
|
|
from .mixins import CustomContextMixin, UserTokenRequiredMixin
|
2019-10-25 11:33:37 +00:00
|
|
|
|
|
|
|
|
2019-10-30 13:06:55 +00:00
|
|
|
class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
|
2019-10-25 11:33:37 +00:00
|
|
|
template_name = "musician/dashboard.html"
|
2019-10-29 09:58:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LoginView(FormView):
|
|
|
|
template_name = 'auth/login.html'
|
|
|
|
form_class = LoginForm
|
|
|
|
success_url = reverse_lazy('musician:dashboard')
|
|
|
|
extra_context = {'version': get_version()}
|
2019-10-30 12:05:46 +00:00
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super().get_form_kwargs()
|
|
|
|
kwargs['request'] = self.request
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
"""Security check complete. Log the user in."""
|
|
|
|
auth_login(self.request, form.username, form.token)
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
|
|
|
|
class LogoutView(RedirectView):
|
|
|
|
"""
|
|
|
|
Log out the user.
|
|
|
|
"""
|
|
|
|
permanent = False
|
|
|
|
pattern_name = 'musician:login'
|
|
|
|
|
|
|
|
def get_redirect_url(self, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Logs out the user.
|
|
|
|
"""
|
|
|
|
auth_logout(self.request)
|
|
|
|
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)
|