private static List <AppUserAccountInfo> GetAppUserAccountInSql()
        {
            List <AppUserAccountInfo> appUserAccountInfos = new List <AppUserAccountInfo>();
            Database database = Database.GetDatabase("BeisenUserSecurity");

            SafeProcedure.ExecuteAndGetInstanceList(database, "[dbo].[AppUserAccount_GetAll]",
                                                    delegate(IRecord record, int entity)
            {
                AppUserAccountInfo appUserAccountInfo = new AppUserAccountInfo();
                appUserAccountInfo.Id              = record.GetOrDefault <int>("Id", 0);
                appUserAccountInfo.AppId           = record.GetOrDefault <string>("AppId", "");
                appUserAccountInfo.OpenId          = record.GetOrDefault <string>("OpenId", "");
                appUserAccountInfo.TenantId        = record.GetOrDefault <int>("TenantId", 0);
                appUserAccountInfo.UserId          = record.GetOrDefault <int>("UserId", 0);
                appUserAccountInfo.BeisenAccount   = record.GetOrDefault <string>("BeisenAccount", "");
                appUserAccountInfo.TypeNotEnum     = record.GetOrDefault <Int16>("Type", 0);
                appUserAccountInfo.StateNotEnum    = record.GetOrDefault <Int16>("State", 0);
                appUserAccountInfo.ActivateTime    = record.GetOrDefault <DateTime>("ActivateTime", DateTime.Now);
                appUserAccountInfo.CreateTime      = record.GetOrDefault <DateTime>("CreateTime", DateTime.Now);
                appUserAccountInfo.UnbindTime      = record.GetOrDefault <DateTime>("UnbindTime", DateTime.Now);
                appUserAccountInfo.MasterAccountId = record.GetOrDefault <int>("MasterAccountId", 0);
                appUserAccountInfos.Add(appUserAccountInfo);
            });
            return(appUserAccountInfos);
        }
        private static ObjectData IsExistLogin(int tenantId, AppUserAccountInfo appUserAccountInfo)
        {
            ApplicationContext.Current.ApplicationName = AppUserConstants.MetaName;
            ApplicationContext.Current.TenantId        = tenantId;
            ApplicationContext.Current.UserId          = appUserAccountInfo.UserId;
            ObjectData objectData = new ObjectData();
            var        filter     = new BooleanFilter()
                                    .Must(new TermFilter(AppUserConstants.AppUser_AppId, appUserAccountInfo.AppId))
                                    .Must(new TermFilter(AppUserConstants.AppUser_OpenId, appUserAccountInfo.OpenId));
            // .Must(new TermFilter(AppUserConstants.AppUser_UserId, appUserAccountInfo.UserId));
            var result = CloudDataHelper.GetEntityAllList("AppConnect.AppUser", tenantId, filter).ToList();

            if (result != null && result.Count > 0)
            {
                if (result.Count > 1)
                {
                    AppConnectLogHelper.Error("AppId下面的OpenId个数大于一个!appUserAccountInfo:" + JsonConvert.SerializeObject(appUserAccountInfo));
                    objectData = null;
                }
                else
                {
                    objectData = result.First();
                }
            }
            else
            {
                objectData = null;
            }
            return(objectData);
        }
        private static void AddCLoud(int tenantId, int sqlId, AppUserAccountInfo appUserAccountInfo)
        {
            ApplicationContext.Current.ApplicationName = "AppConnect";
            ApplicationContext.Current.TenantId        = tenantId;
            ApplicationContext.Current.UserId          = appUserAccountInfo.UserId;

            var metaObject = CloudDataHelper.GetMetaObject(tenantId, "AppConnect.AppUser");
            List <ObjectData> objectDatas = new List <ObjectData>();
            ObjectData        objectData  = new ObjectData(metaObject);

            objectData.ID                 = Guid.NewGuid();
            objectData.CreatedBy          = appUserAccountInfo.UserId;
            objectData.CreatedTime        = DateTime.Now;
            objectData.ModifiedBy         = appUserAccountInfo.UserId;
            objectData.ModifiedTime       = DateTime.Now;
            objectData["StdIsDeleted"]    = false;
            objectData["TenantId"]        = tenantId;
            objectData["UserId"]          = appUserAccountInfo.UserId;
            objectData["UserEmail"]       = appUserAccountInfo.BeisenAccount;
            objectData["State"]           = (int)appUserAccountInfo.State;
            objectData["ActivateTime"]    = DateTime.Now;
            objectData["OpenId"]          = appUserAccountInfo.OpenId;
            objectData["AppId"]           = appUserAccountInfo.AppId;
            objectData["SqlId"]           = sqlId;
            objectData["LoginType"]       = ((int)appUserAccountInfo.Type).ToString();
            objectData["MasterAccountId"] = appUserAccountInfo.MasterAccountId;
            objectDatas.Add(objectData);
            CloudDataHelper.Add(metaObject, objectDatas);
        }
        internal static void AddOrUpdateCLoud(int tenantId, int sqlId, AppUserAccountInfo appUserAccountInfo)
        {
            var objectData = IsExistLogin(tenantId, appUserAccountInfo);

            if (objectData != null)
            {
                UpdateCLoud(tenantId, sqlId, objectData, appUserAccountInfo);
            }
            else
            {
                AddCLoud(tenantId, sqlId, appUserAccountInfo);
            }
        }
        /// <summary>
        /// 增加用户账户
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="appUserAccountInfo"></param>
        public int AddOrUpdate(int tenantId, AppUserAccountInfo appUserAccountInfo)
        {
            ArgumentHelper.AssertIsTrue(tenantId > 0, "tenantId is 0");
            ArgumentHelper.AssertNotNull(appUserAccountInfo, "appUserAccountInfo is null");
            ArgumentHelper.AssertNotNullOrEmpty(appUserAccountInfo.AppId, "appUserAccountInfo.appId is null");
            ArgumentHelper.AssertNotNullOrEmpty(appUserAccountInfo.OpenId, "appUserAccountInfo.openId is null");
            ArgumentHelper.AssertIsTrue(appUserAccountInfo.TenantId > 0, "appUserAccountInfo.TenantId is 0");
            ArgumentHelper.AssertIsTrue(appUserAccountInfo.UserId > 0, "appUserAccountInfo.UserId is 0");
            var sqlId = AppUserAccountDao.InsertOrUpdate(tenantId, appUserAccountInfo);

            AppUserAccountDao.AddOrUpdateCLoud(tenantId, sqlId, appUserAccountInfo);
            return(sqlId);
        }
        public void TestAdd()
        {
            var appUserAccountInfo = new AppUserAccountInfo();

            appUserAccountInfo.AppId         = "dingd8afaa8e8eb609cf35c2f4657eb6378f";
            appUserAccountInfo.OpenId        = "manager5176";
            appUserAccountInfo.TenantId      = 100002;
            appUserAccountInfo.UserId        = 112737565;
            appUserAccountInfo.BeisenAccount = "*****@*****.**";
            appUserAccountInfo.Type          = AppUserAccountType.Login;
            appUserAccountInfo.State         = AppUserAccountState.Activated;

            var id = ProviderGateway.AppUserAccountProvider.AddOrUpdate(appUserAccountInfo.TenantId, appUserAccountInfo);

            Assert.IsTrue(id > 0);
        }
 /// <summary>
 /// 数据映射
 /// </summary>
 /// <param name="record">记录</param>
 /// <param name="info">实体</param>
 private static void BuildInfo(IRecord record, AppUserAccountInfo info)
 {
     info.Id              = record.Get <int>("Id");
     info.AppId           = record.Get <string>("AppId");
     info.OpenId          = record.Get <string>("OpenId");
     info.TenantId        = record.Get <int>("TenantId");
     info.UserId          = record.Get <int>("UserId");
     info.BeisenAccount   = record.Get <string>("BeisenAccount");
     info.Type            = (AppUserAccountType)record.Get <short>("Type");
     info.State           = (AppUserAccountState)record.Get <short>("State");
     info.MasterAccountId = record.Get <int>("MasterAccountId");
     info.CreateTime      = record.Get <DateTime>("CreateTime");
     info.ModifyTime      = record.Get <DateTime>("ModifyTime");
     info.ActivateTime    = record.GetOrDefault <DateTime?>("ActivateTime", null);
     info.UnbindTime      = record.GetOrDefault <DateTime?>("UnbindTime", null);
 }
        /// <summary>
        /// 增加用户账户
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="appUserAccountInfo"></param>
        internal static int InsertOrUpdate(int tenantId, AppUserAccountInfo appUserAccountInfo)
        {
            var db = Database.GetDatabase(DatabaseName.UserSecurity);
            int id = 0;

            SafeProcedure.ExecuteNonQuery(db, "dbo.AppUserAccount_InsertOrUpdate", parameterMapper =>
            {
                parameterMapper.AddWithValue("@AppId", appUserAccountInfo.AppId);
                parameterMapper.AddWithValue("@OpenId", appUserAccountInfo.OpenId);
                parameterMapper.AddWithValue("@TenantId", appUserAccountInfo.TenantId);
                parameterMapper.AddWithValue("@UserId", appUserAccountInfo.UserId);
                parameterMapper.AddWithValue("@BeisenAccount", appUserAccountInfo.BeisenAccount);
                parameterMapper.AddWithValue("@Type", (short)appUserAccountInfo.Type);
                parameterMapper.AddWithValue("@State", (short)appUserAccountInfo.State);
                parameterMapper.AddWithValue("@MasterAccountId", appUserAccountInfo.MasterAccountId);
                parameterMapper.AddTypedDbNull("@Id", ParameterDirectionWrap.Output, DbType.Int32);
            }, o =>
            {
                id = (int)o.GetValue("@Id");
            });
            return(id);
        }
