/// <summary>
 /// 创建用户信息
 /// </summary>
 /// <param name="UserToken"></param>
 /// <param name="MySocket"></param>
 /// <returns></returns>
 public ChatRoomUserInfo GenerateUserInfo(string UserToken, WebSocket MySocket)
 {
     try
     {
         //判断是否为游客
         if (UserToken == "")
         {
             throw new Exception("UserToken空");
         }
         bk_user UserInfo = Common.Cache.CacheHelper.GetCache <bk_user>(UserToken);
         if (UserInfo == null)
         {
             throw new Exception("UserInfo");
         }
         Random Index = new Random();
         return(new ChatRoomUserInfo
         {
             UserSocket = MySocket,
             UserToken = UserToken,
             NickName = UserInfo.Us_NickName,
             Head_Portrait = UserInfo.Us_ProfilePhoto,
             Experience = Index.Next(1000, 5000)//经验值随机生成
         });
     }
     catch (Exception)
     {
         return(new ChatRoomUserInfo
         {
             UserToken = Common.MD5Helper.getMD5String(DateTime.Now.ToString()),
             UserSocket = MySocket,
             Head_Portrait = "Connection_Fails",
             NickName = "系统游客"
         });
     }
 }
        /// <summary>
        /// 增加一条留言
        /// </summary>
        /// <param name="Content">评论内容</param>
        /// <param name="Author">作者</param>
        /// <returns></returns>
        public Response <string> AddComments(string Content, string UserToken)
        {
            Response <string> Result   = new Response <string>();
            bk_user           UserInfo = Common.Cache.CacheHelper.GetCache <bk_user>(UserToken);

            if (UserInfo != null)
            {
                try
                {
                    db.CommentDAL.Add(new bk_comments
                    {
                        Comment_Content    = Content,
                        Comment_Date       = DateTime.Now,
                        Article_Id         = 1, //评论文章ID,默认1
                        Comment_Like_Count = 0, //点赞
                        Comment_ParentId   = 0,
                        Us_Id = UserInfo.Us_Id
                    });
                    Result.State = 1;
                    Result.Msg   = "添加成功!~";
                    db.saveChanges();
                }
                catch (Exception ex)
                {
                    Result.State = 0;
                    Result.Msg   = ex.Message;
                }
            }
            else
            {
                Result.State = 0;
                Result.Msg   = "用户Token已过期,请重新登录!~";
            }
            return(Result);
        }
Exemple #3
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     base.OnActionExecuting(filterContext);
     //确定为返回视图动作
     if (filterContext.ActionDescriptor.ActionName.IndexOf("_") == -1)
     {
         //已经登录处理事件
         if (Request.Cookies["UserToken"] != null)
         {
             //判断是否已经登录缺进入登录页面
             var AccessUrl = filterContext.HttpContext.Request.Url;
             //从前端Cookie取得用户Token
             string UserToken = Request.Cookies["UserToken"].Value;
             //判断Token是否在高速缓存区
             if (!(Common.Cache.CacheHelper.GetCache <bk_user>(UserToken) is bk_user UserInfo))
             {
                 UserIsLogin = false;
                 //Token过期则清除全部Cookies
                 Response.Cookies["UserToken"].Expires = DateTime.Now.AddDays(-1);
                 ViewData["IsLogin"] = UserIsLogin == true ? "1" : "0";
                 return;
             }
             //设置全局登录
             UserIsLogin = true;
             //设置全局用户信息
             Sso_UserInfo = UserInfo;
             //窗口滑动工作,增加过期时间20分钟
             Bolg.Common.Cache.CacheHelper.SetCache(UserToken, UserInfo, DateTime.Now.AddMinutes(20));
         }
         ViewData["IsLogin"] = UserIsLogin == true ? "1" : "0";
     }
 }
