我有一个漂亮的标准User
模型与设计。管理员在模型上使用布尔值:admin
进行控制,而非管理员的用户不能自行管理(即只有管理员可以对用户进行更改)。设计:允许用户重置密码只有
我想要的是允许用户重置他们的密码,如果他们忘记了。他们会输入他们的电子邮件地址,然后通过电子邮件发送令牌,以授予他们访问权限以更改它。我已经开始了一个解决方案,但我真的不知道如何继续。
user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
attr_accessor :current_password
attr_accessible :name, :password, :password_confirmation, :current_password, :email, :remember_me, :ftp, :colour1, :colour2, :logo, :logo2, :address, :url, :disclosure, :general_advice, :facebook, :twitter, :brand_id, :analytics
attr_protected :admin
validates_uniqueness_of :email, :ftp
belongs_to :brand
has_many :docs
has_many :orders, :through => :docs
has_attached_file :logo
has_attached_file :logo2
end
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new #guesting
if user.admin?
can :manage, :all
else
can :manage, :recoverable
end
end
end
而这里的方法:
def reset
@idiot = User.where(:email => params[:email]).first
unless @idiot.nil?
Notifier.send_reset_notice(@idiot).deliver
@idiot.send_reset_password_instructions
redirect_to new_user_session_url
else
redirect_to new_user_session_url, :flash => { :error => "That email address matches no user." }
end
end
用户收到的电子邮件设计,但点击该链接将用户带到应用程序的根,而不是一密码重置表单。我不知道如何从这里开始。有什么想法吗?干杯!
UPDATE
相关路线:
devise_for :users, :path => "d"
devise_scope :user do
get '/sign_in' => 'devise/sessions#new'
get '/sign_out' => 'devise/sessions#destroy'
end
你必须要尝试这种解决方案[设计维基](HTTPS:// GI thub.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-edit-their-password)? – 2013-04-10 05:08:43
是的,它不适合我的情况。感觉就像我的路线有问题或什么的。我会用我的路线更新这个问题。 – 2013-04-10 05:12:22