2015-09-30 65 views
0

我正在使用Rails教程3推出我自己的身份驗證系統,它的工作原理,直到我嘗試密碼重置部分。當我提交密碼重置表單時,會創建一個令牌並將其存儲在數據庫中作爲reset_password_tokenRails教程password_reset路由未找到

<a href="http://localhost:3000/password_resets/$2a$10$UU.bHK5V4o6BFRFPqjtPoOV12aSwq9nvy7OQuxFp.rFjK6lqfJali/edit?email=myemail">Reset password</a> 

當我點擊鏈接(或複製/粘貼,因爲它是本地)我得到一個錯誤:

No route matches [GET] "/password_resets/$2a$10$XAh7yOyphGR84n5fSBUZhuM4WpuyVwLayIZgB0QTTF.q3PgKX9Kz6/edit" 
然後電子郵件與鏈接到密碼重置形式看起來像這樣發

但耙路線顯示路線確實存在:

edit_password_reset_path GET /password_resets/:id/edit(.:format) password_resets#edit 

我的代碼,並在教程中的代碼之間的唯一區別是,我的令牌似乎是更長的時間。它大約60個字符,而Hartl的大約是22.另外,當我在控制檯輸入SecureRandom.urlsafe_base64時,我得到一個22個字符的標記。我不知道爲什麼它會創造一個更長的一個,但我也不確定它的重要性。

更新

梅勒模板:

To reset your password click the link below: 

<%= edit_password_reset_url(@user.reset_password_token, email: @user.email) %> 

This link will expire in two hours. 

If you did not request your password to be reset, please ignore this email and 
your password will stay as it is. 
+0

你可以在問題中發佈郵件模板代碼嗎? – Pavan

+0

一個有趣的事情是密碼重置鏈接都不同(特別是重置令牌'ID'參數)。這兩個鏈接都來自同一封電子郵件?在你的控制檯中用戶的'reset_digest'的價值是什麼(我認爲這是Hartl的教程中提到的)? – nayiaw

回答

0

的問題是,我懷疑與令牌做。我以前使用設計進行身份驗證,並且由於表命名不一致,郵件程序不會返回令牌,而是返回令牌摘要。一旦郵件程序返回令牌,路線就可以正常工作。