如何使用devise gem

时间:2017-10-17 11:26:18

标签: ruby-on-rails devise

我对rails非常陌生。我正在使用设计宝石。现在,我试图在我的应用程序中实现忘记密码字段。我已经工作了几个小时,但我没有真正有任何结果。我该如何设置?我正在使用rails 4

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, #:registerable,
         :recoverable, :rememberable, :trackable, :validatable
  enum role: [:creator, :editor, :curator,  :super_admin]
  enum status: {:inprogress => 1, :completed => 2}

  #has_many :albums
  has_many :order_states
  has_many :products, through: :order_states

  has_many :tagging
  has_many :pictures, through: :tagging

  def self.authenticate(username, password)
    user = User.find_for_authentication(email: username)
    if user
      user.valid_password?(password) ? user : nil
    else
      nil
    end

  end

  def generate_authentication_token
    token = SecureRandom.hex
    self.update_columns(auth_token: token, token_created_at: Time.zone.now)
    token
  end

end

0 个答案:

没有答案