示例#1
0
 def send_confirmation(self, user):
     assert user.email
     self.filter(user=user).delete()
     salt = hashlib.sha224(str(random.random()) + settings.SECRET_KEY).hexdigest()[:5]
     confirmation_key = hashlib.sha224(salt + user.email).hexdigest()[:39]
     try:
         current_site = Site.objects.get_current()
     except Site.DoesNotExist:
         return
     path = reverse("accounts:confirm_email", args=[confirmation_key])
     activate_url = u"http://%s%s" % (unicode(current_site.domain), path)
     context = {
         "user": user,
         "activate_url": activate_url,
         "current_site": current_site,
         "confirmation_key": confirmation_key,
         }
     subject = _(u'Please confirm your email address for %(site)s') % {'site': current_site.name}
     send_templated_email(user.email, subject, 'accounts/email_confirmation_message.html', context, fail_silently=settings.DEBUG)
     return self.create(
         user=user,
         sent=timezone.now(),
         confirmation_key=confirmation_key)
示例#2
0
    def save(self, domain_override=None, email_template_name='accounts/password_reset_email.html',
             use_https=False, token_generator=default_token_generator, from_email=None, request=None, **kwargs):
        """
        Generates a one-use only link for resetting password and sends to the user
        """
        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 = u"Смена пароля для %s" % site_name
            send_templated_email([user.email], subject, email_template_name, c, from_email)