def save( self, domain_override=None, subject_template_name="registration/password_reset_subject.txt", text_template=None, html_template=None, use_https=False, token_generator=default_token_generator, from_email=None, request=None, ): """ Based off of django's but handles html and plain-text emails. """ users = User.objects.filter( email__iexact=self.cleaned_data["email"], is_active=True ) for user in users: if not domain_override: current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain else: site_name = domain = domain_override c = { "email": user.email, "domain": domain, "site_name": site_name, "uid": int_to_base36(user.id), "user": user, "token": token_generator.make_token(user), "protocol": use_https and "https" or "http", } subject = email_utils.render_email(subject_template_name, c) # Email subject *must not* contain newlines subject = "".join(subject.splitlines()) @email_utils.safe_translation def _make_mail(locale): mail = email_utils.make_mail( subject=subject, text_template=text_template, html_template=html_template, context_vars=c, from_email=from_email, to_email=user.email, ) return mail if request: locale = request.LANGUAGE_CODE else: locale = settings.WIKI_DEFAULT_LANGUAGE email_utils.send_messages([_make_mail(locale)])
def save( self, domain_override=None, subject_template_name="registration/password_reset_subject.txt", text_template=None, html_template=None, use_https=False, token_generator=default_token_generator, from_email=None, request=None, ): """ Based off of django's but uses jingo and handles html and plain-text emails """ for user in self.users_cache: if not domain_override: current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain else: site_name = domain = domain_override c = { "email": user.email, "domain": domain, "site_name": site_name, "uid": int_to_base36(user.id), "user": user, "token": token_generator.make_token(user), "protocol": use_https and "https" or "http", } subject = email_utils.render_email(subject_template_name, c) # Email subject *must not* contain newlines subject = "".join(subject.splitlines()) @email_utils.safe_translation def _make_mail(locale): mail = email_utils.make_mail( subject=subject, text_template=text_template, html_template=html_template, context_vars=c, from_email=from_email, to_email=user.email, ) return mail if request: locale = request.LANGUAGE_CODE else: locale = settings.WIKI_DEFAULT_LANGUAGE email_utils.send_messages([_make_mail(locale)])
def save(self, domain_override=None, subject_template_name='registration/password_reset_subject.txt', text_template=None, html_template=None, use_https=False, token_generator=default_token_generator, from_email=None, request=None): """ Based off of django's but uses jingo and handles html and plain-text emails """ users = User.objects.filter( email__iexact=self.cleaned_data["email"], is_active=True) for user in users: if not domain_override: current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain else: site_name = domain = domain_override c = { 'email': user.email, 'domain': domain, 'site_name': site_name, 'uid': int_to_base36(user.id), 'user': user, 'token': token_generator.make_token(user), 'protocol': use_https and 'https' or 'http', } subject = email_utils.render_email(subject_template_name, c) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) @email_utils.safe_translation def _make_mail(locale): mail = email_utils.make_mail( subject=subject, text_template=text_template, html_template=html_template, context_vars=c, from_email=from_email, to_email=user.email) return mail if request: locale = request.LANGUAGE_CODE else: locale = settings.WIKI_DEFAULT_LANGUAGE email_utils.send_messages([_make_mail(locale)])
def save(self, domain_override=None, subject_template_name='registration/password_reset_subject.txt', text_template=None, html_template=None, use_https=False, token_generator=default_token_generator, from_email=None, request=None): """ Based off of django's but uses jingo and handles html and plain-text emails """ for user in self.users_cache: if not domain_override: current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain else: site_name = domain = domain_override c = { 'email': user.email, 'domain': domain, 'site_name': site_name, 'uid': int_to_base36(user.id), 'user': user, 'token': token_generator.make_token(user), 'protocol': use_https and 'https' or 'http', } subject = email_utils.render_email(subject_template_name, c) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) @email_utils.safe_translation def _make_mail(locale): mail = email_utils.make_mail(subject=subject, text_template=text_template, html_template=html_template, context_vars=c, from_email=from_email, to_email=user.email) return mail if request: locale = request.LANGUAGE_CODE else: locale = settings.WIKI_DEFAULT_LANGUAGE email_utils.send_messages([_make_mail(locale)])
def request_password_reset(self, request, user__username=None): profile = self.get_object() current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain c = { "email": profile.user.email, "domain": domain, "site_name": site_name, "uid": int_to_base36(profile.user.id), "user": profile.user, "token": default_token_generator.make_token(profile.user), "protocol": "https" if request.is_secure() else "http", } subject = email_utils.render_email("users/email/pw_reset_subject.ltxt", c) # Email subject *must not* contain newlines subject = "".join(subject.splitlines()) @email_utils.safe_translation def _make_mail(locale): mail = email_utils.make_mail( subject=subject, text_template="users/email/pw_reset.ltxt", html_template="users/email/pw_reset.html", context_vars=c, from_email=None, to_email=profile.user.email, ) return mail email_utils.send_messages([_make_mail(profile.locale)]) return Response("", status=204)
def request_password_reset(self, request, user__username=None): profile = self.get_object() current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain c = { 'email': profile.user.email, 'domain': domain, 'site_name': site_name, 'uid': int_to_base36(profile.user.id), 'user': profile.user, 'token': default_token_generator.make_token(profile.user), 'protocol': 'https' if request.is_secure() else 'http', } subject = email_utils.render_email('users/email/pw_reset_subject.ltxt', c) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) @email_utils.safe_translation def _make_mail(locale): mail = email_utils.make_mail( subject=subject, text_template='users/email/pw_reset.ltxt', html_template='users/email/pw_reset.html', context_vars=c, from_email=None, to_email=profile.user.email) return mail email_utils.send_messages([_make_mail(profile.locale)]) return Response('', status=204)