mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 23:31:52 +00:00
[svn] Use hashlib rather than depreciated sha
This commit is contained in:
parent
7fe5cd6ede
commit
e27f5565cb
@ -1,7 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import sha
|
import hashlib
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
@ -117,7 +117,8 @@ class RegistrationManager(models.Manager):
|
|||||||
registration_profile = self.create_profile(new_user)
|
registration_profile = self.create_profile(new_user)
|
||||||
|
|
||||||
if send_email:
|
if send_email:
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail, EmailMultiAlternatives
|
||||||
|
|
||||||
current_site = Site.objects.get_current()
|
current_site = Site.objects.get_current()
|
||||||
|
|
||||||
subject = render_to_string('registration/activation_email_subject.txt',
|
subject = render_to_string('registration/activation_email_subject.txt',
|
||||||
@ -125,12 +126,18 @@ class RegistrationManager(models.Manager):
|
|||||||
# Email subject *must not* contain newlines
|
# Email subject *must not* contain newlines
|
||||||
subject = ''.join(subject.splitlines())
|
subject = ''.join(subject.splitlines())
|
||||||
|
|
||||||
message = render_to_string('registration/activation_email.txt',
|
text_content = render_to_string('registration/activation_email.txt',
|
||||||
{ 'activation_key': registration_profile.activation_key,
|
{ 'activation_key': registration_profile.activation_key,
|
||||||
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
|
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
|
||||||
'site': settings.URL_ROOT })
|
'site': settings.URL_ROOT })
|
||||||
|
html_content = render_to_string('registration/activation_email.html',
|
||||||
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_user.email])
|
{ 'activation_key': registration_profile.activation_key,
|
||||||
|
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
|
||||||
|
'site': settings.URL_ROOT })
|
||||||
|
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [new_user.email])
|
||||||
|
msg.attach_alternative(html_content, "text/html")
|
||||||
|
msg.send()
|
||||||
|
# send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_user.email])
|
||||||
user_registered.send(sender=self.model, user=new_user)
|
user_registered.send(sender=self.model, user=new_user)
|
||||||
return new_user
|
return new_user
|
||||||
create_inactive_user = transaction.commit_on_success(create_inactive_user)
|
create_inactive_user = transaction.commit_on_success(create_inactive_user)
|
||||||
@ -145,8 +152,8 @@ class RegistrationManager(models.Manager):
|
|||||||
username and a random salt.
|
username and a random salt.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
salt = sha.new(str(random.random())).hexdigest()[:5]
|
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
|
||||||
activation_key = sha.new(salt+user.username).hexdigest()
|
activation_key = hashlib.sha1(salt+user.username).hexdigest()
|
||||||
return self.create(user=user,
|
return self.create(user=user,
|
||||||
activation_key=activation_key)
|
activation_key=activation_key)
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ getting django-registration running in the default setup, to wit:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import sha
|
import hashlib
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
@ -115,7 +115,7 @@ class RegistrationModelTests(RegistrationTestCase):
|
|||||||
self.failIf(RegistrationProfile.objects.activate_user('foo'))
|
self.failIf(RegistrationProfile.objects.activate_user('foo'))
|
||||||
|
|
||||||
# Activating from a key that doesn't exist returns False.
|
# Activating from a key that doesn't exist returns False.
|
||||||
self.failIf(RegistrationProfile.objects.activate_user(sha.new('foo').hexdigest()))
|
self.failIf(RegistrationProfile.objects.activate_user(hashlib.sha1('foo').hexdigest()))
|
||||||
|
|
||||||
def test_account_expiration_condition(self):
|
def test_account_expiration_condition(self):
|
||||||
"""
|
"""
|
||||||
@ -351,5 +351,5 @@ class RegistrationViewTests(RegistrationTestCase):
|
|||||||
|
|
||||||
# Nonexistent key sets the account to False.
|
# Nonexistent key sets the account to False.
|
||||||
response = self.client.get(reverse('registration_activate',
|
response = self.client.get(reverse('registration_activate',
|
||||||
kwargs={ 'activation_key': sha.new('foo').hexdigest() }))
|
kwargs={ 'activation_key': hashlib.sha1('foo').hexdigest() }))
|
||||||
self.failIf(response.context['account'])
|
self.failIf(response.context['account'])
|
||||||
|
Loading…
Reference in New Issue
Block a user