我有以下色器件模型(编辑为简洁起见)设计与用户名登录空间
class Student < ActiveRecord::Base
devise :database_authenticatable, :token_authenticatable,
:recoverable, :rememberable, :trackable,
:authentication_keys => [:login], :reset_password_keys => [ :login ]
attr_accessor :login
attr_accessible :name, :email, :password, :password_confirmation, :login
validates :name, :presence => true
validates :email, :presence => true
validates_uniqueness_of :email, :case_sensitive => false, :allow_blank => true, :if => :email_changed?, :scope => :id
validates_format_of :email, :with => Devise.email_regexp, :allow_blank => true, :if => :email_changed?
validates_presence_of :password, :on=>:create
validates_confirmation_of :password, :on=>:create
validates_length_of :password, :within => Devise.password_length, :allow_blank => true
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions).where(["name = :value OR lower(email) = :value", { :value => login.downcase }]).first
else
where(conditions).first
end
end
def email_required?
false
end
def email_changed?
false
end
end
而且我跟着上this link先导,以实现与名称或电邮登入。
这里的问题:
学生的名字> 2层的话不能登录,例如“亚当布拉沃查理”
一个名称,例如“亚当”或< = 2个字,例如“亚当·布拉沃”的名字可以签署。
学校要求学生用自己的全名,伴随空间登录。我如何让我的学生使用全名和空格进行登录?
我没有挖掘代码,但使用用户名而不是全名与空间是整个网络的约定。想想Google,Facebook,Twitter,StackOverflow。遵循约定。 –
这是一个很好的建议,但我试图修改旧版应用程序。由于学校的要求,学生使用全名而不是用户名。如果证明不可行,那么我会更改应用程序以遵循约定。非常感谢 –