简体   繁体   English

允许现有用户添加Facebook帐户

[英]Allow Existing Users to Add Facebook Accounts

In my app, users can login with Facebook using the code from this tutorial . 在我的应用程序中,用户可以使用本教程中的代码登录Facebook。 The only issue is I want to allow users who signed up for my app the old fashioned way (As in users go to the signup page and input all their data like email, password, etc and don't log in with Facebook.) to be able to connect their Facebook account with their existing account. 唯一的问题是我希望允许以旧方式注册我的应用程序的用户(因为用户进入注册页面并输入其所有数据,例如电子邮件,密码等,并且不使用Facebook登录)。能够将其Facebook帐户与现有帐户相关联。 I haven't seen any questions on this, and I'm wondering how should I implement this. 我还没有看到任何关于此的问题,我想知道应该如何实施。

Omniauthcallbacks Controller Omniauthcallbacks控制器

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def all
    user = User.from_omniauth(request.env["omniauth.auth"])
    if user.persisted?
      flash.notice = "Signed in!"
      sign_in_and_redirect user
    else
      session["devise.user_attributes"] = user.attributes
      redirect_to new_user_registration_url
    end
  end
  alias_method :facebook, :all
end

The only issue is I want to allow users who signed up for my app the old fashioned way (As in users go to the signup page and input all their data like email, password, etc and don't log in with Facebook.) to be able to connect their Facebook account with their existing account. 唯一的问题是我希望允许以旧方式注册我的应用程序的用户(因为用户进入注册页面并输入其所有数据,例如电子邮件,密码等,并且不使用Facebook登录)。能够将其Facebook帐户与现有帐户相关联。

Two possible ways: 两种可能的方式:

  1. Use the email address to automatically connect an existing account with that email set when a user uses the Facebook registration flow. 当用户使用Facebook注册流程时,使用电子邮件地址自动将现有帐户与该电子邮件集相关联。 (“An account with the email address foo@example.com already exists, do you want to connect your Facebook account with it?”) (“已经存在一个电子邮件地址为foo@example.com的帐户,您想将其与Facebook帐户相关联吗?”)

  2. Have the user log in using your login system, and then offer them a “connect with your Facebook account”-button – and then when they authenticate via Facebook, connect that Facebook ID with the logged in user account. 让用户使用您的登录系统登录,然后为他们提供“与您的Facebook帐户连接”按钮-然后,当他们通过Facebook进行身份验证时,将该Facebook ID与登录的用户帐户连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM