在Kinvey中合并用户 [英] Merging Users in Kinvey

查看:280
本文介绍了在Kinvey中合并用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:


  1. 用户A在我们的申请中注册一个帐户并登录。


  2. 使用Facebook社交登录,使用具有与
    原始注册相关联的相同电子邮件的帐户,再次登录到应用程序。

  3. 为此登录创建了第二个帐户,系统中存在2个帐户。

如何在社交登录期间(通过查询该电子邮件的存在)将这些帐户合并到一个帐户中自动或与用户集合业务挂钩(如果有业务钩子,请提供一个示例,我将如何做



注意:




  • > Kinvey后端

  • 有Facebook插件的Phonegap

  • Jquery mobile

  • 希望合并帐户或找到现有帐户

  • 假设我无法删除用户

  • 最好使用PreSave Kinvey业务逻辑钩子实现此步骤



解决方案

创建自己的自定义终点基本上实现用户合并。



如果用户存在kinvey帐户,则尝试使用facebook登录,并使用与kinvey匹配的电子邮件地址用户,我使用以下端点代码在尝试使用该用户登录之前向现有用户添加社交身份(此功能仅在因为我们为未登录到系统的用户维护访客登录时才起作用)。



希望这有助于某一个。

  function onRequest ){
var users = modules.collectionAccess.collection('user');
var social = request.body.social;
users.findAndModify({username:request.body.email},{$ set:{_ socialIdentity:social}},
function(err,result){
if err){
response.error(err);
response.complete();
} else {
if(!result._id){
response.body = {message:找不到用户匹配此电子邮件};
response.complete();
} else {
response.body = {message:User Was Hopefully Updated};
response.complete();
}
}
});
}


Situation:

  1. User A registers an account in our application and logs in.
  2. For what ever reason logs out.
  3. Logs in to the application again using Facebook social sign on with an account that has the same email associated with it as the original registration had.
  4. A second account is created for this sign on and 2 accounts exist in the system.

How can I merge these accounts into a single account during the social sign on (by querying for the existence of that email) automatically or with User Collection Business Hooks (if with business hooks, can you please provide an example of how I would do this as documentation online is unclear for this specific purpose).

Notes:

  • Kinvey backend
  • Phonegap with facebook plugin
  • Jquery mobile
  • Wish to merge accounts or find existing account and add social identity to it during sign on
  • Assume I cannot delete users
  • Preferably achieve this step with a PreSave Kinvey Business Logic Hook

Cheers,

解决方案

I managed to create my own custom end point to basically achieve user merging.

If a user exists with a kinvey account, then tries to log in using facebook with an email address matching a kinvey user, I used the following end point code to add a social identity to the existing user before attempting to log in using that user (This function only worked because we maintain a guest login for users not logged in to the system).

Hope this helps some one.

function onRequest(request, response, modules) {
  var users = modules.collectionAccess.collection('user');
  var social = request.body.social;
  users.findAndModify({"username":request.body.email},{$set:{"_socialIdentity":social}},
  function(err,result){
    if(err){
      response.error(err);
      response.complete();
    }else{
     if(!result._id){
       response.body = {message:"No User Found Matching This Email"};
       response.complete();
     }else{
       response.body = {message:"User Was Hopefully Updated"};
       response.complete();
     }
    }
  });
}

这篇关于在Kinvey中合并用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