我正在使用 Rayan Bates http://railscasts.com/episodes/170-openid-with-authlogic资源作为基础。
所以我为 OpenID 提供商创建了几个图标,比如 Google、Yandex、OpenID,并且用户必须选择使用哪一个(类似于 stackoverflow 上的这里)。所以一切都很好。现在我决定只单击一次登录或注册:当用户单击图标时,Authlogic 必须创建新用户并对其进行身份验证,或者,如果用户存在,则对其进行身份验证。所以我绑定到 User#create 中的更改逻辑:
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
在这种情况下什么也不返回。
更新
调查Shripad K链接源(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
我所需要的