2015-04-30 5 views
5

मैं पूरी तरह वसीयत की त्रुटि संदेश 'reset_password_token is invalid' ओवरराइड करने के लिए कोशिश कर रहा हूँ बदलने का तरीका। मैं इसे "password reset link has already been used." मैं यह कैसे कर सकते पढ़ने के लिए चाहते हैं? वहाँ devise.en.yml में इस के लिए एक क्षेत्र या कीवर्ड के रूप में देखा नहीं है।वसीयत reset_password_token त्रुटि

उत्तर

2

Reset password token is invalid संदेश पासवर्ड अपडेट करते समय एक सत्यापन त्रुटि फेंक दी गई है, और यह एक विशिष्ट विशिष्ट त्रुटि नहीं है (जिसके लिए devise.en.yml में संग्रहीत संदेश)।

यह मान्यता devise/passwords_controller#update विधि में होता है। कोड नीचे शामिल:

# PUT /resource/password 
def update 
    self.resource = resource_class.reset_password_by_token(resource_params) 
    yield resource if block_given? 

    if resource.errors.empty? 
    resource.unlock_access! if unlockable?(resource) 
    flash_message = resource.active_for_authentication? ? :updated : :updated_not_active 
    set_flash_message(:notice, flash_message) if is_flashing_format? 
    sign_in(resource_name, resource) 
    respond_with resource, location: after_resetting_password_path_for(resource) 
    else 
    respond_with resource 
    end 
end 

self.resource = resource_class.reset_password_by_token(resource_params) लाइन सेट अमान्य किया जा रहा reset_password_token से संबंधित त्रुटि संदेश के साथ resource.errors वस्तु।

इस लाइन के बाद resource.errors का मूल्य निरीक्षण एक बड़ा हैश ... @messages={:reset_password_token=>["is invalid"]}

devise_error_messages method reformats इस के साथ समाप्त होने को कहते हैं "पासवर्ड टोकन अमान्य है रीसेट" दिखाई देगा।

इस संदेश को बदलने के लिए, पासवर्ड नियंत्रक को अनुकूलित किया जाना चाहिए और update विधि एक अलग त्रुटि संदेश हैश बदलने के लिए बदल गया है।

1) पासवर्ड नियंत्रक

# config/routes.rb 
devise_for :users, :controllers => { :passwords => "passwords" } 

2) बनाएं अनुकूलित पासवर्ड नियंत्रक

# app/controllers/passwords_controller.rb 
class PasswordsController < Devise::PasswordsController 

end 

3) के लिए अद्यतन विधि अनुकूलित के लिए मार्गों अनुकूलित:

कदम के रूप में निम्नानुसार होगा

# app/controllers/passwords_controller.rb 
# Include the update method as it is fully, with the following changes in the else block: 

def update 
    ... 

    if resource.errors.empty? 
    ... 
    else 
    if resource.errors.messages[:reset_password_token] 
     resource.errors.messages.delete(:reset_password_token) 
     resource.errors.messages[:password_reset_link] = ["has already been used"] 
    end 
    respond_with resource 
    end 
: त्रुटि संदेश को बदलने 363,210

अधिक Customizing Devise controllers के बारे में

1

passwords_controller अधिलेखन से एक अधिक आसान समाधान, दृश्य को संशोधित करने के लिए बस है:

ऐप्लिकेशन में/विचारों/वसीयत/पासवर्ड/edit.html.haml (या अपने ERB समकक्ष), बस प्रपत्र के अंदर इस सशर्त डाल:

- if resource.errors[:reset_password_token].present? 
    .alert.alert-danger 
    This password reset URL has expired. You may have requested to reset your password more than once. Follow the link in the most recent email or 
    = link_to 'request to reset your password again.', new_user_password_path 

और आप इन दो पंक्तियों को दूर कर सकते हैं:

= f.error_notification 
= f.full_error :reset_password_token 
संबंधित मुद्दे