membersystem/parked_apps/users/views.py

60 lines
1.6 KiB
Python
Raw Normal View History

2019-08-31 18:46:49 +00:00
from django.contrib.auth import views as auth_views
from django.shortcuts import redirect
from django.urls.base import reverse_lazy
from django.views.generic.base import RedirectView
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView
2018-06-23 11:00:26 +00:00
2019-08-31 18:46:49 +00:00
from . import forms
2019-08-31 22:27:36 +00:00
2019-08-31 18:46:49 +00:00
# from . import email
class PasswordResetView(auth_views.PasswordResetView):
2019-08-31 22:27:36 +00:00
email_template_name = "users/password_reset_email.html"
success_url = reverse_lazy("users:password_reset_done")
2019-08-31 18:46:49 +00:00
class PasswordResetConfirmView(auth_views.PasswordResetConfirmView):
2019-08-31 22:27:36 +00:00
success_url = reverse_lazy("users:password_reset_complete")
2019-08-31 18:46:49 +00:00
class PasswordChangeView(auth_views.PasswordChangeView):
2019-08-31 22:27:36 +00:00
success_url = reverse_lazy("users:password_change_done")
2019-08-31 18:46:49 +00:00
class SignupView(FormView):
template_name = "users/signup.html"
form_class = forms.SignupForm
def form_valid(self, form):
user = form.save(commit=False)
user.is_active = False
2019-08-31 22:27:36 +00:00
user.set_password(form.cleaned_data["password1"])
2019-08-31 18:46:49 +00:00
user.save()
# mail = email.UserConfirm(user=user)
# mail.send_with_feedback(success_msg=_("An email was sent with a confirmation link"))
self.request.session["user_confirm_pending_id"] = user.id
return redirect("users:signup_confirm")
class SignupConfirmView(TemplateView):
template_name = "users/signup_confirm.html"
class SignupConfirmRedirectView(RedirectView):
def get_redirect_url(self):
2019-08-31 22:27:36 +00:00
uuid = self.kwargs["uuid"]
2019-08-31 18:46:49 +00:00
if self.kwargs["token"] == forms.get_confirm_code(uuid):
redirect("users:confirmed") # TODO
redirect("users:confirm_nope") # TODO