2012-11-09 65 views
1

我正在尋找在設計中的定製,如果我們點擊忘記密碼,它應該發送郵件到任何電子郵件ID。無論電子郵件ID是否存在,Gmail中都會發生類似情況。設計發送忘記密碼指令到任何電子郵件編號

屏幕1個 enter image description here

屏幕2 enter image description here

目前我有什麼是這其中它試圖與系統中的有效用戶來驗證。

enter image description here

Deviserecoverable module需要照顧這個

 def send_reset_password_instructions(attributes={}) 
      recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found) 
      recoverable.send_reset_password_instructions if recoverable.persisted? 
      recoverable 
     end 

我怎樣才能刪除此驗證,併發送到任何電子郵件ID電子郵件?

+0

設計控制用戶的存在。什麼是你的設計版本? – emrahbasman

+0

使用Devise 1.5.3 – AnkitG

回答

8

有一個名爲paranoid的設計配置,當設置爲true時,將以避免電子郵件枚舉的方式更改消息。只需在您的設計配置中設置config.paranoid = true即可。

2

我的解決方案是擴展/重寫Devise的密碼控制器。要做到這一點,創建一個控制器(讓我們的密碼稱呼它),從設計的密碼控制器繼承,像這樣:

class PasswordsController < Devise::PasswordsController 

然後編輯你的路由文件,以便此更改生效:

devise_for :users, :controllers => { :passwords => 'passwords' } 

現在,你會想要覆蓋create action。有幾種方法可以做到這一點,但因爲我不知道你想做什麼,我會告訴你兩件事情你可以做:

  1. 你只是想阻止「電子郵件未找到「的錯誤,使人們無法找到該郵件存在或不是在你的數據庫:

    def create 
        self.resource = resource_class.send_reset_password_instructions(resource_params) 
    
        respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name)) 
    end 
    
  2. 你真的想發送電子郵件到任何輸入的電子郵件:

    def create 
        self.resource = resource_class.send_reset_password_instructions(resource_params) 
    
        unless successfully_sent?(resource) 
        Devise::Mailer.reset_password_instructions(resource).deliver 
        end 
    
        respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name)) 
    end 
    

現在,這個最後的解決方案的問題是,你正在發送一封電子郵件給一個不存在的用戶......所以當用戶回來時,他將無法輸入他的新密碼,因爲他的用戶帳戶無法找到。但如果你真的想這樣做,希望我能讓你走上正軌。

相關問題