2015-07-21 114 views
4

我想實現類似於一個介質的用戶認證系統,其中用戶只需把他們的電子郵件地址,而註冊&他們會在郵箱的確認鏈接,點擊該鏈接,他們以後被重定向回到網站,然後被要求填寫密碼和其他細節。 我使用的設計&發現2篇文章,但他們沒有工作。 Stackoverflow有類似的問題,但沒有好的解決方案。

https://github.com/plataformatec/devise/wiki/How-To:-Email-only-sign-up
https://github.com/plataformatec/devise/wiki/How-To:-Override-confirmations-so-users-can-pick-their-own-passwords-as-part-of-confirmation-activation

有什麼不對這些物品?電子郵件只註冊使用設計與軌道

回答

0

爲了與註冊用戶出密碼,我們要做的是使第一件事就是確保我們有機會獲得設計視圖這樣

rails generate devise:views

,我關心的視圖大多數在這個時候是應用程序/視圖/設計/註冊/ new.html.erb *,但你一定要看看他們都確保他們匹配應用程序*

要找到並刪除它

。這應該是行11 - 22如果一切都是默認的

<div class="field"> 
    <%= f.label :password %> 
    <% if @minimum_password_length %> 
    <em>(<%= @minimum_password_length %> characters minimum)</em> 
    <% end %><br /> 
    <%= f.password_field :password, autocomplete: "off" %> 
    </div> 

    <div class="field"> 
    <%= f.label :password_confirmation %><br /> 
    <%= f.password_field :password_confirmation, autocomplete: "off" %> 
    </div> 

現在窗體將提交給控制器沒有密碼。這將觸發一個錯誤密碼不能爲空

所以我在這一點上做的只是給它這樣

1密碼)色器件registrations_controller.rb複製到你的應用程序

#app/controllers/devise/registrations_controller.rb 
class Devise::RegistrationsController < DeviseController 
    ... 

    def create 
    build_resource(sign_up_params) 

    resource.password = SecureRandom.hex(10) # sets the password 

    resource.save 
    yield resource if block_given? 
    if resource.persisted? 
     resource.send_reset_password_instructions # send them instructions how to reset password 

     if resource.active_for_authentication? 
     set_flash_message! :notice, :signed_up 
     sign_up(resource_name, resource) 
     respond_with resource, location: after_sign_up_path_for(resource) 
     else 
     set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}" 
     expire_data_after_sign_in! 
     respond_with resource, location: after_inactive_sign_up_path_for(resource) 
     end 
    else 
     clean_up_passwords resource 
     set_minimum_password_length 
     respond_with resource 
    end 
    end 
    ... 
end 

我希望這有助於 你可以找到我的代碼here

相關問題