Пример #1
0
 public void bindingSns(
     String appId,
     String plat,
     String id,
     String platform,
     BaasAuth auth,
     BaasUser currentUser,
     boolean isMaster) {
   if (!isMaster) {
     // 非管理权限
     if (currentUser == null || !currentUser.getId().equals(id)) {
       // 非本人禁止修改社交平台信息
       throw new SimpleError(SimpleCode.USER_NOT_MATCH);
     }
   }
   // 验证授权信息是否有效
   if (!authUtil.verifyAuthData(platform, auth)) {
     // 授权无效
     throw new SimpleError(SimpleCode.USER_AUTH_REJECT);
   } else {
     // 验证是否已经绑定现有用户
     BaasUser exist = getUserByAuth(appId, plat, platform, auth.getUid());
     if (exist != null) {
       // 该第三方用户信息已经被其他用户绑定,禁止重复绑定
       throw new SimpleError(SimpleCode.USER_AUTH_EXIST);
     }
     // 授权有效 将授权信息与用户绑定
     BaasObject object = objectService.get(appId, plat, USER_CLASS_NAME, id);
     BaasUser userNow = new BaasUser(object);
     BaasObject authNow = userNow.getAuth();
     if (authNow == null) {
       // 当前授权信息为空 创建新的授权信息
       authNow = new BaasObject();
     }
     // 填充授权信息
     authNow.put(platform, auth);
     BaasUser userNew = new BaasUser();
     userNew.setAuth(authNow);
     objectService.update(appId, plat, UserService.USER_CLASS_NAME, id, userNew, null, true);
     // 更新成功 清除用户缓存
     deleteUserCache(appId, userNow.getSessionToken());
   }
 }
Пример #2
0
 /**
  * 使用第三方平台登录信息进行登录
  *
  * @param appId 应用id
  * @param platform 名称
  * @param auth 授权信息
  * @return 用户信息
  */
 public BaasUser loginWithSns(String appId, String plat, String platform, BaasAuth auth) {
   // 验证授权信息
   if (!authUtil.verifyAuthData(platform, auth)) {
     // 授权无效
     throw new SimpleError(SimpleCode.USER_AUTH_REJECT);
   }
   BaasUser user = getUserByAuth(appId, plat, platform, auth.getUid());
   if (user == null) {
     throw new SimpleError(SimpleCode.USER_NOT_EXIST);
   }
   // 更新accessToken
   BaasObject authNow = user.getAuth();
   // 填充授权信息
   authNow.put(platform, auth);
   BaasUser userNew = new BaasUser();
   userNew.setAuth(authNow);
   objectService.update(
       appId, plat, UserService.USER_CLASS_NAME, user.getId(), userNew, null, true);
   // 返回用户信息
   user.setPassword("");
   return user;
 }