﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
2442	django.contrib.auth.forms.CreateUserForm	django@…	Adrian Holovaty	"There are three Auth Forms for the User model (django.contrib.auth.forms):
  * AuthenticationForm - user login
  * PasswordChangeForm - obvious
  * PasswordResetForm  - set password to a random value and e-mail it to the user

But there does not seem to be a CreateUserForm.
This is different from the AddManipulator (used by admin) in two ways:
  * CreateUserForm contains a password confirmation field
  * The default user AddManipulator should show the raw <hash>$<salt>$<check-sum> value.

There is a patch for changing the AddManipulator to accept a password, and not use the hash, but that still doesnt solve the password confirmation, and I perfer having a Form which is optional in use (like the login and password change forms).
[[BR]]
''(the encoding thing might need to be removed and later replaced with whatever the unicode solution will be)''
{{{
#!python
class CreateUserForm(forms.Manipulator):
    """"""
    Base class for creating users. Extend this to get a form that accepts
    username/password creation.
    """"""
    def __init__(self, request=None, encoding='ASCII'):
        """"""
        If request is passed in, the manipulator will validate that cookies are
        enabled. Note that the request (a HttpRequest object) must have set a
        cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before
        running this validator.
        
        Encoding is the string encoding to be used for the username and
        optional first and last names. This should match your Database.
        """"""
        self.request = request
        self.encoding = encoding
        self.fields = [
            forms.TextField(field_name=""username"", length=15, maxlength=30, is_required=True,
                validator_list=[self.isNotValidUser, self.hasCookiesEnabled]),
            forms.PasswordField(field_name=""password"", length=15, maxlength=30, is_required=True),
            forms.PasswordField(field_name=""confirm"", length=15, maxlength=30, is_required=True,
                                validator_list=[validators.AlwaysMatchesOtherField('password', ""The two password fields didn't match."")]),
            forms.TextField(field_name=""e-mail_address"", length=15, maxlength=30, is_required=False,
                validator_list=[validators.isValidEmail]),
            forms.TextField(field_name=""first_name"", length=15, maxlength=30, is_required=False),
            forms.TextField(field_name=""last_name"", length=15, maxlength=30, is_required=False),
        ]

    def hasCookiesEnabled(self, field_data, all_data):
        if self.request and not self.request.session.test_cookie_worked():
            raise validators.ValidationError, _(""Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in."")

    def isNotValidUser(self, field_data, all_data):
        try:
            User.objects.get(username=field_data)
        except User.DoesNotExist:
            return True
        raise validators.ValidationError, _(""This username is already in use."")
    
    def save(self, new_data):
        ""Saves the new user.""
        user = User.objects.create_user(new_data['username'].encode(self.encoding), new_data['e-mail_address'], new_data['password'])
        if 'first_name' in new_data:
            user.first_name = new_data['first_name'].encode(self.encoding)
        if 'last_name' in new_data:
            user.last_name = new_data['last_name'].encode(self.encoding)
        user.save()
        
}}}
"	enhancement	closed	Contrib apps	dev	normal	worksforme	Auth User Form Manipulator Create		Unreviewed	0	0	0	0	0	0
