def form_valid(self, form): if form.cleaned_data['email'] != self.initial_email: new_email = form.cleaned_data['email'] form.cleaned_data['email'] = form.instance.email = self.initial_email ctx = form.instance.get_email_context() ctx['url'] = build_absolute_uri( self.request.organizer, 'presale:organizer.customer.change.confirm' ) + '?token=' + dumps({ 'customer': form.instance.pk, 'email': new_email }, salt='pretix.presale.views.customer.ChangeInformationView') mail( new_email, _('Confirm email address for your account at {organizer}').format(organizer=self.request.organizer.name), self.request.organizer.settings.mail_text_customer_email_change, ctx, locale=form.instance.locale, customer=form.instance, organizer=self.request.organizer, ) messages.success(self.request, _('Your changes have been saved. We\'ve sent you an email with a link to update your ' 'email address. The email address of your account will be changed as soon as you ' 'click that link.')) else: messages.success(self.request, _('Your changes have been saved.')) with transaction.atomic(): form.save() d = dict(form.cleaned_data) del d['email'] self.request.customer.log_action('pretix.customer.changed', d) update_customer_session_auth_hash(self.request, form.instance) return HttpResponseRedirect(self.get_success_url())
def get(self, request, *args, **kwargs): if not request.organizer.settings.customer_accounts: raise Http404('Feature not enabled') try: data = loads(request.GET.get('token', ''), salt='pretix.presale.views.customer.ChangeInformationView', max_age=3600 * 24) except BadSignature: messages.error(request, _('You clicked an invalid link.')) return HttpResponseRedirect(self.get_success_url()) try: customer = request.organizer.customers.get(pk=data.get('customer')) except Customer.DoesNotExist: messages.error(request, _('You clicked an invalid link.')) return HttpResponseRedirect(self.get_success_url()) with transaction.atomic(): customer.email = data['email'] customer.save() customer.log_action('pretix.customer.changed', { 'email': data['email'] }) messages.success(request, _('Your email address has been updated.')) if customer == request.customer: update_customer_session_auth_hash(self.request, customer) return HttpResponseRedirect(self.get_success_url())
def form_valid(self, form): customer = form.customer customer.log_action('pretix.customer.password.set', {}) customer.set_password(form.cleaned_data['password']) customer.save() messages.success(self.request, _('Your changes have been saved.')) update_customer_session_auth_hash(self.request, customer) return HttpResponseRedirect(self.get_success_url())