jeverling  committed 1efeb21

Added an object "domain_override".
request.get_host() gets passed in this variable from the view to the form and from there to the model.
This is meant as an override until the sites app can be used with appenginepatch.
The key_name for the user is always lowercase now, to prevent several users registering the same nick with different casing.

  • Participants
  • Parent commits 62dcaaa

Comments (0)

Files changed (3)

File registration/

 from django import forms
 from django.utils.translation import ugettext_lazy as _
 from django.contrib.auth.models import User
         in use.
-        user = User.get_by_key_name("key_"+self.cleaned_data['username'])
+        user = User.get_by_key_name("key_"+self.cleaned_data['username'].lower())
         if user:
             raise forms.ValidationError(_(u'This username is already taken. Please choose another.'))
         return self.cleaned_data['username']
                 raise forms.ValidationError(_(u'You must type the same password each time'))
         return self.cleaned_data
-    def save(self):
+    def save(self, domain_override=""):
         Create the new ``User`` and ``RegistrationProfile``, and
         returns the ``User``.
         new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
-                                                                    email=self.cleaned_data['email'])
+                                                                    email=self.cleaned_data['email'],
+                                                                    domain_override=domain_override,
+                                                                    )
         return new_user

File registration/

                 return user
         return False
-    def create_inactive_user(self, username, password, email,
+    def create_inactive_user(self, username, password, email, domain_override="", 
         Create a new, inactive ``User``, generates a
 #        prepend "key_" to the key_name, because key_names can't start with numbers
-        new_user = User(username=username, key_name="key_"+username)
+        new_user = User(username=username, key_name="key_"+username.lower()) = email
         new_user.is_active = False
         if send_email:
             from django.core.mail import send_mail
+            current_site = domain_override
 #            current_site = Site.objects.get_current()
-            subject = render_to_string('registration/activation_email_subject.txt')
+            subject = render_to_string('registration/activation_email_subject.txt',
+                                       { 'site': current_site })
             # Email subject *must not* contain newlines
             subject = ''.join(subject.splitlines())
             message = render_to_string('registration/activation_email.txt',
                                        { 'activation_key': registration_profile.activation_key,
-                                         'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS})
+                                         'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
+                                         'site': current_site })
             send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [])
         return new_user

File registration/

 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.http import HttpResponseRedirect
     if request.method == 'POST':
         form = form_class(data=request.POST, files=request.FILES)
+        domain_override = request.get_host()
         if form.is_valid():
-            new_user =
+            new_user =
             # success_url needs to be dynamically generated here; setting a
             # a default value using reverse() will cause circular-import
             # problems with the default URLConf for this application, which