Exemple #4
0
        /// <summary>
        /// 上传分数
        /// </summary>
        /// <param name="Us_Id"></param>
        /// <param name="Score"></param>
        /// <returns></returns>
        public Response <string> UpScore(string UserToken, int Score)
        {
            Response <string> Result   = new Response <string>();
            bk_user           UserInfo = Common.Cache.CacheHelper.GetCache <bk_user>(UserToken);

            if (UserInfo != null)
            {
                try
                {
                    List <bk_game> ScoreInfo = db.GameDAL.GetEntities(o => o.Us_Id == UserInfo.Us_Id).ToList();
                    if (ScoreInfo.Count() > 0)
                    {
                        if (ScoreInfo[0].Game_Score > Score)
                        {
                            throw new Exception("您未超越自己的最高分~继续努力!!");
                        }
                        db.GameDAL.Update(new bk_game
                        {
                            Us_Id      = UserInfo.Us_Id,
                            Game_Score = Score
                        });
                    }
                    else
                    {
                        db.GameDAL.Add(new bk_game
                        {
                            Us_Id      = UserInfo.Us_Id,
                            Game_Score = Score
                        });
                    }
                    Result.State = 1;
                    Result.Msg   = "上传分数成功!~";
                    db.saveChanges();
                }
                catch (Exception ex)
                {
                    Result.State = 0;
                    Result.Msg   = ex.Message;
                }
            }
            else
            {
                Result.State = 0;
                Result.Msg   = "用户Token已过期,请重新登录!~";
            }
            return(Result);
        }
Exemple #5
0
        /// <summary>
        /// 保存用户修改的数据
        /// </summary>
        /// <returns></returns>
        public ActionResult ModifUserInfo_(string UserToken, string NickName, string Eamil, string Phone, string Birth, string cars, string Img_url)
        {
            //判断是否是真的是自己
            string  Msg = ""; int State = 0;
            bk_user UserData = Bolg.Common.Cache.CacheHelper.GetCache <bk_user>(UserToken);

            if (UserData != null)
            {
                try
                {
                    bk_user SaveData = new bk_user();
                    SaveData = new bk_user
                    {
                        Us_NickName = NickName,
                        Us_Id       = UserData.Us_Id,
                        Us_Eamil    = Eamil,
                        Us_Phone    = Phone,
                        Us_Birthday = Birth != null?Convert.ToDateTime(Birth) : new DateTime(),
                                          Us_ProfilePhoto = Img_url,
                                          Us_Sex          = cars != null?Int32.Parse(cars) : 0
                    };
                    if (UserService_.UpUserData(UserData.Us_Id, SaveData))
                    {
                        Msg = "保存成功"; State = 1;
                        //更新缓存数据
                        Bolg.Common.Cache.CacheHelper.SetCache(UserToken, UserService_.FindUserData(UserData.Us_Id.ToString()));
                    }
                    else
                    {
                        Msg = "保存失败:手机号或邮箱已存在,请修改!"; State = 0;
                    }
                }
                catch (Exception)
                {
                    Msg = "未知错误,保存失败~!"; State = 0;
                }
            }
            else
            {
                Msg = "身份信息过期~!"; State = 0;
            }
            return(Json(new Response <string> {
                Msg = Msg, State = State
            }));
        }
 public void ProcessRequest(HttpContext context)
 {
     if (context.Request.HttpMethod.ToLower() == "post")
     {
         bk_user SaveData = new bk_user();
         SaveData.Us_NickName     = context.Request.Form["NickName"];
         SaveData.Us_Id           = Int32.Parse(context.Request.Form["UsId"]);
         SaveData.Us_Eamil        = context.Request.Form["Eamil"];
         SaveData.Us_Phone        = context.Request.Form["Phone"];
         SaveData.Us_Birthday     = Convert.ToDateTime(context.Request.Form["Birth"]);
         SaveData.Us_Sex          = Int32.Parse(context.Request.Form["cars"]);
         SaveData.Us_ProfilePhoto = context.Request.Form["Img_url"];
         new  UserService().UpUserData(SaveData.Us_Id, SaveData);
     }
     context.Response.ContentType = "text/html";
     context.Response.Write(JsonConvert.SerializeObject(new Response <String> {
         State = 1, Msg = "修改成功"
     }));
 }