from datetime import timedelta, date

from django.shortcuts import render
from django.contrib.auth.views import PasswordChangeView
from django.urls import reverse_lazy
from .models import User


class PasswordChange(PasswordChangeView):
    success_url = reverse_lazy('password_change_done')

    def form_valid(self, form):
        form.save()
        user = self.request.user
        user.password_expiry_date = date.today() + timedelta(days=14)
        user.save()
        return super().form_valid(form)
