任何人都知道一个很好的黑客,使django注册使用电子邮件作为用户名? [英] Anyone knows a good hack to make django-registration use emails as usernames?

查看:131
本文介绍了任何人都知道一个很好的黑客,使django注册使用电子邮件作为用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划在我的网站上进行电子邮件注册激活,即将推出。我刚刚开始查看django注册,我可以在django上使用其他电子邮件注册激活系统。

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.

我唯一的要求是,对于我的网站,我实际上并没有使用用户名。相反,用户使用他们的电子邮件和密码登录。为了达到这个目的,我想得到一个专家的意见,如何修改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.

推荐答案

我们使用 django-注册与自定义后端,我们覆盖(或定义)注册表单的 clean 方法:

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']

还有其他方法:

  • 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

请注意,默认情况下,用户名只能使用 30个字符长。你也需要一个黑客:

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?

这篇关于任何人都知道一个很好的黑客,使django注册使用电子邮件作为用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