Consider that there may be some third party app which you will
want to add in the future, and that it may depend on the existing
nature of usernames.  (E.g.; uses username as a slug and uses
a simple regular expression in a url pattern to capture the username.

Consider that usernames are currently limited to 30 characters,
while email addresses are not, so you would also need to modify
the User model.

Wouldn't it be simpler modify the AuthenticationForm to accept
an email address instead of a username and in the clean
method, look up the user by email address, get the username
from there, and authenticate on that and the collected password?
You would still want to modify the User model to mark email
as unique.  And you would have to modify UserCreationForm to
collect an email address instead of a username, then in the
clean_email method, check that the email address doesn't
already exist, create a username that doesn't exist (from the email
address, or randomly, adding a numeric suffix if necessary to
make it unique, and modify the save method to set the username
(since username wouldn't be a field of the form you might have
to do your own user object creation and saving, rather than
calling the super-class save method).

Bill

On Tue, May 4, 2010 at 1:19 AM, Felippe Bueno <felippe.bu...@gmail.com> wrote:
> Btw,
>
> I read about django don't accept @ in usernames, but I can create a User
> using
> User.create_user(m...@email.com, m...@email.com, mypassword)
> The only problem is, I can't save the user at admin site.
> I was thinking if the limitation is only at forms.
> I did not test the authentication yet.
> Any one know more about this ?
>
> Thanks
> ps - sorry my poor english.
> Cheers
>
> On Sun, May 2, 2010 at 7:54 AM, Rob <rob.nikan...@gmail.com> wrote:
>>
>> Hi,
>>
>> I'm trying to allow usernames that have '@' in them, so they can just
>> be email addresses.  Maybe this is a bad idea.  ...  But putting that
>> aside for a second... The admin user forms don't validate with '@' in
>> usernames, so I thought I'd try this, which I copied from an older
>> post in this group.
>>
>> from django.contrib.auth.admin import User, UserChangeForm,
>> UserCreationForm, UserAdmin
>>
>> class OurUserChangeForm(UserChangeForm):
>>    username = forms.EmailField
>>
>> class OurUserCreationForm(UserCreationForm):
>>    username = forms.EmailField
>>
>> admin.site.unregister(User)
>> UserAdmin.form = OurUserChangeForm
>> UserAdmin.add_form = OurUserCreationForm
>> admin.site.register(User, UserAdmin)
>>
>> But it doesn't work.  The user form is still validating with the
>> 'username' from the superclass, which is a RegexField.  Is this
>> working as designed?  Are you not allowed to override a field?
>>
>> thanks,
>> Rob
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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