gpt4 book ai didi

ruby-on-rails - 使用空格登录设计用户名

转载 作者:行者123 更新时间:2023-12-02 08:38:04 25 4
gpt4 key购买 nike

我有以下设计模型(为简洁起见进行了编辑)

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个字的学生无法签到,e.g. “亚当布拉沃查理”

可以登录单个名称,例如“Adam”或 <= 2 个单词的名称,例如“Adam Bravo”。

学校要求学生使用带空格的全名登录。我如何让我的学生使用他们的全名和空格登录?

最佳答案

在登录表单上,我将获取一个字符串并将其转换为 slug。使用 slug 作为 username 进行身份验证。创建新用户时,使用before_create 方法和parameterize 全名。这将允许您拥有无限数量的空格,包括标点符号(句点和逗号)。这会给用户输入他们的全名作为用户名的感觉,而反过来,它将参数化用户的全名并将其用作登录的用户名。

关于ruby-on-rails - 使用空格登录设计用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19270451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com