/// <summary>
        /// 当openid或用户ID有一个不为空时自动登录
        /// </summary>
        /// <param name="OpenID"></param>
        /// <param name="ID"></param>
        public static void AutoLogin(string OpenID, int ID)
        {
            GameWZEntities db = new GameWZEntities();

            if (ID != 0)  //用户ID不为空时
            {
                var user = (
                    from a in db.User.Where(x => x.ID == ID) select a
                    ).FirstOrDefault();
                if (user != null)
                {
                    HttpContext.Current.Response.Write("666");
                    HttpContext.Current.Session["ID"]       = user.ID;
                    HttpContext.Current.Session["NickName"] = user.nickname;
                    HttpContext.Current.Session["OpenID"]   = user.OpenID;
                    if (user.OpenID != OpenID)
                    {   //如果OpenID不一致时更数据库
                        user.OpenID = OpenID;
                        db.SaveChanges();
                    }
                }
            }
            else //当openid不为空时自动登录
            {
                var user = (
                    from a in db.User.Where(x => x.OpenID == OpenID) select a
                    ).FirstOrDefault();
                if (user != null)
                {
                    HttpContext.Current.Session["ID"]       = user.ID;
                    HttpContext.Current.Session["NickName"] = user.nickname;
                    HttpContext.Current.Session["OpenID"]   = user.OpenID;
                }
            }
        }
Beispiel #2
0
 public JsonResult Add(FormCollection f)
 {
     try
     {
         //Session["ID"] = "10006";
         var  id       = Convert.ToInt32(Session["ID"]);
         var  integral = Request.Form["integral"];
         var  model    = Request.Form["model"];
         Ring ring     = new Ring();
         ring.ID           = id;
         ring.Gamemode     = model;
         ring.RingDiamonds = Convert.ToInt32(integral);
         db.Ring.Add(ring);
         if (db.SaveChanges() > 0)
         {
             return(Json("摆擂成功,联系客服安排比赛"));
         }
         else
         {
             return(Json("摆擂失败"));
         }
     }
     catch (Exception ex)
     {
         return(Json("摆擂失败" + ex.Message));
     }
 }
        public JsonResult registed(FormCollection collection)
        {
            //测试先不用发送手机
            //HttpContext.Session.Add("phone", collection["phone"].Trim());
            //HttpContext.Session.Add("code", collection["code"].Trim());
            User u = new User();

            u.game_name      = collection["game_name"].Trim();
            u.nickname       = collection["nickname"].Trim();
            u.code           = collection["code"].Trim();
            u.level          = collection["level"].Trim();
            u.password       = collection["password"].Trim();
            u.region_name    = collection["region_name"].Trim();
            u.phone          = collection["phone"].Trim();
            u.area_wx        = collection["region"].Trim();
            u.InvitationCode = collection["InvitationCode"].Trim();
            if (Session["OpenID"] != null)
            {
                u.OpenID = Session["OpenID"].ToString();
            }
            if (db.User.Any(x => x.phone == u.phone))
            {
                return(Json("该手机已注册过不能再注册。"));
            }
            switch (u.level)
            {
            case "1":
                u.level = "青铜";
                break;

            case "2":
                u.level = "白银";
                break;

            case "3":
                u.level = "黄金";
                break;

            case "4":
                u.level = "铂金";
                break;

            case "5":
                u.level = "钻石";
                break;

            case "6":
                u.level = "星耀";
                break;

            case "7":
                u.level = "王者";
                break;
            }

            switch (u.area_wx)
            {
            case "1":
                u.area_wx = "微信区";
                break;

            case "2":
                u.area_wx = "QQ区";
                break;
            }
            //  System.IO.Stream s = Request.InputStream;
            //  int count = 0;
            //  byte[] buffer = new byte[1024];
            //  StringBuilder builder = new StringBuilder();
            //  while ((count = s.Read(buffer, 0, 1024)) > 0)
            //  {
            //      builder.Append(Encoding.UTF8.GetString(buffer,0,count));
            //  }
            ////  builder.Append("success=true");
            //  s.Flush();
            //  s.Close();
            //  s.Dispose();
            //  string a = builder.ToString();
            if (u.phone == Session["phone"].ToString() && u.code == Session["code"].ToString() && u != null)
            {
                if (!string.IsNullOrEmpty(u.InvitationCode))
                {
                    if (!db.StaffSeller.Any(x => x.OwnerInvitationcode == u.InvitationCode))
                    {
                        return(Json("注册失败,邀请码错误"));
                    }
                }
                db.User.Add(u);
                if (db.SaveChanges() > 0)
                {
                    Session["ID"]       = u.ID;
                    Session["NickName"] = u.nickname;
                    return(Json("注册成功"));
                }
                else
                {
                    return(Json("注册失败"));
                }
            }
            else
            {
                return(Json("注册失败,验证码错误"));
            }
        }