Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #472 from mortenwh/master
Browse files Browse the repository at this point in the history
Fixed problem with æ, ø, å in strings sent to utils.generate_sha1 and updated translations
  • Loading branch information
swistakm committed Sep 15, 2015
2 parents 26d2b0e + 005bdca commit ae63b07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
8 changes: 4 additions & 4 deletions userena/locale/nb/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ msgid ""
"We will store your signup information for %(userena_activation_days)s days "
"on our server. "
msgstr ""
"Vi vil lagre din informasjonn på vår server i %(userena_activation_days)s "
"Vi vil lagre din informasjon på vår server i %(userena_activation_days)s "
"dager."

#: templates/userena/disabled.html:4
Expand All @@ -474,7 +474,7 @@ msgstr "Det ser ut til at din konto har blitt deaktivert."
msgid ""
"If you feel that injustice has been done to you, feel free to contact the "
"administrators to find out why"
msgstr "Kontakt gjerne administrator hvis du mener vi har gjort deg urett."
msgstr "Kontakt gjerne administrator hvis du mener noe er feil."

#: templates/userena/email_change_complete.html:4
msgid "Email verification"
Expand Down Expand Up @@ -731,7 +731,7 @@ msgstr "Du kan nå bruke oppgitt legitimering for å logge inn."
#: templates/userena/emails/confirmation_email_message_new.html:4
#, python-format
msgid "Dear %(username)s,</p>"
msgstr "Kjære %(username)s,</p>"
msgstr "Hei %(username)s,</p>"

#: templates/userena/emails/activation_email_message.html:5
#, python-format
Expand Down Expand Up @@ -768,7 +768,7 @@ msgstr "Vennlig hilsen"
#: templates/userena/emails/confirmation_email_message_old.txt:2
#, python-format
msgid "Dear %(username)s,"
msgstr "Kjære %(username)s,"
msgstr "Hei %(username)s,"

#: templates/userena/emails/activation_email_message.txt:4
#, python-format
Expand Down
15 changes: 14 additions & 1 deletion userena/tests/tests_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import sys, re, six

from django.test import TestCase
from django.conf import settings
from django.utils.six.moves.urllib_parse import urlparse, parse_qs

from userena.utils import (get_gravatar, signin_redirect, get_profile_model,
get_protocol, get_user_model)
get_protocol, get_user_model, generate_sha1)
from userena import settings as userena_settings
from userena.compat import SiteProfileNotAvailable

Expand All @@ -13,6 +14,18 @@ class UtilsTests(TestCase):
""" Test the extra utils methods """
fixtures = ['users']

def test_generate_sha(self):
s1 = six.u('\xc5se')
s2 = six.u('\xd8ystein')
s3 = six.u('\xc6gir')
h1 = generate_sha1(s1)
h2 = generate_sha1(s2)
h3 = generate_sha1(s3)
# Check valid SHA1 activation key
self.failUnless(re.match('^[a-f0-9]{40}$', h1[1]))
self.failUnless(re.match('^[a-f0-9]{40}$', h2[1]))
self.failUnless(re.match('^[a-f0-9]{40}$', h3[1]))

def test_get_gravatar(self):
template = 's=%(size)s&d=%(type)s'

Expand Down
8 changes: 6 additions & 2 deletions userena/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.conf import settings

from django.utils.six import text_type
from django.utils.six.moves.urllib.parse import urlencode
try:
from django.utils.six.moves.urllib.parse import urlencode
except ImportError:
from six.moves.urllib.parse import urlencode
from django.utils.encoding import smart_bytes

from userena import settings as userena_settings
from userena.compat import SiteProfileNotAvailable, get_model
Expand Down Expand Up @@ -112,7 +116,7 @@ def generate_sha1(string, salt=None):
if not salt:
salt = sha_constructor(str(random.random()).encode('utf-8')).hexdigest()[:5]

salted_bytes = (salt.encode('utf-8') + string.encode('utf-8'))
salted_bytes = (smart_bytes(salt) + smart_bytes(string))
hash_ = sha_constructor(salted_bytes).hexdigest()

return salt, hash_
Expand Down

0 comments on commit ae63b07

Please sign in to comment.