2012-09-05 60 views
0

我正在使用refinerycms並覆蓋重置密碼的功能。 這裏是我的密碼查看網頁:覆蓋RefineryCMS的普通用戶的重置密碼功能

密碼/ new.html.erb

<h2>Forgot your password?</h2> 
<%= form_for(resource, :as => resource_name, :url => refinery.user_password_path, :html => { :method => :post }) do |f| %> 

<div><%= f.label :email %><br /> 
<%= f.email_field :email %></div> 

<div><%= f.submit "Send me reset password instructions" %></div> 
<% end %> 

密碼/ edit.html.erb

<h2>Change your password</h2> 

<%= form_for(resource, :as => resource_name, :url => refinery.user_password_path, :html => { :method => :put }) do |f| %> 
<%= f.hidden_field :reset_password_token %> 

<div><%= f.label :password, "New password" %><br /> 
<%= f.password_field :password %></div> 

<div><%= f.label :password_confirmation, "Confirm new password" %><br /> 
<%= f.password_field :password_confirmation %></div> 

<div><%= f.submit "Change my password" %></div> 
<% end %> 

和密碼控制器是:

class PasswordsController < Devise::PasswordsController 
    helper Refinery::Core::Engine.helpers 
    before_filter :store_password_reset_return_to, :only => [:update] 

    def store_password_reset_return_to 
    session[:'refinery_user_return_to'] = refinery.admin_root_path 
    end 
    protected :store_password_reset_return_to 

    # Rather than overriding devise, it seems better to just apply the notice here. 
    after_filter :give_notice, :only => [:update] 
    def give_notice 
    Rails.logger.debug @refinery_user 
    if %w(notice error alert).exclude?(flash.keys.map(&:to_s)) or    @refinery_user.errors.any? 
    flash[:notice] = t('successful', :scope => 'users.reset', :email => @refinery_user.email) 
    end 
    end 
    protected :give_notice 

    # GET /registrations/password/edit?reset_password_token=abcdef 
    def edit 
    if params[:reset_password_token] and ( @refinery_user = Refinery::User.where(:reset_password_token => params[:reset_password_token]).first).present? 
     #Rails.logger.debug @refinery_user 
     #logger.debug"******************************************************" 
     respond_with(@refinery_user) 
    else 
     redirect_to refinery.new_user_password_path, 
       :flash => ({ :error => t('code_invalid', :scope => 'refinery.users.reset') }) 
    end 
    end 

    # POST /registrations/password 
    def create 
    if params[:user].present? and (email = params[:user][:email]).present? and (user = Refinery::User.where(:email => email).first).present? 

     # Call devise reset function. 
     user.send(:generate_reset_password_token!) 
     UserMailer.reset_notification(user, request).deliver 
     redirect_to refinery.new_user_session_path,:notice => t('email_reset_sent', :scope => 'users.forgot') 
    else 
     flash.now[:error] = if (email = params[:user][:email]).blank? 
     t('blank_email', :scope => 'users.forgot') 
     else 
     t('email_not_associated_with_account_html', :email => ERB::Util.html_escape(email), :scope => 'users.forgot').html_safe 
     end 
     render :new 
    end 
    end 
end 

郵件成功發送電子郵件與重置通知和編輯密碼林k但是 當我輸入新密碼並點擊輸入時,它會給出錯誤
「undefined method email' for nil:NilClass",app/controllers/passwords_controller.rb:15:in give_notice」。 我如何刪除該錯誤??請幫助!

+0

是否有任何一個誰幫我嗎? –

回答

0

結果是簡單地刪除give_notice方法和使用錯誤信息領域的密碼/ edit.html.erb爲:

​​