Пример #1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        public void Login(string userName, string password)
        {
            var member = DataBase.Get <Member>(e => e.UserName == userName);

            if (member == null)
            {
                throw new PlatformException(ErrorCode.ErrorUserNameOrPassword);
            }
            string toPassword = CypherUtility.Md5(password + Salt);

            if (toPassword != member.Password)
            {
                throw new PlatformException(ErrorCode.ErrorUserNameOrPassword);
            }
            if (member.Status == MemberStatus.UnActived)        //未激活不让登录
            {
                throw new PlatformException(ErrorCode.AccountIsUnActived);
            }
            //Locking
            if (member.Status == MemberStatus.Actived && member.LastModifiedAt < DateTime.Now.AddDays(-10))
            {
                member.Status = MemberStatus.Locking;
                DataBase.Update(member);
            }
            //Freezing
            if (member.Status == MemberStatus.Actived && member.LastModifiedAt < DateTime.Now.AddDays(-20))
            {
                member.Status = MemberStatus.Freezing;
                DataBase.Update(member);
                throw new PlatformException(ErrorCode.AccountIsFreezing);
            }
            if (member.Status == MemberStatus.Freezing)
            {
                throw new PlatformException(ErrorCode.AccountIsFreezing);
            }
            //SealUp
            if (member.Status == MemberStatus.InUse && member.ExpiredAt <= DateTime.Now)
            {
                member.Status = MemberStatus.SealUp;
                DataBase.Update(member);
                throw new PlatformException(ErrorCode.AccountIsSealUp);
            }
            if (member.Status == MemberStatus.SealUp)
            {
                throw new PlatformException(ErrorCode.AccountIsSealUp);
            }
            DataBase.Update(member);
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, member.UserName, DateTime.Now, DateTime.Now.AddHours(3), true, member.SerializeObject());
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket))
            {
                HttpOnly = true,
            };

            HttpContext.Current.Response.Cookies.Add(cookie);
        }
Пример #2
0
        public void SysMemberResetPassword(string userName, string password)
        {
            var member = DataBase.Get <Member>(e => e.UserName == userName);

            if (member == null)
            {
                throw new PlatformException(ErrorCode.UserNameIsNotExisted);
            }
            member.Password = CypherUtility.Md5(password + Salt);
            DataBase.Update(member);
        }
Пример #3
0
        public void SysMemberAdd(string userName, string password, string nickName)
        {
            if (DataBase.Count <Member>(e => e.UserName == userName) > 0)
            {
                throw new PlatformException(ErrorCode.UserNameIsExisted);
            }
            var member = new Member
            {
                UserName          = userName,
                Password          = CypherUtility.Md5(password + Salt),
                Mobile            = "",
                Name              = "",
                NickName          = nickName,
                Status            = MemberStatus.Actived,
                WeChat            = "",
                HeadPic           = MemberHeadPicOption.A,
                RecommendUserName = "",
                Chain             = ""
            };

            DataBase.Save(member);
        }
Пример #4
0
        /// <summary>
        /// 注册
        /// //TODO 必须要推荐人,初始为未激活
        /// </summary>
        /// <param name="inviter">必填</param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="mobile"></param>
        /// <param name="weChat"></param>
        /// <param name="alipay"></param>
        /// <param name="bitCoin"></param>
        /// <returns></returns>
        public void Register(string inviter, string userName, string password, string mobile, string bankName, string bankCode, string areaCode, string weChat = "", string alipay = "", string bitCoin = "", string name = "")
        {
            lock (this)
            {
                var member = DataBase.Get <Member>(e => e.UserName == userName);
                if (member != null)
                {
                    throw new PlatformException(ErrorCode.UserNameIsExisted);
                }
                if (DataBase.Count <Member>(e => e.Mobile == mobile) > 0)
                {
                    throw new PlatformException(ErrorCode.MobileIsExisted);
                }
                //校验
                var recommendUser = DataBase.Get <Member>(e => e.UserName == inviter);
                if (recommendUser == null)
                {
                    throw new PlatformException(ErrorCode.InviterError);
                }
                ISession     session      = DataBase.Session;
                ITransaction iTransaction = session.BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    //Todo
//					if (recommendUser.CopperBalance < MiddleTier.BusinessConfig.ActivePartnerNeedAmount)
//					{
//						throw new PlatformException(ErrorCode.InviterAccountBalanceNotEnough);
//					}
                    //保存用户
                    member = new Member
                    {
                        UserName          = userName,
                        Password          = CypherUtility.Md5(password + Salt),
                        Mobile            = mobile,
                        Name              = name,
                        NickName          = "",
                        Status            = MemberStatus.UnActived,
                        WeChat            = weChat,
                        Alipay            = alipay,
                        BitCoin           = bitCoin,
                        HeadPic           = MemberHeadPicOption.A,
                        RecommendUserName = inviter,
                        Chain             = $"{recommendUser.Chain}{ChainStr}{recommendUser.UserName}",
                        DiamondBalance    = 1,
                        ExpiredAt         = DateTime.Now.AddDays(30),
                        MemberType        = MemberType.Normal,
                        GlobalAreaCode    = areaCode,
                        BankCode          = bankCode,
                        BankName          = bankName
                    };
                    DataBase.Save(member, session);
//					MiddleTier.TransferBillManager.Initiate(TransferBillType.Active, TransferBillStatus.Completed, recommendUser.UserName, member.UserName, MiddleTier.BusinessConfig.ActivePartnerNeedAmount);
                    //发放邀请奖励
//					var recommendCount = DataBase.Count<Member>(e => e.RecommendUserName == inviter,session);
//					var slagEquipmentCount = DataBase.Count<SlagRefiningEquipment>(e => e.MemberUserName == inviter&&e.SourceType==SlagRefiningEquipmentSourceType.InvitingAwards,session);
//					if (slagEquipmentCount < MiddleTier.BusinessConfig.SlagRefiningEquipmentCountLimit&& (int)(recommendCount/MiddleTier.BusinessConfig.SlagRefiningEquipmentRewardInviteMemberCount)>slagEquipmentCount)//每个推荐人精炼设备上限&&达到发放奖励的推荐人数
//					{
//						//矿渣提炼炉上限是10台,每推荐10名合伙人送一台,每台可精炼矿渣总量的0.3%黄金,前两台0.5%,每台使用期限一年!
//						DataBase.Save(new SlagRefiningEquipment
//						{
//							MemberUserName = inviter,
//							LastRefiningAt = DateTime.Now,
//							Percentage = slagEquipmentCount<MiddleTier.BusinessConfig.SlagRefiningEquipmentTopCount ? MiddleTier.BusinessConfig.SlagRefiningEquipmentTopPercentage:MiddleTier.BusinessConfig.SlagRefiningEquipmentNormalPercentage,
//							SourceType = SlagRefiningEquipmentSourceType.InvitingAwards,
//							ValidityTerm = DateTime.Now.AddDays(MiddleTier.BusinessConfig.SlagRefiningEquipmentUseTermDay)
//						},session);
//					}
                    iTransaction.Commit();
                }
                catch (Exception ex)
                {
                    iTransaction.Rollback();
                    MiddleTier.LogManager.Error(ex);
                    if (ex is PlatformException platformException)
                    {
                        throw platformException;
                    }
                    throw new PlatformException(ErrorCode.SystemError);
                }
                finally
                {
                    session.Close();
                }
            }
        }