【问题标题】:Devise + email confirmation token, to set initial password设计+电子邮件确认令牌,设置初始密码
【发布时间】:2014-05-30 11:32:15
【问题描述】:

设计 (3.2.4) rails (3.2.17) 和 cancan (1.6.10)

管理员创建其他用户。所以在RegistrationsController我有

before_filter :check_permissions, :only => [:new, :create]
skip_before_filter :require_no_authentication

def check_permissions
    authorize! :create, resource
end 

new and create 操作也是如此。

我发现很难关注confirmable 和一些通过 SO 问题。

如何为已注册的用户调用 generate_confirmation_token,并使用 confirmation_url 通过电子邮件发送链接,我应该使用ConfirmationsController。

编辑: 管理员仅使用姓名和电子邮件创建用户。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 devise cancan


    【解决方案1】:

    在用户模型中添加confirmable

    devise :confirmable
    

    通过此命令生成迁移

    rails g migration add_confirmable_to_devise
    

    在迁移文件中添加这个并运行rake db:migrate

    class AddConfirmableToDevise < ActiveRecord::Migration
      # Note: You can't use change, as User.update_all with fail in the down migration
      def self.up
        add_column :users, :confirmation_token, :string
        add_column :users, :confirmed_at, :datetime
        add_column :users, :confirmation_sent_at, :datetime
        # add_column :users, :unconfirmed_email, :string # Only if using reconfirmable
        add_index :users, :confirmation_token, :unique => true
        # User.reset_column_information # Need for some types of updates, but not for update_all.
        # To avoid a short time window between running the migration and updating all existing
        # users as confirmed, do the following
        User.update_all(:confirmed_at => Time.now)
        # All existing user accounts should be able to log in after this.
      end
    
      def self.down
        remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at
        # remove_columns :users, :unconfirmed_email # Only if using reconfirmable
      end
    end
    

    在注册时,设备将自动发送带有说明的确认电子邮件

    来源 - https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users

    【讨论】:

    • devise :confirmable 是我错过的。现在我得到密码不能为空的问题,我可以用任何方法覆盖吗?
    • 你是在没有密码的情况下注册的吗?
    • 您需要覆盖默认注册,然后在创建用户时创建一个随机密码,在确认电子邮件中将该密码连同确认链接一起发送给用户
    • 如果没有:confirmable,我也能做到。我需要用户通过链接本身设置他的初始密码,是否可以通过设计?
    • 创建一个控制器并覆盖默认行为,它不是预定义的
    猜你喜欢
    • 1970-01-01
    • 2013-07-11
    • 2019-08-04
    • 2017-02-22
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    • 2012-02-08
    相关资源
    最近更新 更多