Hey,

I've created my own User Registration FormView. Everything seems to
work great except the password is always saved as "!". I can change
that with the "password changer" in the admin section of the site. I
am using an alternative authentication backend, so I'm not sure if
that was causing problems. I went ahead and included the default
authentication backend as well (at the front of the list) but that
didn't seem to change things. I've included my code at the bottom. Any
help would be greatly appreciated! Also, if there's anything wierd
about my code, let me know. I'm still learning.

class SignUpFormView(FormView):

    template_name = u'base.html'
    form_class = SignUpForm
    success_url = '/pages/getting_started'

    def form_valid(self, form):

        # Gather Data
        email = form.cleaned_data['email']
        firstName = form.cleaned_data['firstName']
        lastName = form.cleaned_data['lastName']
        password = form.cleaned_data['password']

        # Create a Unique UserName from a Hash
        userName_hash = hashlib.md5(email).hexdigest()
        userName_hash = userName_hash[:30]

        # Create the User
        user = User.objects.create_user(userName_hash, email,
password)
        user.set_password(password) # Duplicated in hopes of it
working.
        user.first_name = firstName
        user.last_name = lastName
        user.is_active = True

        # Save the User
        user.save()

        return super(SignUpFormView, self).form_valid(form)

    def form_invalid(self, form):
        return super(SignUpFormView, self).form_invalid(form)

class SignUpForm(forms.Form):

    email = forms.EmailField(required = True, label = u'Email
Address')
    firstName = forms.CharField(required = True)
    lastName = forms.CharField(required = True)
    password = PasswordField()
    password_confirm = forms.CharField(label = u'Password
Confirmation',
                        widget = forms.PasswordInput(render_value =
False),
                        required = True)

    # Custom Form Validation
    def clean(self):

        cleaned_data = self.cleaned_data
        password = cleaned_data.get('password')
        password_confirm = cleaned_data.get('password_confirm')

        # Check Password Matches Confirmation
        if password and password_confirm:
            if password is not password_confirm:
                raise forms.ValidationError(u'Your passwords do not
match.')

        return self.cleaned_data

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to