Anyone knows a good hack to make django-registration use emails as usernames?

為{幸葍}努か 提交于 2019-12-21 02:46:20

问题


I am planning to do email-registration-activation on my site which will be launched very soon. I have just started looking at django-registration and I am open to other email-registration-activation system available on django.

My only requirement is that for my site, I don't actually use usernames. Rather, user logs in with their emails and passwords. I want to get an expert's opinion how to modify django-registration cleanly and safely for this purpose.

If there are easier solutions which are scalable, feel free to post up here.


回答1:


We used django-registration with a custom backend, where we overwrote (or defined) the clean method of the registration form:

def clean(self):
    ...
    # use the email as the username 
    if 'email' in self.cleaned_data:
        self.cleaned_data['username'] = self.cleaned_data['email']

There are other ways:

  • http://bitbucket.org/hakanw/django-email-usernames/wiki/Home
  • http://djangosnippets.org/snippets/74/
  • http://www.davidcramer.net/code/224/logging-in-with-email-addresses-in-django.html

Note that by default, usernames can be only 30 chars long. You'll need a hack for that, too:

  • Can django's auth_user.username be varchar(75)? How could that be done?



回答2:


Since Django 1.5 now it possible to have custom auth.User and make email address as username.



来源:https://stackoverflow.com/questions/3690269/anyone-knows-a-good-hack-to-make-django-registration-use-emails-as-usernames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!