Devise Confirmable — 如何禁用确认功能?

huangapple go评论75阅读模式
英文:

Devise Confirmable -- How To Disable Confirmation Feature?

问题

根据这个问题,如果我在创建帐户后不要求用户“确认”它们的帐户,那么我可以将这个选项传递给配置,config.allow_unconfirmed_access_for = nil,我在这个问题中找到了这个选项。但是,对我不清楚的是确认配置的其余部分:

i) 我需要更新我的 Devise 用户模型以添加 devise :confirmable 吗?现在它看起来像这样,并没有传递 :confirmable

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable

ii) 此外,关于迁移文件,需要做哪些更改?使用 config.allow_unconfirmed_access_for = nil,我是否需要取消注释迁移文件中在这些文档中指定的确认字段?还是我保持注释不变?

目前,我使用的是 Rails 6.0.1 和 Devise 4.7.1

英文:

According to this issue, if I do not require my users to "confirm" their account after creating it, then I can pass this option to the config, config.allow_unconfirmed_access_for = nil, which I found in this issue. However, what is unclear to me is the rest of the configuration for confirmable:

i) Do I need update my Devise User model with devise :confirmable? Right now it looks like this and does not have :confirmable passed:

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable

ii) Also, what needs to change with regards to the migration file? With config.allow_unconfirmed_access_for = nil, do I need to uncomment the confirmable fields in my migration file as specified in these docs? Or do I leave the comments alone?

Currently I am using Rails 6.0.1 and Devise 4.7.1.

答案1

得分: 2

confirmable模块默认未启用。要“禁用”它,只需从模型中devise方法的调用中删除模块名称:

class Person < ApplicationRecord
  # 包括默认的devise模块。其他可用的模块包括:
  # :confirmable, :lockable, :timeoutable, :trackable和:omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable 
end

config.allow_unconfirmed_access_for 设置在未启用confirmable模块的情况下完全无效。

你想要使用config.allow_unconfirmed_access_for = nil 的原因是,如果你想使用Devise::Confirmable 来确认电子邮件,但不想用它来限制授权。例如,许多应用程序会将某些功能限制为已确认其电子邮件的用户,但你仍然可以使用未确认的电子邮件随时登录。

英文:

The confirmable module is not enabled by default. To "disable" it you just remove the module name from the call to the devise method in the model:

class Person &lt; ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable 
end

The config.allow_unconfirmed_access_for setting does absolutely nothing without the confirmable module enabled.

The reason you would want to use config.allow_unconfirmed_access_for = nil is if you want to use Devise::Confirmable to confirm emails but not use it to restrict authorization. Many apps for example restrict certain features to users that have confirmed their email - but you can still log in how ever long you want with an unconfirmed email.

huangapple
  • 本文由 发表于 2020年1月4日 01:48:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/59583083.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定