我正在玩Rayan Bates http://railscasts.com/episodes/170-openid-with-authlogic来源为基础。因此,我为OpenID提供商创建了几个图标,例如Google,Yandex,OpenID,用户必须选择使用哪一个(在此类似于stackoverflow)。所以一切都很好。现在我决定只进行一次点击登录或注册:当用户点击图标Authlogic必须创建新用户并对其进行身份验证时,或者,如果用户存在,只需对其进行身份验证即可。所以我绑改变用户#逻辑创建:Authlogic和OpenID注册和登录在一个动作
class UsersController < ApplicationController
def create
@user = User.new(params[:user])
@user.save do |result|
if result
redirect_to root_url
else
@user_session = UserSession.new(:openid_identifier => @user.openid_identifier)
@user_session.save
redirect_to root_url
end
end
end
end
所以,如果用户不能保存Authlogic将尝试验证他(当然,用户不能保存,不仅是否存在另一个用户与相同的openid_identifier,但只是例如)。但是这些方案是行不通的。在这种情况下什么也没有发生,@user_session.save
什么也没有返回。
UPD
展望Shripadķ链接源(http://github.com/shripadk/authlogic_openid_selector_example/blob/master/app/models/user_session.rb)我已经搭上了这一点:
class UserSession < Authlogic::Session::Base
auto_register
end
auto_register
是我所需要的
看起来很有趣。去看看 – fl00r 2010-07-18 08:32:18
好吧,我明白了:UserSession模型中的'auto_register'就足够了! – fl00r 2010-07-18 09:03:04
'auto_register'中存在一个错误。事实上,我已经用提交来修补我的应用程序。看看最新的提交。当你使用auto_register而不使用补丁时,它不会从open-id提供程序返回电子邮件地址(或任何sreg/ax)! – 2010-07-18 11:10:44