我正在尝试将 Devise 与 Omniauth 集成,但两者都有一些问题。主要问题是将设计用户模型与 Omniauth 身份验证绑定。我想要一种简单的方法来将我的用户与 facebook、twitter、g+ 等外部提供商联系起来。
我的应用程序出现的最烦人的问题之一是:
如果一个用户在我的网站上注册了 devise(我称之为本地用户),这意味着,提供了一个电子邮件和一个密码,当用户尝试使用 twitter 登录时,系统会要求邮件确认。如果该邮件已经存在,则用户必须提供另一封邮件。相反,我希望他可以使用密码确认这实际上是他的电子邮件。怎么做?如何覆盖该模板?
这是我的身份验证控制器:
class AuthenticationsController < ApplicationController
def index
@authentications = Authentication.all
end
def create
@authentication = Authentication.new(params[:authentication])
if @authentication.save
redirect_to authentications_url, :notice => "Successfully created authentication."
else
render :action => 'new'
end
end
def destroy
@authentication = Authentication.find(params[:id])
@authentication.destroy
redirect_to authentications_url, :notice => "Successfully destroyed authentication."
end
def twitter
omni = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omni['provider'], omni['uid'])
if authentication
flash[:notice] = "Logged in Successfully"
sign_in_and_redirect User.find(authentication.user_id)
elsif current_user
token = omni['credentials'].token
token_secret = omni['credentials'].secret
current_user.authentications.create!(:provider => omni['provider'], :uid => omni['uid'], :token => token, :token_secret => token_secret)
flash[:notice] = "Authentication successful."
sign_in_and_redirect current_user
else
user = User.new
user.apply_omniauth(omni)
if user.save
flash[:notice] = "Logged in."
sign_in_and_redirect User.find(user.id)
else
session[:omniauth] = omni.except('extra')
p session
redirect_to new_user_registration_path
end
end
end
end
我也不知道在哪里new_users_registration_path
。