删除设计电子邮件验证 [英] Remove devise email validation

查看:40
本文介绍了删除设计电子邮件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用devise和devise-token-auth.我的用户模型具有以下内容

I use devise and devise-token-auth. I have User model with following content

class User < ApplicationRecord

  devise :database_authenticatable, :registerable,
          :recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:login]
  include DeviseTokenAuth::Concerns::User

  validates_uniqueness_of :login
  validates_presence_of :full_name

  protected
  def email_required?
    puts "email_required called"
    false
  end
end

但是设计电子邮件验证仍然有效

but devise email validation is still working

2.3.0 :003 > user = User.new(login: "hello", password: "11111111", password_confirmation: "11111111", full_name: "hello world")
 => #<User id: nil, provider: "email", uid: "", email: nil, full_name: "hello world", login: "hello", created_at: nil, updated_at: nil> 
2.3.0 :004 > user.valid?
email_required? called   #<===== my method is called!
   (3.7ms)  SELECT COUNT(*) FROM "users" WHERE "users"."provider" = $1 AND "users"."email" IS NULL  [["provider", "email"]]
  User Exists (1.0ms)  SELECT  1 AS one FROM "users" WHERE "users"."login" = $1 LIMIT $2  [["login", "hello"], ["LIMIT", 1]]
 => false 
2.3.0 :005 > user.errors
 => #<ActiveModel::Errors:0x000000028e2338 @messages={:email=>[...]}, @details={:email=>[{:error=>:blank}]}>

为什么呢?谢谢

推荐答案

在我的情况下,我更改为用户名字段.首先,我更改了/config/initializers/devise.rb -> config.authentication_keys = [:用户名]

In my case I changed to username field. First I changed /config/initializers/devise.rb --> config.authentication_keys = [:username]

而且,当我使用旧式数据库时,我也必须将主键也更改为用户名,并更改 auth 方法

And, as I use a legacy database, I have to change the primary key to username too and change the auth method

def self.find_for_database_authentication(warden_conditions)
  conditions = warden_conditions.dup
  login = conditions.delete(:username)
  where(["APP_NAME = '#{$app_name.downcase}' AND USERNAME = :value", { :value => login }]).first
end

这篇关于删除设计电子邮件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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