示例#9
0
        private static Dictionary <int, List <AppUserAccountInfo> > GetAppUserAccountInSql()
        {
            Dictionary <int, List <AppUserAccountInfo> > appUserAccountInfoDic = new Dictionary <int, List <AppUserAccountInfo> >();
            Database database = Database.GetDatabase("BeisenUserSecurity");

            SafeProcedure.ExecuteAndGetInstanceList(database, "[dbo].[AppUserAccount_GetAll]",
                                                    delegate(IRecord record, int entity)
            {
                AppUserAccountInfo appUserAccountInfo = new AppUserAccountInfo();
                appUserAccountInfo.Id              = record.GetOrDefault <int>("Id", 0);
                appUserAccountInfo.AppId           = record.GetOrDefault <string>("AppId", "");
                appUserAccountInfo.OpenId          = record.GetOrDefault <string>("OpenId", "");
                appUserAccountInfo.TenantId        = record.GetOrDefault <int>("TenantId", 0);
                appUserAccountInfo.UserId          = record.GetOrDefault <int>("UserId", 0);
                appUserAccountInfo.BeisenAccount   = record.GetOrDefault <string>("BeisenAccount", "");
                appUserAccountInfo.TypeNotEnum     = record.GetOrDefault <Int16>("Type", 0);
                appUserAccountInfo.StateNotEnum    = record.GetOrDefault <Int16>("State", 0);
                appUserAccountInfo.CreateTime      = record.GetOrDefault <DateTime>("CreateTime", DateTime.Now);
                appUserAccountInfo.ActivateTime    = record.GetOrDefault <DateTime>("ActivateTime", appUserAccountInfo.CreateTime);
                appUserAccountInfo.UnbindTime      = record.GetOrDefault <DateTime>("UnbindTime", DateTime.Now);
                appUserAccountInfo.MasterAccountId = record.GetOrDefault <int>("MasterAccountId", 0);

                if (appUserAccountInfoDic.ContainsKey(appUserAccountInfo.TenantId))
                {
                    var existList = appUserAccountInfoDic[appUserAccountInfo.TenantId];
                    existList.Add(appUserAccountInfo);
                    appUserAccountInfoDic[appUserAccountInfo.TenantId] = existList;
                }
                else
                {
                    appUserAccountInfoDic.Add(appUserAccountInfo.TenantId, new List <AppUserAccountInfo> {
                        appUserAccountInfo
                    });
                }
            });

            return(appUserAccountInfoDic);
        }
        public BindResult Bind(Dictionary <string, string> openIds, string batch, string userName, string password, string captcha)
        {
            var result = new BindResult
            {
                NeedCaptcha = false
            };

            var callback         = ProviderGateway.CallbackContentProvider.GetByBatchId(batch);
            var appAccountPublic = ProviderGateway.AppAccountProvider.Get(callback.AppAccountPublic);

            if (!openIds.ContainsKey(appAccountPublic.AppId))
            {
                result.Result  = 2;
                result.Message = "用户公有OpenId无效";
                return(result);
            }
            AppAccountInfo appAccountPrivate = null;

            if (callback.TenantId != 0 && !string.IsNullOrEmpty(callback.AppAccountPrivate))
            {
                appAccountPrivate = ProviderGateway.AppAccountProvider.Get(callback.AppAccountPrivate);
                if (!openIds.ContainsKey(appAccountPrivate.AppId))
                {
                    result.Result  = 2;
                    result.Message = "用户私有OpenId无效";
                    return(result);
                }
            }
            var openIdPublic = openIds[appAccountPublic.AppId];

            var currentAppUserAccount = ProviderGateway.AppUserAccountProvider.GetByOpenId(appAccountPublic.AppId, openIdPublic);

            if (currentAppUserAccount != null && currentAppUserAccount.State == AppUserAccountState.Activated)
            {
                result.Result  = 8;
                result.Message = "您已经绑定过了,无需重复绑定";
                return(result);
            }

            //验证绑定时间
            //if (RedisHelper.IsExist(RedisConstName.MobileCheck + userName))
            //{
            //    result.Result = 6;
            //    result.Message = "绑定过于频繁";
            //    return result;
            //}

            var users = ProviderGateway.StaffProvider.GetByUserName(userName);

            if (users == null || users.Count <= 0)
            {
                result.Result  = 5;
                result.Message = "未找到对应账户";
                return(result);
            }

            var userId   = users.First().Key;
            var tenantId = Proxy.BeisenUserProxy.GetTenantId(userId);
            //判断用户是否已经绑定
            var oldAppUserAccount = ProviderGateway.AppUserAccountProvider.GetByUserId(tenantId, userId, appAccountPublic.AppId);

            if (oldAppUserAccount != null && oldAppUserAccount.State == AppUserAccountState.Activated)
            {
                result.Result  = 7;
                result.Message = "帐号已绑定";
                return(result);
            }

            var newAppUserAccountMaster = new AppUserAccountInfo
            {
                AppId           = appAccountPublic.AppId,
                OpenId          = openIdPublic,
                TenantId        = tenantId,
                UserId          = userId,
                BeisenAccount   = userName,
                Type            = _type,
                State           = AppUserAccountState.Activated,
                MasterAccountId = 0
            };
            var masterAccountId = ProviderGateway.AppUserAccountProvider.AddOrUpdate(tenantId, newAppUserAccountMaster);

            //增加私有关联关系
            if ((appAccountPublic.Type == 11 || appAccountPublic.Type == 12) && callback.TenantId != 0 && masterAccountId != 0 && !string.IsNullOrEmpty(callback.AppAccountPrivate))
            {
                var newAppAccountUser = new AppUserAccountInfo
                {
                    AppId           = appAccountPrivate.AppId,
                    OpenId          = openIds[appAccountPrivate.AppId],
                    TenantId        = tenantId,
                    UserId          = userId,
                    BeisenAccount   = userName,
                    Type            = _type,
                    State           = AppUserAccountState.Activated,
                    MasterAccountId = masterAccountId
                };
                ProviderGateway.AppUserAccountProvider.AddOrUpdate(tenantId, newAppAccountUser);
            }

            result.RedirectUrl = callback.Content;
            //RedisHelper.SetRedis(RedisConstName.MobileCheck + userName, DateTime.Now.Ticks.ToString(), 300);
            return(result);
        }
