ruby-on-rails - 设计忘记密码设置

标签 ruby-on-rails ruby devise

我真的是 Rails 的新手,一直在努力构建一个应用程序。一段时间后,我最近为 facebook 安装了 devise 和 omniauth,并取得了巨大的成功。当我阅读 devise 时,我注意到 Devise 内置了一个“忘记密码”模块。

我已经在互联网上搜索过了,但我一直都不知道如何设置它。有什么指南吗?我已经工作了几个小时,但我还没有真正的结果。我该如何设置?我正在使用 Rails 4.0 和最新版本的设计。

谢谢,

路线

Omrails::Application.routes.draw do
resources :boards

resources :pins

get 'about' => "pages#about"

root :to => 'pins#index'
resources :tests, :birthdays
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks"  }
end

设计迁移:

class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  t.integer  :sign_in_count, :default => 0, :null => false
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.string   :current_sign_in_ip
  t.string   :last_sign_in_ip

  ## Confirmable
  # t.string   :confirmation_token
  # t.datetime :confirmed_at
  # t.datetime :confirmation_sent_at
  # t.string   :unconfirmed_email # Only if using reconfirmable

  ## Lockable
  # t.integer  :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at


  t.timestamps
end

add_index :users, :email,                :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token,   :unique => true
# add_index :users, :unlock_token,         :unique => true
end
end

用户.rb

class User < ActiveRecord::Base 

 # Include default devise modules. Others available are:
 # :token_authenticatable, :confirmable,
 # :lockable, :timeoutable and :omniauthable
 devise :database_authenticatable, 
     :registerable, 
     :rememberable, 
     :trackable, 
     :recoverable,
     :validatable, 
     :omniauthable, 
     :omniauth_providers => [:facebook]


 # Setup accessible (or protected) attributes for your model
 attr_accessible :email, :password, :password_confirmation, :remember_me, :name,    :birthday, :sex, :address, :mobile, :provider, :uid

 has_many :pins, :dependent => :destroy
has_many :boards, :dependent => :destroy
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
unless user
  user = User.create(name:auth.extra.raw_info.name,
                       provider:auth.provider,
                       uid:auth.uid,
                       email:auth.info.email,
                       password:Devise.friendly_token[0,20])
end
user
end
end

最佳答案

Devise 由 10 个模块组成,您正在寻找的模块是可恢复的。在您的设计模型中,您需要为设计添加 :recoverable 属性。

关于ruby-on-rails - 设计忘记密码设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19339679/

相关文章:

ruby-on-rails - 如何构建 Nodejs 服务器和 Rails 之间的通信?

Ruby Unicode 和字符串插值问题

ruby-on-rails - 浏览器保存的密码不会在页面加载时加载

ruby-on-rails - rails 设计 : get object of the currently logged in user?

ruby-on-rails - 在 Destroy_User_Session_Path 之前设计操作

ruby-on-rails - Ransack Gem Rails 和多选

ruby-on-rails - 有没有办法配置 Rails 控制台来重新运行我的初始化程序?

ruby-on-rails - 将符号作为方法传递?

ruby-on-rails - 隐藏电子邮件地址的一部分

ruby - 用 ruby​​ 进行时间序列重采样