0
使用與設計的Omniauth Github的戰略和Rails 4設計的`#sign_in_and_redirect`仍然存在用戶即使無效
我已經引起了#創建的代碼驗證失敗下面失敗(返回失敗的用戶對象,並輸入if
,因爲它仍然計算爲true
),然後將未保留的用戶傳遞給#sign_in_and_redirect
(模型錯誤完好)。我對所有事情都很滿意,直到這裏。錯誤的代碼,但在有意義的方面不好。
儘管這樣,用戶實際上是在#sign_in_and_redirect
代碼創建地方(通過與描述puts
的和服務器日誌縮小下來發現)。
A)我找不到在Devise或Omniauth源中發生的情況。我找不到#save
或#create
呼叫。 B)即使#create
或#save
被#sign_in_and_redirect
調用,它們仍應該由於錯誤而失敗。
這怎麼可能?
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
...
user = User.create(provider: omniauth['provider'],
uid: omniauth['uid'],
email: omniauth['info']['email'],
username: omniauth['info']['nickname'])
if user
flash.now[:notice] = "Signed in successfully"
# Makes perfect sense how we got here, user is currently not persisted
sign_in_and_redirect(:user, user)
# Somehow, magically, user is now persisted
else
...
感謝您的答覆 - 我編輯的問題,爲清楚起見,但我真正想知道就是爲什麼'#sign_in_and_redirect'is都堅持我的用戶,其次,出現瞭如何給用戶是無效的。 –