示例#11
0
        public BindResult Bind(Dictionary <string, string> openIds, string batch, string userName, string password, string captcha)
        {
            var result = new BindResult
            {
                NeedCaptcha = false
            };

            var callback         = ProviderGateway.CallbackContentProvider.GetByBatchId(batch);
            var appAccountPublic = ProviderGateway.AppAccountProvider.Get(callback.AppAccountPublic);

            if (!openIds.ContainsKey(appAccountPublic.AppId))
            {
                result.Result  = 2;
                result.Message = "用户公有OpenId无效";
                return(result);
            }
            AppAccountInfo appAccountPrivate = null;

            if (callback.TenantId != 0)
            {
                appAccountPrivate = ProviderGateway.AppAccountProvider.Get(callback.AppAccountPrivate);
                if (!openIds.ContainsKey(appAccountPrivate.AppId))
                {
                    result.Result  = 2;
                    result.Message = "用户私有OpenId无效";
                    return(result);
                }
            }
            var openIdPublic = openIds[appAccountPublic.AppId];

            var currentAppUserAccount = ProviderGateway.AppUserAccountProvider.GetByOpenId(appAccountPublic.AppId, openIdPublic);

            if (currentAppUserAccount != null && currentAppUserAccount.State == AppUserAccountState.Activated)
            {
                result.Result  = 8;
                result.Message = "您已经绑定过了,无需重复绑定";
                return(result);
            }

            //验证发送时间
            if (RedisHelper.IsExist(RedisConstName.SendCheck + userName))
            {
                result.Result  = 6;
                result.Message = "绑定过于频繁";
                return(result);
            }

            // 校验邮箱是否存在
            var userId = Proxy.BeisenUserProxy.GetSecurityByUserName(userName);

            if (userId <= 0)
            {
                result.Result  = 5;
                result.Message = "未找到对应账户";
                return(result);
            }
            var tenantId = Proxy.BeisenUserProxy.GetTenantId(userId);

            var oldAppUserAccount = ProviderGateway.AppUserAccountProvider.GetByUserId(tenantId, userId, appAccountPublic.AppId);

            if (oldAppUserAccount != null && oldAppUserAccount.State == AppUserAccountState.Activated)
            {
                result.Result  = 7;
                result.Message = "帐号已绑定";
                return(result);
            }

            var newAppUserAccountMaster = new AppUserAccountInfo
            {
                AppId           = appAccountPublic.AppId,
                OpenId          = openIdPublic,
                TenantId        = tenantId,
                UserId          = userId,
                BeisenAccount   = userName,
                Type            = _type,
                State           = AppUserAccountState.Inactive,
                MasterAccountId = 0
            };
            var masterAccountId = ProviderGateway.AppUserAccountProvider.AddOrUpdate(tenantId, newAppUserAccountMaster);

            //增加私有关联关系
            if ((appAccountPublic.Type == 11 || appAccountPublic.Type == 12) && callback.TenantId != 0 && masterAccountId != 0)
            {
                var newAppAccountUser = new AppUserAccountInfo
                {
                    AppId           = appAccountPrivate.AppId,
                    OpenId          = openIds[appAccountPrivate.AppId],
                    TenantId        = tenantId,
                    UserId          = userId,
                    BeisenAccount   = userName,
                    Type            = _type,
                    State           = AppUserAccountState.Inactive,
                    MasterAccountId = masterAccountId
                };
                ProviderGateway.AppUserAccountProvider.AddOrUpdate(tenantId, newAppAccountUser);
            }
            // 记录发邮件记录
            var bindBatch = new BindBatchInfo
            {
                TenantId         = tenantId,
                AppUserAccountId = masterAccountId,
                BeisenAccount    = userName,
                Type             = _type,
                State            = BindBatchState.UnUse
            };
            var bindBatchId = ProviderGateway.BindBatchProvider.Add(tenantId, bindBatch);

            // 发送激活邮件
            string activateCode = CryptographyHelper.AESEncrypt(tenantId + "_" + bindBatchId);
            string emailBody    = GetEmailBody(userName, AppConnectHostConfig.Cache[0] + HostConst.UserActivate + "?code=" + activateCode);
            var    emailBatch   = EmailProxy.SendEmail(0, "iTalent登录邮件验证", "", userName, emailBody);

            RedisHelper.SetRedis(RedisConstName.SendCheck + userName, DateTime.Now.Ticks.ToString(), 180);
            ProviderGateway.BindBatchProvider.UpdateBatchId(tenantId, bindBatchId, emailBatch);

            return(result);
        }
        /// <summary>
        /// 校验用户身份,并返回绑定Url
        /// </summary>
        /// <param name="appAccountId"></param>
        /// <param name="redirectUrl"></param>
        /// <param name="type"></param>
        /// <param name="cookie"></param>
        /// <returns>
        /// null:用户身份存在且状态正常
        /// 非null:返回绑定Url,直接跳转
        /// </returns>
        public string GetIdentityUrl(string appAccountId, string redirectUrl, int type, UserCookie cookie, CallbackContentState state = CallbackContentState.Bind)
        {
            ArgumentHelper.AssertIsTrue(!string.IsNullOrWhiteSpace(redirectUrl), "redirectUrl is null or empty");

            AppAccountInfo     appAccountPublic;
            AppAccountInfo     appAccountPrivate = null;
            var                tenantId          = 0;
            AppUserAccountInfo appUserAccountMaster;
            AppUserAccountInfo appUserAccount;
            string             appAccountPublicId;

            //根据类型初始化信息
            if (string.IsNullOrWhiteSpace(appAccountId))
            {
                //公共账户方式
                appAccountPublic     = ProviderGateway.AppAccountProvider.GetPublicByType(type);
                appUserAccountMaster = ProviderGateway.AppUserAccountProvider.GetByOpenId(appAccountPublic.AppId, cookie.OpenIds[appAccountPublic.AppId]);
                appAccountPublicId   = appAccountPublic.AppAccountId;

                if (appUserAccountMaster != null && appUserAccountMaster.State == AppUserAccountState.Activated)
                {
                    cookie.AccountAppId  = appAccountPublic.AppId;
                    cookie.AccountOpenId = cookie.OpenIds[appAccountPublic.AppId];
                    return(null);
                }
            }
            else
            {
                //私有账户方式
                appAccountPrivate = ProviderGateway.AppAccountProvider.Get(appAccountId);
                tenantId          = appAccountPrivate.TenantId;

                switch (appAccountPrivate.Type)
                {
                case 11:
                case 12:
                    appAccountPublic     = ProviderGateway.AppAccountProvider.GetPublicByType(appAccountPrivate.Type);
                    appUserAccountMaster = ProviderGateway.AppUserAccountProvider.GetByOpenId(appAccountPublic.AppId, cookie.OpenIds[appAccountPublic.AppId]);
                    appUserAccount       = ProviderGateway.AppUserAccountProvider.GetByOpenId(appAccountPrivate.AppId, cookie.OpenIds[appAccountPrivate.AppId]);
                    appAccountPublicId   = appAccountPublic.AppAccountId;

                    if (appUserAccountMaster == null)
                    {
                        if (appUserAccount != null)
                        {
                            //如果与其他账户冲突
                            var appUserAccoutTemp = ProviderGateway.AppUserAccountProvider.GetByUserId(appUserAccount.TenantId, appUserAccount.UserId, appAccountPublic.AppId);
                            if (appUserAccoutTemp == null)
                            {
                                //补充主账户
                                var appUserAccountMasterNew = new AppUserAccountInfo();
                                appUserAccountMasterNew.AppId           = appAccountPublic.AppId;
                                appUserAccountMasterNew.OpenId          = cookie.OpenIds[appAccountPublic.AppId];
                                appUserAccountMasterNew.TenantId        = appUserAccount.TenantId;
                                appUserAccountMasterNew.UserId          = appUserAccount.UserId;
                                appUserAccountMasterNew.BeisenAccount   = BeisenUserProxy.GetUserEmail(appUserAccount.UserId);
                                appUserAccountMasterNew.Type            = AppUserAccountType.Email;
                                appUserAccountMasterNew.State           = AppUserAccountState.Activated;
                                appUserAccountMasterNew.MasterAccountId = 0;
                                var appUserAccountMasterNewId = ProviderGateway.AppUserAccountProvider.AddOrUpdate(appUserAccountMasterNew.TenantId, appUserAccountMasterNew);
                                ProviderGateway.AppUserAccountProvider.UpdateMasterAccountId(appUserAccount.Id, appUserAccountMasterNewId);

                                cookie.AccountAppId  = appAccountPublic.AppId;
                                cookie.AccountOpenId = cookie.OpenIds[appAccountPublic.AppId];

                                return(null);
                            }
                        }
                    }
                    else if (appUserAccountMaster.State == AppUserAccountState.Activated)
                    {
                        if (appUserAccount == null)
                        {
                            //补充账户信息
                            var appUserAccountNew = new AppUserAccountInfo();
                            appUserAccountNew.AppId           = appAccountPrivate.AppId;
                            appUserAccountNew.OpenId          = cookie.OpenIds[appAccountPrivate.AppId];
                            appUserAccountNew.TenantId        = appUserAccountMaster.TenantId;
                            appUserAccountNew.UserId          = appUserAccountMaster.UserId;
                            appUserAccountNew.BeisenAccount   = appUserAccountMaster.BeisenAccount;
                            appUserAccountNew.Type            = appUserAccountMaster.Type;
                            appUserAccountNew.State           = appUserAccountMaster.State;
                            appUserAccountNew.MasterAccountId = appUserAccountMaster.Id;
                            ProviderGateway.AppUserAccountProvider.AddOrUpdate(appUserAccountNew.TenantId, appUserAccountNew);
                        }
                        else if (appUserAccount.MasterAccountId != appUserAccountMaster.Id)
                        {
                            //更新MasterId
                            ProviderGateway.AppUserAccountProvider.UpdateMasterAccountId(appUserAccount.Id, appUserAccountMaster.Id);
                        }
                        cookie.AccountAppId  = appAccountPublic.AppId;
                        cookie.AccountOpenId = cookie.OpenIds[appAccountPublic.AppId];
                        return(null);
                    }
                    break;

                default:
                    appUserAccountMaster = ProviderGateway.AppUserAccountProvider.GetByOpenId(appAccountPrivate.AppId, cookie.OpenIds[appAccountPrivate.AppId]);
                    appAccountPublicId   = appAccountPrivate.AppAccountId;
                    if (appUserAccountMaster != null && appUserAccountMaster.State == AppUserAccountState.Activated)
                    {
                        cookie.AccountAppId  = appAccountPrivate.AppId;
                        cookie.AccountOpenId = cookie.OpenIds[appAccountPrivate.AppId];
                        return(null);
                    }
                    break;
                }
            }
            //记录回调信息
            var batchId         = Guid.NewGuid().ToString();
            var callbackContent = new CallbackContentInfo
            {
                BatchId           = batchId,
                TenantId          = tenantId,
                AppAccountPublic  = appAccountPublicId,
                AppAccountPrivate = appAccountPrivate == null ? null : appAccountPrivate.AppAccountId,
                Content           = redirectUrl,
                State             = state
            };

            ProviderGateway.CallbackContentProvider.Add(callbackContent);

            if (state == CallbackContentState.Bind)
            {
                return(UrlHelper.AddParameter(HostConst.UserBind, "batch", batchId));
            }
            else
            {
                var parameter = redirectUrl.Split('?');
                var query     = parameter.Length > 0 ? string.Format("{0}&batch={1}", parameter[1], batchId) : string.Empty;
                return(UrlHelper.AddQuery(HostConst.RegisterBind, query));
            }
        }
