简体   繁体   English

设计+电子邮件确认令牌,设置初始密码

[英]Devise + email confirmation token, to set initial password

devise (3.2.4) rails (3.2.17) and cancan (1.6.10) 设计(3.2.4)导轨(3.2.17)和康康(1.6.10)

Admin creates other users. 管理员创建其他用户。 So in RegistrationsController I have 所以在RegistrationsController我有

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

def check_permissions
    authorize! :create, resource
end 

new and create actions as well. new and create动作。

I'm finding it difficult to follow confirmable and some through SO questions. 我发现很难遵循可确认的问题以及某些SO问题。

How to call generate_confirmation_token for the signed up user,and email the link using confirmation_url , should I use ConfirmationsController . 如果我要使用ConfirmationsController ,则如何为已注册的用户调用generate_confirmation_token ,并使用confirmation_url通过电子邮件发送链接

edit: Admin creates user with just name and email. 编辑:管理员只使用名称和电子邮件创建用户。

In User model add confirmable 在用户模型中添加confirmable

devise :confirmable

Generate migration by this command 通过此命令生成迁移

rails g migration add_confirmable_to_devise

In migration file add this and run rake db:migrate 在迁移文件中添加此代码并运行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

On signup devise will automatically send confirmation email with instructions 在注册时,devise将自动发送包含说明的确认电子邮件

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM