gpt4 book ai didi

设计 + Omniauth + remember_me

转载 作者:行者123 更新时间:2023-12-04 08:29:43 28 4
gpt4 key购买 nike

关于如何记住我与 Omniauth 一起工作似乎有些困惑。

根据这个wiki ,您需要在 OmniauthCallbacksController 中包含以下内容:

remember_me(user)

另一方面,根据这个 issue ,你只需要这样做:
user.remember_me = true

另外,根据 this,让remember_me默认为true ,您只需要将以下内容添加到您的 User.rb
def remember_me
true
end

不确定哪一个是官方答案,这三个都不适合我。它仅适用于 Mac 上的 Chrome,但不适用于 Firefox Mac 和 Chrome Windows。不知道发生了什么。

我的代码如下所示:
# -*- encoding : utf-8 -*-
class OmniauthCallbacksController < Devise::OmniauthCallbacksController

include Devise::Controllers::Rememberable

def all
omniauth = request.env["omniauth.auth"]
auth = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if auth

auth.update_with_omniauth omniauth
auth.save!

# ???
remember_me auth.user
auth.user.remember_me = true

if user_signed_in?
redirect_back_or settings_path(current_user)
else
sign_in_and_redirect auth.user, event: :authentication
end
else
if user_signed_in?
current_user.build_auth(omniauth).save!
redirect_back_or settings_path(current_user)
else
session["devise.omniauth"] = omniauth.except('extra')
redirect_to new_user_registration_url
end
end
end

alias_method :facebook, :all
alias_method :twitter, :all

end

最佳答案

这是回答 here来自 Jose Valim .

The first option is the correct one. The other two simply set the default value of the field to true, which means it will be automatically remembered whenever the first one is called.

If it works in some browsers or not, it is likely a browser issue because the server is definitely sending the proper cookies. Try to confirm if the cookie is indeed correct and find out if the browser is storing it properly.

关于设计 + Omniauth + remember_me,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25345956/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com