簡體   English   中英

設計+電子郵件確認令牌,設置初始密碼

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

設計(3.2.4)導軌(3.2.17)和康康(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動作。

我發現很難遵循可確認的問題以及某些SO問題。

如果我要使用ConfirmationsController ,則如何為已注冊的用戶調用generate_confirmation_token ,並使用confirmation_url通過電子郵件發送鏈接

編輯:管理員只使用名稱和電子郵件創建用戶。

在用戶模型中添加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

在注冊時,devise將自動發送包含說明的確認電子郵件

來源-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