Ruby on rails 设计忘记密码设置
我是rails的新手,一直在尝试构建一个应用程序。我最近为facebook安装了Desive和omniauth,一段时间后取得了巨大成功。当我阅读Desive时,我注意到Desive内置了一个“忘记密码”模块 我搜索过互联网,但我一辈子都没有弄清楚如何设置它。有什么指导吗?我已经工作了好几个小时了,但还没有什么结果。我该如何设置?我使用的是rails 4.0和Desive的最新版本 谢谢 路线Ruby on rails 设计忘记密码设置,ruby-on-rails,ruby,devise,Ruby On Rails,Ruby,Devise,我是rails的新手,一直在尝试构建一个应用程序。我最近为facebook安装了Desive和omniauth,一段时间后取得了巨大成功。当我阅读Desive时,我注意到Desive内置了一个“忘记密码”模块 我搜索过互联网,但我一辈子都没有弄清楚如何设置它。有什么指导吗?我已经工作了好几个小时了,但还没有什么结果。我该如何设置?我使用的是rails 4.0和Desive的最新版本 谢谢 路线 Omrails::Application.routes.draw do resources :boar
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
classdeveliecCreateUsersfalse,:default=>
t、 字符串:加密密码,:null=>false,:default=>
##可恢复
t、 字符串:重置密码\u令牌
t、 日期时间:重置密码发送时间
##难忘的
t、 datetime:记住在
##可追踪
t、 整数:计数中的符号,:default=>0,:null=>false
t、 日期时间:当前登录时间
t、 日期时间:上次登录时间
t、 字符串:ip中的当前\u符号\u
t、 字符串:ip中的最后\u签名\u
##可证实
#t.string:确认令牌
#t.datetime:已确认
#t.datetime:确认发送至
#t.string:未确认的电子邮件#仅当使用可再确认
##可锁
#t.integer:failed_尝试,:default=>0,:null=>false#仅当锁定策略为:failed_尝试时
#t.string:unlock_token#仅当解锁策略为:email或:两者皆有时
#t.datetime:locked_在
t、 时间戳
结束
添加索引:users,:email,:unique=>true
添加索引:users,:reset\u password\u token,:unique=>true
#添加索引:users,:confirmation\u token,:unique=>true
#添加索引:users,:unlock\u token,:unique=>true
结束
结束
User.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
class用户[:facebook]
#设置模型的可访问(或受保护)属性
可访问属性:电子邮件、密码、密码确认、记住我、姓名、生日、性别、地址、手机、提供商、uid
有多个:pin,:dependent=>:destroy
有多个:电路板,:dependent=>:destroy
def self.find_for_facebook_oauth(auth,signed_in_resource=nil)
user=user.where(:provider=>auth.provider,:uid=>auth.uid)。首先
除非用户
user=user.create(名称:auth.extra.raw\u info.name,
提供者:auth.provider,
uid:auth.uid,
电子邮件:auth.info.email,
密码:designe.friendly_令牌[0,20])
结束
用户
结束
结束
Desive由10个模块组成,您正在寻找的模块是可恢复的。在您的设备模型中,您需要为设备添加:recoverable
属性。太棒了,谢谢!但是当我这样做的时候,我会得到一个错误“undefined method`new#u password_path` for#”,这就是我所要做的吗?只是把我的评论移到ans上,以防万一其他人遇到同样的问题,你能运行rake路由来看看你是否看到了新的#u密码路由吗?你需要重新启动你的应用程序才能看到有效的更改,我看到的是新的用户密码,但不是新的密码路径。在routes.rb中,我有“design_for:users,:controllers=>{:omniauth_callbacks=>“users/omniauth_callbacks”}这正是您需要的,您可以重新启动服务器并重试吗?