from django.contrib.auth import get_user_model
from django.contrib.auth.views import LoginView
from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import TemplateView, FormView, ListView, UpdateView

from accounts.forms import LoginForm, RegisterForm


# Create your views here.
class DepotLoginView(LoginView):
    template_name = 'registration/login.html'
    # success_url = reverse_lazy('dashboard')
    form_class = LoginForm
    next_page = reverse_lazy('dashboard')


class RegisterView(FormView):
    template_name = 'registration/register.html'
    form_class = RegisterForm
    # model = get_user_model()
    success_url = reverse_lazy('dashboard')

    def form_valid(self, form):
        # Create user from form data
        user = form.save(commit=False)
        # user.set_password(form.cleaned_data['password'])
        user.save()
        return super().form_valid(form)

class UserListView(ListView):
    template_name = 'registration/register.html'
    # form_class = RegisterForm
    model = get_user_model()
    success_url = reverse_lazy('dashboard')

class UserEditView(UpdateView):
    template_name = 'registration/register.html'
    form_class = RegisterForm
    model = get_user_model()
    success_url = reverse_lazy('dashboard')
