Ejemplo n.º 1
0
        /// <summary>
        /// 域的身份认证
        /// </summary>
        /// <param name="domainCode"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static JsonModel<string> DomainIdentityAuth(string domainCode, string password)
        {
            JsonModel<string> jsonModel = new JsonModel<string>()
            {
                Success = false,
                ErrMsg = "域拥有者身份认证不通过",
                SuccessMsg = "域拥有者身份认证通过"
            };
            IDomainDal domainDal = new DomainDal();
            var domain = domainDal.GetEntity(new DomainSingleParam() { DomainCode = domainCode });
            if (domainCode == null)
            {
                jsonModel.ErrMsg = "域不存在";
            }
            if (string.IsNullOrEmpty(domainCode) || string.IsNullOrEmpty(password))
            {
                jsonModel.ErrMsg = "域标识不正确或者域密码不正确";
                return jsonModel;
            }

            string inputEncrypt = EncryptDomainPassword(password, domain.DomainCode, domain.DomainKey);
            if (!inputEncrypt.Trim().Equals(domain.DomainPassword.Trim()))
            {
                jsonModel.ErrMsg = "密码不正确";
            }
            jsonModel.Success = true;
            return jsonModel;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 判断是否有domainCode参数,并且判断domainCode是否合法
 /// </summary>
 /// <param name="domainCode"></param>
 /// <returns></returns>
 public static bool HasDomainCode()
 {
     var domainCode = HttpContext.Current.Request["domainCode"];
     if (!string.IsNullOrEmpty(domainCode))
     {
         string code = DotNet.Utils.Untility.StringHelper.FilterHtml(domainCode);
         IDomainDal domainDal = new DomainDal();
         var domain = domainDal.GetEntity(new DomainSingleParam() { DomainCode = code });
         if (domain != null && domain.DomainId > 0)
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 添加一个单点登录池
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public JsonModel<string> AddSSOPool(SSOPoolAddModel model)
 {
     JsonModel<string> jsonModel = new JsonModel<string>()
     {
         Success = false,
         SuccessMsg = "添加成功",
         ErrMsg = "添加失败"
     };
     //对实体进行验证
     var validate = DotNet.Utils.DataValidate.ValidateHelper<SSOPoolAddModel>.ValidateModel(model);
     if (!validate.Pass)
     {
         jsonModel.ErrMsg = validate.ResultList.FirstOrDefault().ErrorMessage;
         return jsonModel;
     }
     //字符过滤
     model.ReMark = DotNet.Utils.Untility.StringHelper.FilterHtml(model.ReMark);
     //判断主域是否存在
     IDomainDal domainDal = new DomainDal();
     if (model.MainDomainId > 0)
     {
         var domain = domainDal.GetEntity(model.MainDomainId);
         if (domain == null)
         {
             jsonModel.ErrMsg = "主域不存在";
             return jsonModel;
         }
     }
     //构建实体
     SSOPool pool = new SSOPool()
     {
         PoolName = model.PoolName,
         IsEnabled = model.IsEnabled,
         MaxAmount = model.MaxAmount,
         MainDomainId = model.MainDomainId,
         DelFlag = (int)DelFlagEnum.Noraml,
         ReMark = model.ReMark
     };
     ISSOPoolDal ssoPoolDal = new SSOPoolDal();
     var r = ssoPoolDal.AddEntity(pool);
     if (r != null)
     {
         jsonModel.Success = true;
     }
     return jsonModel;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 查询需要修改的域实体
 /// </summary>
 /// <param name="domainId"></param>
 /// <returns></returns>
 public DomainEditModel GetEditModel(int domainId)
 {
     IDomainDal domainDal = new DomainDal();
     DomainEditModel editModel = new DomainEditModel();
     var domain = domainDal.GetEntity(domainId);
     if (domain != null)
     {
         editModel = new DomainEditModel()
        {
            DomainId = domain.DomainId,
            DomainName = domain.DomainName,
            //DomainPassword=BllUtility.DomainHandler.DecryptDomainPassword(domain.DomainPassword,domain.DomainCode,domain.DomainKey),
            DomainUrl = domain.DomainUrl,
            DomainLevel = domain.DomainLevel,
            IsEnabled = domain.IsEnabled,
            IsSSO = domain.IsSSO,
            SSOUrl = domain.SSOUrl,
            CookieDomain = domain.CookieDomain,
            ParentDomainId = domain.ParentDomainId,
            ReMark = domain.ReMark,
            SSOPoolPoolId = domain.SSOPoolPoolId
        };
     }
     return editModel;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 根据唯一参数查询域
 /// </summary>
 /// <param name="domainId"></param>
 /// <returns></returns>
 public Domain GetDomain(DomainSingleParam parameter)
 {
     IDomainDal domainDal = new DomainDal();
     //过滤
     parameter.DomainCode = DotNet.Utils.Untility.StringHelper.FilterHtml(parameter.DomainCode);
     var domain = domainDal.GetEntity(parameter);
     return domain;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 修改域
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonModel<Domain> EditDomain(DomainEditModel model)
        {
            JsonModel<Domain> jsonModel = new JsonModel<Domain>()
            {
                Success = false,
                ErrMsg = "修改失败",
                SuccessMsg = "修改成功"
            };
            //对实体进行验证
            var validate = DotNet.Utils.DataValidate.ValidateHelper<DomainEditModel>.ValidateModel(model);
            if (!validate.Pass)
            {
                jsonModel.ErrMsg = validate.ResultList.FirstOrDefault().ErrorMessage;
                return jsonModel;
            }
            //字符过滤
            model.ReMark = DotNet.Utils.Untility.StringHelper.FilterHtml(model.ReMark);
            IDomainDal domainDal = new DomainDal();
            var dbDomain = domainDal.GetEntity(model.DomainId);
            if (dbDomain == null)
            {
                jsonModel.ErrMsg = "当前域不存在";
                return jsonModel;
            }
            //先判断当前域的级别,如果为1级,则没有上一级,否则,就检测上一级是否存在
            if (model.DomainLevel > 1)
            {
                var parentDomain = domainDal.GetEntity(model.ParentDomainId);
                if (parentDomain == null)
                {
                    jsonModel.ErrMsg = "父域不存在";
                    return jsonModel;
                }
            }
            else
            {
                model.DomainLevel = 1;
                model.ParentDomainId = 0;
            }
            int oldPoolId = dbDomain.SSOPoolPoolId;
            //检测单点登录池是否存在
            ISSOPoolDal ssoPoolDal = new SSOPoolDal();
            var pool = ssoPoolDal.GetEntity(model.SSOPoolPoolId);
            if (pool == null)
            {
                jsonModel.ErrMsg = "你选择的单点登录池不存在";
                return jsonModel;
            }

            #region 生成修改的属性
            //域密码
            //string encryptPassword = BllUtility.DomainHandler.EncryptDomainPassword(model.DomainPassword,dbDomain.DomainCode,dbDomain.DomainKey);

            dbDomain.DomainName = model.DomainName;
            dbDomain.DomainUrl = model.DomainUrl;
            dbDomain.DomainLevel = model.DomainLevel;
            dbDomain.ParentDomainId = model.ParentDomainId;
            dbDomain.CookieDomain = model.CookieDomain;
            dbDomain.IsEnabled = model.IsEnabled;
            dbDomain.IsSSO = model.IsSSO;
            dbDomain.SSOUrl = model.SSOUrl;
            dbDomain.ReMark = model.ReMark;
            dbDomain.SSOPoolPoolId = model.SSOPoolPoolId;
            //   dbDomain.DomainPassword = encryptPassword;
            #endregion

            var r = domainDal.UpdateEntity(dbDomain);
            if (r != null && r.DomainId > 0)
            {
                jsonModel.Success = true;
                jsonModel.Data = r;
            }
            //最后,判断是否修改了池子
            if (oldPoolId != dbDomain.SSOPoolPoolId)
            {
                //判断池子的主域是否是这个
                if (pool.MainDomainId == oldPoolId)
                {
                    pool.MainDomainId = 0;
                    ssoPoolDal.UpdateEntity(pool);
                }
            }
            return jsonModel;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 删除域
        /// </summary>
        /// <param name="domainId"></param>
        /// <returns></returns>
        public JsonModel<string> DeleteDomain(int domainId)
        {
            JsonModel<string> jsonModel = new JsonModel<string>()
            {
                Success = false,
                ErrMsg = "删除失败",
                SuccessMsg = "删除成功"
            };

            IDomainDal domainDal = new DomainDal();
            var domain = domainDal.GetEntity(domainId);
            if (domain == null)
            {
                jsonModel.ErrMsg = "该域不存在";
                return jsonModel;
            }
            domain.DelFlag = (int)DelFlagEnum.LogicalDelete;
            var r = domainDal.UpdateEntity(domain);
            if (r != null && r.DomainId > 0)
            {
                jsonModel.Success = true;
            }
            return jsonModel;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 开启或者关闭域
 /// </summary>
 /// <param name="domainId"></param>
 /// <param name="isEnabled"></param>
 /// <returns></returns>
 public JsonModel<string> ChangeDomainEnabled(int domainId, int isEnabled)
 {
     JsonModel<string> jsonModel = new JsonModel<string>()
     {
         Success = false,
         ErrMsg = "操作失败",
         SuccessMsg = "操作成功"
     };
     IDomainDal domainDal = new DomainDal();
     var domain = domainDal.GetEntity(domainId);
     if (domain == null || domain.DomainId == 0)
     {
         jsonModel.ErrMsg = "当前域不存在";
         return jsonModel;
     }
     if (!Enum.IsDefined(typeof(IsEnabledEnum), isEnabled))
     {
         jsonModel.ErrMsg = "域的状态不正确";
         return jsonModel;
     }
     domain.IsEnabled = isEnabled;
     var r = domainDal.UpdateEntity(domain);
     if (r != null && r.DomainId > 0)
     {
         jsonModel.Success = true;
     }
     return jsonModel;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 根据当前域的等级和父级Id获取当前域的真实等级
 /// </summary>
 /// <param name="level"></param>
 /// <param name="parentDomainId"></param>
 public static void GetDomainLevel(ref int level, ref int parentDomainId)
 {
     IDomainDal domainDal = new DomainDal();
     //获取当前域的等级,需要先判断上一级的域是否存在
     var parentDomain = domainDal.GetEntity(parentDomainId);
     if (parentDomain != null && parentDomain.DomainId > 0)
     {
         parentDomainId = parentDomain.DomainId;
         level = parentDomain.DomainLevel + 1;
     }
     else
     {
         parentDomainId = 0;
         level = 1;
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 修改单点登录池
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonModel<string> EditSSOPool(SSOPoolEditModel model)
        {
            JsonModel<string> jsonModel = new JsonModel<string>()
            {
                Success = false,
                SuccessMsg = "修改成功",
                ErrMsg = "修改失败"
            };

            //对实体进行验证
            var validate = DotNet.Utils.DataValidate.ValidateHelper<SSOPoolEditModel>.ValidateModel(model);
            if (!validate.Pass)
            {
                jsonModel.ErrMsg = validate.ResultList.FirstOrDefault().ErrorMessage;
                return jsonModel;
            }
            //字符过滤
            model.ReMark = DotNet.Utils.Untility.StringHelper.FilterHtml(model.ReMark);
            IDomainDal domainDal = new DomainDal();
            //检测选择的主要验证域是否正确
            if (model.MainDomainId > 0)
            {
                var domain = domainDal.GetEntity(model.MainDomainId);
                if (domain == null || domain.SSOPoolPoolId != model.PoolId)
                {
                    jsonModel.ErrMsg = "您选择的主要验证域不正确";
                    return jsonModel;
                }
            }
            //查看最大的域数量是否超出限制
            var poolDomainCount = domainDal.GetPoolDomain(model.PoolId).Count;
            if (poolDomainCount > model.MaxAmount)
            {
                jsonModel.ErrMsg = string.Format("您输入的最大域数量不正确,应大于{0}", poolDomainCount);
                return jsonModel;
            }

            ISSOPoolDal ssoPoolDal = new SSOPoolDal();
            var dbPool = ssoPoolDal.GetEntity(model.PoolId);
            if (dbPool != null)
            {
                dbPool.PoolName = model.PoolName;
                dbPool.MainDomainId = model.MainDomainId;
                dbPool.IsEnabled = model.IsEnabled;
                dbPool.MaxAmount = model.MaxAmount;
                dbPool.ReMark = model.ReMark;
            }
            var r = ssoPoolDal.UpdateEntity(dbPool);
            if (r != null && r.PoolId > 0)
            {
                jsonModel.Success = true;
            }

            return jsonModel;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 添加单点登录的帐号
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonModel<Account> AddAccount(AccountAddModel model)
        {
            JsonModel<Account> jsonModel = new JsonModel<Account>()
            {
                Success = false,
                ErrMsg = "添加失败",
                SuccessMsg = "添加成功"
            };
            try
            {
                //对实体进行验证
                var validate = DotNet.Utils.DataValidate.ValidateHelper<AccountAddModel>.ValidateModel(model);
                if (!validate.Pass)
                {
                    jsonModel.ErrMsg = validate.ResultList.FirstOrDefault().ErrorMessage;
                    return jsonModel;
                }
                //过滤
                model.LoginName = DotNet.Utils.Untility.StringHelper.FilterHtml(model.LoginName);
                model.Mobile = DotNet.Utils.Untility.StringHelper.FilterHtml(model.Mobile);
                model.LoginName = DotNet.Utils.Untility.StringHelper.FilterHtml(model.LoginName);

                #region 验证
                if (!BllUtility.AccountHandler.VerifyOnly(new AccountSingleParam() { LoginName = model.LoginName }))
                {
                    jsonModel.ErrMsg = "用户名已经存在";
                    return jsonModel;
                };
                //验证Mobile
                int mobileBinding = (int)BindingEnum.NotBinded;
                if (!string.IsNullOrEmpty(model.Mobile))
                {
                    if (!DotNet.Utils.Untility.RegexValidate.IsMobileNumber(model.Mobile))
                    {
                        jsonModel.ErrMsg = "手机号码格式不正确";
                        return jsonModel;
                    }
                    mobileBinding=(int)BindingEnum.Binded;
                    if (!BllUtility.AccountHandler.VerifyOnly(new AccountSingleParam() { Mobile = model.Mobile }))
                    {
                        jsonModel.ErrMsg = "手机号码已经存在";
                        return jsonModel;
                    };
                }
                //验证Email
                 int emailBinding = (int)BindingEnum.NotBinded;
                if (!string.IsNullOrEmpty(model.Email))
                {
                    if (!DotNet.Utils.Untility.RegexValidate.IsEmailAddress(model.Email))
                    {
                        jsonModel.ErrMsg = "Email格式不正确";
                        return jsonModel;
                    }
                    emailBinding=(int)BindingEnum.Binded;
                    if (!BllUtility.AccountHandler.VerifyOnly(new AccountSingleParam() { Email = model.Email }))
                    {
                        jsonModel.ErrMsg = "邮箱已经存在";
                        return jsonModel;
                    };
                }

                //验证安全密码
                int safeBinding = (int)BindingEnum.NotBinded;
                if (!string.IsNullOrEmpty(model.SafePassword))
                {
                    if (!DotNet.Utils.Untility.RegexValidate.IsPasswordOne(model.SafePassword, 6, 25))
                    {
                        jsonModel.ErrMsg = "安全密码格式不正确";
                        return jsonModel;
                    }
                    model.SafePassword = BllUtility.AccountHandler.EncryptSafePassword(model.SafePassword);
                    safeBinding = (int)BindingEnum.Binded;
                }

                //验证提交的域是否存在
                IDomainDal domainDal = new DomainDal();
                var domain = domainDal.GetEntity(new DomainSingleParam() { DomainCode=model.SubmitDomainCode });
                if (domain == null || domain.DomainId <= 0)
                {
                    jsonModel.ErrMsg = "域不存在";
                    return jsonModel;
                }
                #endregion

                string openId = BllUtility.AccountHandler.CreateOpenId();
                string encryptKey = BllUtility.AccountHandler.CreateEncryptKey();
                string encryptPassword = BllUtility.AccountHandler.EncryptPassword(openId, model.Password, encryptKey);
                string mobile = string.IsNullOrEmpty(model.Mobile) ? "" : model.Mobile;
                string email = string.IsNullOrEmpty(model.Email) ? "" : model.Email;
                string safePassword = string.IsNullOrEmpty(model.SafePassword) ? "" : model.SafePassword;
                Account account = new Account()
                {
                    OpenId = openId,
                    LoginName = model.LoginName,
                    EncryptKey = encryptKey,
                    Password = encryptPassword,
                    Mobile = mobile,
                    MobileBinding = mobileBinding,
                    Email = email,
                    EmailBinding = emailBinding,
                    SafePassword = safePassword,
                    SafeBinding = safeBinding,
                    CreateDate = DateTime.Now,
                    DelFlag = (int)DelFlagEnum.Noraml,
                    ReMark = model.ReMark,
                    SubmitDomainId = domain.DomainId
                };
                IAccountDal accountDal = new AccountDal();
                var r = accountDal.AddEntity(account);
                if (r != null && r.AccountId > 0)
                {
                    jsonModel.Success = true;
                    jsonModel.Data = r;
                }
                else
                {
                    jsonModel.ErrMsg = "数据插入失败";
                }
            }
            catch
            {
                jsonModel.ErrMsg = "系统内部错误";
            }

            return jsonModel;
        }