Example #1
0
        public LoginXiakeData Login(string name, string password, string boardCode)
        {
            try
            {
                var rv = new LoginXiakeData() {Token = Guid.NewGuid().ToString()};
                using (var db = DbContextFactory.CreateDbContext())
                {
                    var settings = ConfigSettings.GetConfigSettings( db.Settingses.FirstOrDefault().ConfigData );
                   
                    var xika = db.Xiakes.Include(a=>a.Credits).FirstOrDefault(a => a.XiakeName == name && a.Password == password);
                     
                    if (xika == null)
                    {
                        throw new FaultException("帐户或密码错误,请核对后再输");
                    }  
                    mMasterServiceProxy.PushShutdownMessage(xika.Id, "您的帐号在其他地方被登录.");

                    if ((xika.UserType == XiakeType.Biaoju || xika.UserType == XiakeType.Zhanggui ) && settings != null)
                    {
                        if (settings.SystemStatusSet.IsDisableLogin == true)
                            throw new FaultException(settings.SystemStatusSet.DisableLoginReason);
                        if (settings.SystemStatusSet.IsDisableSystem == true)
                            throw new FaultException(settings.SystemStatusSet.DisableSystemReason); 
                    }
                    if(xika.Status == XiakeStatus.Disabled)
                        throw new FaultException("您的帐号暂时被冻结!");
                     
                     
                    xika.LastLoginTime = DateTime.Now;
                    xika.LoginCount += 1;
                    xika.LastLoginIp = WcfHelper.GetClientIp();
                    
                    rv.Name = xika.XiakeName;
                    rv.XiakeLevel = xika.Level;
                    rv.XiakeType = xika.UserType;
                    rv.Credits = xika.Credits.FreeCredits;
                    rv.FreezeCredits = xika.Credits.FreezeCredits;
                    rv.ID = xika.Id; 
                    rv.Urls = mMasterServiceProxy.XiakeJoin(xika.Id, xika.XiakeName,rv.Token,xika.UserType,xika.Level);

                    if(!db.BoardCodes.Any(a => a.Xiake.Id  == xika.Id && a.Code == boardCode) && !string.IsNullOrEmpty(boardCode))
                    {
                        var code = new BoardCode() {Code = boardCode, Xiake = xika };
                        db.BoardCodes.Add(code);
                    }

                    db.SaveChanges();
                }
                LogHelper.Log.Debug("Login " + name);
                
                return rv;
            } catch (Exception e)
            {
                LogHelper.Log.Error("Login Exception" , e);
                throw;
            }
          
        }
Example #2
0
        public LoginXiakeData XiakeJoin(string xiakeName, string password, string qq, string mail, string tel, XiakeType xiakeType,string inviteCode)
        {
            var result = new LoginXiakeData();
            using (WebDbContext db = DbContextFactory.CreateDbContext())
            { 
                var settins = ConfigSettings.GetConfigSettings(  db.Settingses.FirstOrDefault().ConfigData);

                if(settins != null && settins.SystemStatusSet.IsDisableRegister)
                {
                    throw new FaultException(settins.SystemStatusSet.DisableRegisterReason);
                }
                if(settins != null && settins.SystemStatusSet.IsDisableSystem)
                {
                    throw new FaultException(settins.SystemStatusSet.DisableSystemReason);
                }

                if(settins.InviteSet.IsEnableInvite && settins.InviteSet.IsRejectNoInviteRegister &&
                   string.IsNullOrEmpty(inviteCode))
                {
                    throw new FaultException("Sorry, 没有邀请码不可注册!");
                }

                if (db.Xiakes.Any(a => a.XiakeName.Equals(xiakeName)))
                {
                    throw new FaultException("用户名已被使用中,请更换");
                }

                if(db.Xiakes.Any(a => a.Mail.Equals(mail)))
                {
                    throw new FaultException("邮箱已被使用中,请更换");
                }

                if (db.Xiakes.Any(a => a.Tel.Equals(tel)))
                {
                    throw new FaultException("手机已被使用中,请更换");
                }

                if (db.Xiakes.Any(a => a.QQ.Equals(qq)))
                {
                    throw new FaultException("QQ已被使用中,请更换");
                }

                var ip = WcfHelper.GetClientIp();
                
                var xiake = new Xiake
                {
                    XiakeName = xiakeName,
                    Password = password,
                    QQ = qq,
                    Mail = mail,
                    Tel = tel, 
                    RegisterIp = ip,
                    Credits =  new XiakeCredits()
                    {
                        FreeCredits=0,
                        FreezeCredits = 0
                    },
                    InviteStorage = new InviteStorage(),
                    IsAuthorized = true,
                    IsFrozen = false, 
                    LoginCount = 1,
                    LastLoginTime = DateTime.Now,
                    LastLoginIp = ip,
                    UserType = xiakeType,
                    Level = XiakeLevel.Guest,
                    Status = XiakeStatus.Enabled,
                    LastReadGonggaoId = 0
                };
                db.Xiakes.Add(xiake);

                var gift = 
                        xiakeType == XiakeType.Biaoju
                            ? settins.CreditsPolicySet.GifrForBiaoju
                            : settins.CreditsPolicySet.GiftForZhanggui;
                if(gift > 0)
                {
                    var charge = new Charge()
                    {
                        ChargeMode = ChargeMode.ByOwner,
                        Comments="新会员赠送",
                        Handler= xiake,
                        PayType= PayType.ByPresent,
                        TargetXiake= xiake,
                        Value = gift
                    };
                
                    xiake.Credits.FreeCredits = charge.Value;
                    db.Charges.Add(charge); 
                }

                if(!string.IsNullOrEmpty(inviteCode))
                {
                    var masterId = InviteCodeHelper.GetXiakeIdWithInviteCode(inviteCode);
                    var master = db.Xiakes.FirstOrDefault(a => a.Id == masterId);
                    if(master == null)
                    {
                        throw new FaultException("Sorry, 邀请码错误!");
                    }
                    var invite = new Invite() {Slave = xiake , Master = master};
                    db.Invites.Add(invite);
                    
                   
                }
                //if(settins.InviteSet.IsEnableInvite)
                //{
                //    var inviteStorage = new InviteStorage() {Credits = 0, Xiake = xiake};
                //    db.InviteStorages.Add(inviteStorage);
                //}
                
                
                db.SaveChanges(); 
                result.ID  = xiake.Id;
                result.Name  = xiake.XiakeName;
                result.XiakeType  = xiake.UserType;
                result.XiakeLevel  = xiake.Level;
                result.Token = Guid.NewGuid().ToString();
                
            }
            return result;
        }