def _send_reset_link(self, user): from wagboot.models import WebsiteSettings reset_link = "{protocol}://{domain}{url}?reset_token={token}&reset_uid={uid64}" reset_link = reset_link.format(protocol="https" if self._use_https else "http", domain=self.request.site.hostname, url=self.request.path_info, uid64=force_str(urlsafe_base64_encode(force_bytes(user.pk))), token=self.token_generator.make_token(user)) from_email = WebsiteSettings.get_from_email(self.request.site, True) if not from_email: raise ValueError("Password reset block requires 'from_email' in website settings to be set") to_email = formataddr(("{}".format(user), user.email)) subject = self.block_value['reset_email_subject'].replace('\n', '') context = { 'reset_link': mark_safe(reset_link), 'email_text': self.block_value['reset_email_text'], 'site': self.request.site, 'user': user } html_body = render_to_string(self.template_email_body_html, context=context) text_body = render_to_string(self.template_email_body_text, context=context) send_mail(subject=subject, message=text_body, html_message=html_body, from_email=from_email, recipient_list=[to_email])
def pre_render_action(self): from wagboot.models import WebsiteSettings if not WebsiteSettings.get_from_email(self.request.site): raise ValueError("Password reset block requires 'from_email' in website settings to be set") uid64, token = self._get_uid64_and_token() if uid64 and token and not self._is_valid_reset_link(): # We have some tokens, but they are not good. We show email form, but need to tell the user about error messages.error(self.request, "This reset link has expired, you need to request password reset again") return super(PasswordResetBlock, self).pre_render_action()