|
|
|
|
@ -20,7 +20,7 @@ from django.contrib.messages.views import SuccessMessageMixin |
|
|
|
|
from django.http import JsonResponse |
|
|
|
|
from django.shortcuts import redirect, resolve_url |
|
|
|
|
from django.urls import reverse, reverse_lazy |
|
|
|
|
from django.utils.http import is_safe_url |
|
|
|
|
from django.utils.http import is_safe_url, urlencode |
|
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
|
|
|
|
|
|
from core.views import ProtectedView |
|
|
|
|
@ -56,58 +56,17 @@ class LoginView(LoginViewBase): |
|
|
|
|
return redirect(redirect_to) |
|
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
def render_done(self, form, **kwargs): |
|
|
|
|
""" |
|
|
|
|
This method gets called when all forms passed. The method should also |
|
|
|
|
re-validate all steps to prevent manipulation. If any form don't |
|
|
|
|
validate, `render_revalidation_failure` should get called. |
|
|
|
|
If everything is fine call `done`. |
|
|
|
|
""" |
|
|
|
|
final_form_list = [] |
|
|
|
|
# walk through the form list and try to validate the data again. |
|
|
|
|
for form_key in self.get_form_list(): |
|
|
|
|
form_obj = self.get_form(step=form_key, |
|
|
|
|
data=self.storage.get_step_data(form_key), |
|
|
|
|
files=self.storage.get_step_files( |
|
|
|
|
form_key)) |
|
|
|
|
form_obj.exclude_second_captcha_validation = True |
|
|
|
|
if not (form_key in self.idempotent_dict or form_obj.is_valid()): |
|
|
|
|
return self.render_revalidation_failure(form_key, form_obj, |
|
|
|
|
**kwargs) |
|
|
|
|
final_form_list.append(form_obj) |
|
|
|
|
|
|
|
|
|
# render the done view and reset the wizard before returning the |
|
|
|
|
# response. This is needed to prevent from rendering done with the |
|
|
|
|
# same data twice. |
|
|
|
|
done_response = self.done(final_form_list, **kwargs) |
|
|
|
|
self.storage.reset() |
|
|
|
|
return done_response |
|
|
|
|
|
|
|
|
|
def get_user(self): |
|
|
|
|
""" |
|
|
|
|
Returns the user authenticated by the AuthenticationForm. Returns False |
|
|
|
|
if not a valid user; see also issue #65. |
|
|
|
|
""" |
|
|
|
|
if not self.user_cache: |
|
|
|
|
form_obj = self.get_form(step='auth', |
|
|
|
|
data=self.storage.get_step_data('auth')) |
|
|
|
|
form_obj.exclude_second_captcha_validation = True |
|
|
|
|
self.user_cache = form_obj.is_valid() and form_obj.user_cache |
|
|
|
|
return self.user_cache |
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super().get_context_data(**kwargs) |
|
|
|
|
context['title'] = AuthenticationForm.title |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResetPasswordView(PasswordResetViewBase): |
|
|
|
|
form_class = PasswordResetRequestForm |
|
|
|
|
template_name = 'accounts_ext/reset_password.html' |
|
|
|
|
email_template_name = 'Reset password email' |
|
|
|
|
html_email_template_name = 'emails/reset_password_email.html' |
|
|
|
|
success_url = reverse_lazy('accounts_ext:reset_password_done') |
|
|
|
|
from_email = settings.DEFAULT_FROM_EMAIL |
|
|
|
|
subject_template_name = _('Сброс пароля') |
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super().get_context_data(**kwargs) |
|
|
|
|
@ -118,7 +77,6 @@ class ResetPasswordView(PasswordResetViewBase): |
|
|
|
|
class ResetPasswordDoneView(PasswordResetDoneViewBase): |
|
|
|
|
template_name = 'accounts_ext/reset_password_done.html' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResetPasswordConfirmView(PasswordResetConfirmViewBase): |
|
|
|
|
form_class = PasswordResetForm |
|
|
|
|
template_name = 'accounts_ext/reset_password_confirm.html' |
|
|
|
|
@ -149,26 +107,48 @@ class RegistrationView(RegistrationViewBase): |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
def form_valid(self, form): |
|
|
|
|
new_user = self.register(form) |
|
|
|
|
context = self.get_context_data() |
|
|
|
|
company_form = context.get('company_form') |
|
|
|
|
try: |
|
|
|
|
user = form.save() |
|
|
|
|
if company_form.is_valid(): |
|
|
|
|
company_form.save(user=user) |
|
|
|
|
company_form.save(user=new_user) |
|
|
|
|
else: |
|
|
|
|
logger.error("User {email} company has invalid data during registration") |
|
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
logger.error(e) |
|
|
|
|
return self.form_invalid(form=form) |
|
|
|
|
return super().form_valid(form) |
|
|
|
|
|
|
|
|
|
# success_url may be a simple string, or a tuple providing the |
|
|
|
|
# full argument set for redirect(). Attempting to unpack it |
|
|
|
|
# tells us which one it is. |
|
|
|
|
success_url = self.get_success_url(new_user) |
|
|
|
|
try: |
|
|
|
|
to, args, kwargs = success_url |
|
|
|
|
except ValueError: |
|
|
|
|
return redirect(success_url) |
|
|
|
|
else: |
|
|
|
|
return redirect(to, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
def get_success_url(self,user): |
|
|
|
|
url = reverse_lazy('accounts_ext:register_done') |
|
|
|
|
return "{}?{}".format(url, urlencode({'email':user.email})) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RegistrationDoneView(TemplateView): |
|
|
|
|
template_name = 'registration/registration_done.html' |
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
|
if reverse_lazy('accounts_ext:register').__str__() in request.META.get('HTTP_REFERER',''): |
|
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
|
return redirect(settings.LOGIN_REDIRECT_URL) |
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super().get_context_data(**kwargs) |
|
|
|
|
context['title'] = _('Отправка письма активации') |
|
|
|
|
context['email'] = self.request.GET.get('email') |
|
|
|
|
context['email_domain'] = "http://"+self.request.GET.get('email').split('@')[-1] |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|