I found a way to customize devise to use username to login instead of email address.
But actually I want to use combination :-
我找到了一种方法来自定义设备使用用户名登录而不是电子邮件地址。但实际上我想使用组合: -
Enter username or Email: <text-box>
Enter your password : <text-box>
So how to achieve this ?
那么如何实现呢?
Actually we need to modify devise gem's configuration to support this.
for now I know that modifying the "/config/initializers/devise.rb" file as
实际上我们需要修改devise gem的配置来支持它。现在我知道修改“/config/initializers/devise.rb”文件为
config.authentication_keys = [ :username ] (edited from email to username.)
would actually enable logging in using username instead of emailid.
But can I do some thing like:-
实际上会使用username而不是emailid启用登录。但我可以做一些事情: -
config.authentication_keys = [ :username | :email] in the "config/initializers/devise.rb" file.
So that we devise can take username or email as authentication key at runtime depending on the input provided by user.
Thanks in advance .
因此,我们设计可以在运行时将用户名或电子邮件作为身份验证密钥,具体取决于用户提供的输入。提前致谢 。
3 个解决方案
#1
14
Look at there : https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address (url updated)
看那里:https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address(url updated)
It explains how to allow users to sign in using their username or email address.
它解释了如何允许用户使用其用户名或电子邮件地址登录。
#2
3
how about filtering on the username or email if there is an @ and a . which would be characteristics for an email.
如果有@和a,如何过滤用户名或电子邮件。这将是电子邮件的特征。
#3
0
You can use this guide https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address
您可以使用本指南https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address
but remember to change :authentication_keys => [:username] at devise model or at devise.rb as suggested by the guide to :authentication_keys => [:login] to make it work
但请记住在设计模型或devise.rb中更改:authentication_keys => [:username],如以下指南所示:authentication_keys => [:login]使其工作
Regards
问候
#1
14
Look at there : https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address (url updated)
看那里:https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address(url updated)
It explains how to allow users to sign in using their username or email address.
它解释了如何允许用户使用其用户名或电子邮件地址登录。
#2
3
how about filtering on the username or email if there is an @ and a . which would be characteristics for an email.
如果有@和a,如何过滤用户名或电子邮件。这将是电子邮件的特征。
#3
0
You can use this guide https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address
您可以使用本指南https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address
but remember to change :authentication_keys => [:username] at devise model or at devise.rb as suggested by the guide to :authentication_keys => [:login] to make it work
但请记住在设计模型或devise.rb中更改:authentication_keys => [:username],如以下指南所示:authentication_keys => [:login]使其工作
Regards
问候