所以我有一個設置Devise的Rails應用程序。我在我的Users
表中設置了:confirmable
,發送確認電子郵件完美無缺。Rails + Devise:當用戶在確認郵件之前嘗試登錄時,沒有出現錯誤通知?
不過,我正在與未經證實的用戶嘗試登錄一個小問題。
當一個無效的電子郵件/密碼組合輸入到登錄,我得到一個閃光的通知,上面寫着「無效的電子郵件或密碼。」。但是,如果未經確認的用戶正確登錄,它們將重定向回/users/sign_in
,但"You have to confirm your account before continuing."
沒有閃爍消息,該消息在/config/locales/devise.en.yml
中定義。
我已重寫thses方法:
RegistrationsController):新:創建
SessionsController):創建
ConfirmationsController):after_confirmation_path_for
究竟制定時未經確認的用戶做些什麼使用正確的憑據登錄?我試着在我的sessions#create
方法的頂部放置一個binding.pry
聲明,但它從來沒有打過它,這意味着Devise必須進行某種外部檢查。我試圖看看源代碼無濟於事。
這是日誌狀態正在發生的事情:
Started POST "https://stackoverflow.com/users/sign_in" for 127.0.0.1 at 2013-10-18 15:04:26 -0400
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"03kQgiMGyXcq/nW8jlVyGkGDw1Q9lpP+JZ03e+LZHPU=", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "commit"=>"Login"}
[1m[35mUser Load (0.7ms)[0m SELECT `users`.* FROM `users` WHERE `users`.`email` = '[email protected]' LIMIT 1
[1m[36m (0.2ms)[0m [1mBEGIN[0m
[1m[35m (0.1ms)[0m COMMIT
Completed 401 Unauthorized in 90ms
Started GET "https://stackoverflow.com/users/sign_in" for 127.0.0.1 at 2013-10-18 15:04:27 -0400
Processing by SessionsController#new as HTML
Rendered devise/shared/_links.haml (0.6ms)
Rendered devise/sessions/new.html.haml within layouts/application (5.0ms)
Rendered layouts/_header.html.haml (0.9ms)
Rendered layouts/_navigation.html.haml (0.6ms)
Rendered layouts/_footer.html.haml (0.9ms)
Completed 200 OK in 33ms (Views: 28.0ms | ActiveRecord: 0.0ms)
所以它看起來像sessions#create
方法被擊中。所以我不確定該從哪裏出發。任何幫助,將不勝感激!
config/routes.rb
devise_for :users, :controllers => {
:registrations => "registrations",
:sessions => "sessions",
:confirmations => "confirmations"}
那麼它的命中創建,收到「未經授權」,並重新繪製新的。這表現得應該如此。你可以發佈你的路線設計,確保它擊中你的自定義控制器。 – trh
我的路由是正確的,因爲它使用有效的電子郵件/密碼登錄時會創建創建方法。我只是試圖在未經證實的用戶嘗試登錄時創建一個'flash [:notice]'消息。 – justindao
我明白了,你是否收到了一條消息,而不是你期望的消息,或者你什麼都沒有收到? – trh