示例#13
0
        internal void BatchHandleExcelData(int tenantId, int userId, ISheet staffSheet, string appId, bool isAsync)
        {
            List <AppUserAccountInfo> appUserAccountInfoList = new List <AppUserAccountInfo>();

            Dictionary <string, string> emailDic  = new Dictionary <string, string>();
            Dictionary <string, string> mobileDic = new Dictionary <string, string>();
            //将excel数据 转换成datatable,接着转换成Dictionary
            var dataTable = ExcelService.Instance.ExcelToDataTable(staffSheet);

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                var openId = Convert.ToString(dataTable.Rows[i][0]);
                var email  = Convert.ToString(dataTable.Rows[i][1]);
                var mobile = Convert.ToString(dataTable.Rows[i][2]);

                if (!string.IsNullOrEmpty(email))
                {
                    emailDic.Add(email, openId);
                }
                else
                {
                    if (!string.IsNullOrEmpty(mobile))
                    {
                        mobileDic.Add(mobile, openId);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            IEnumerable <string> emailList  = emailDic.Select(t => t.Key);
            IEnumerable <string> mobileList = mobileDic.Select(t => t.Key);
            var emailResult  = GetUserByEmail(tenantId, userId, emailList);
            var mobileResult = GetUserByMobile(tenantId, userId, mobileList);

            foreach (var emailItem in emailResult)
            {
                AppUserAccountInfo userInfo = new AppUserAccountInfo()
                {
                    AppId         = appId,
                    OpenId        = emailDic[emailItem.Key],
                    TenantId      = emailItem.Value.TenantId,
                    UserId        = emailItem.Value.UserId,
                    BeisenAccount = emailItem.Value.Email,
                    Type          = AppUserAccountType.Batch,
                    State         = AppUserAccountState.Activated,
                    CreateTime    = DateTime.Now,
                    ModifyTime    = DateTime.Now,
                    ActivateTime  = DateTime.Now
                };
                appUserAccountInfoList.Add(userInfo);
            }
            foreach (var mobileItem in mobileResult)
            {
                AppUserAccountInfo userInfo = new AppUserAccountInfo()
                {
                    AppId         = appId,
                    OpenId        = mobileDic[mobileItem.Key],
                    TenantId      = mobileItem.Value.TenantId,
                    UserId        = mobileItem.Value.UserId,
                    BeisenAccount = mobileItem.Value.Mobile,
                    Type          = AppUserAccountType.Batch,
                    State         = AppUserAccountState.Activated,
                    CreateTime    = DateTime.Now,
                    ModifyTime    = DateTime.Now,
                    ActivateTime  = DateTime.Now
                };
                appUserAccountInfoList.Add(userInfo);
            }

            foreach (var user in appUserAccountInfoList)
            {
                var rest = ProviderGateway.AppUserAccountProvider.AddOrUpdate(tenantId, user);
                if (rest <= 0)
                {
                    AppConnectLogHelper.ErrorFormat("执行AddOrUpdate失败:tenantId:{0},userInfo:{1}", tenantId, Newtonsoft.Json.JsonConvert.SerializeObject(user));
                }
            }

            if (isAsync)
            {
                TitaMessageHelper.SendMessage(tenantId, userId, "导入数据成功");
            }
        }
 internal static void UpdateCLoud(int tenantId, int sqlId, ObjectData objectData, AppUserAccountInfo appUserAccountInfo)
 {
     ApplicationContext.Current.ApplicationName = "AppConnect";
     ApplicationContext.Current.TenantId        = tenantId;
     ApplicationContext.Current.UserId          = appUserAccountInfo.UserId;
     objectData["AppId"]           = appUserAccountInfo.AppId;
     objectData["OpenId"]          = appUserAccountInfo.OpenId;
     objectData["UserId"]          = appUserAccountInfo.UserId;
     objectData["UserEmail"]       = appUserAccountInfo.BeisenAccount;
     objectData["State"]           = (int)appUserAccountInfo.State;
     objectData["LoginType"]       = ((int)appUserAccountInfo.Type).ToString();
     objectData["ActivateTime"]    = DateTime.Now;
     objectData["MasterAccountId"] = appUserAccountInfo.MasterAccountId;
     objectData["SqlId"]           = sqlId;
     objectData.ModifiedBy         = appUserAccountInfo.UserId;
     objectData.ModifiedTime       = DateTime.Now;
     CloudDataHelper.Update(objectData);
 }