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

时间:2014-05-30 11:32:16

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

设计(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和一些问题。

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

修改 管理员只使用姓名和电子邮件创建用户。

1 个答案:

答案 0 :(得分:2)

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