public static AuthenticationToken <T> GetCurrentAuthToken <T>() where T : class, new()
        {
            var authToken = HttpContext.Current.Items[FormsAuthentication.FormsCookieName] as AuthenticationToken <T>;

            if (authToken == null)
            {
                try
                {
                    var encryptedToken = //Utility.MD5Decrypt(
                                         Encoding.UTF8.GetString(
                        Convert.FromBase64String(
                            FormsAuthentication.Decrypt(
                                CookiesHelper.GetCookieValue(
                                    FormsAuthentication.FormsCookieName)).UserData));            //);

                    if (!string.IsNullOrWhiteSpace(encryptedToken))
                    {
                        authToken = encryptedToken.ToJsonObject <AuthenticationToken <T> >();
                        HttpContext.Current.Items[FormsAuthentication.FormsCookieName] = authToken;
                    }
                }
                catch (Exception)
                {
                }
            }
            return(authToken);
        }
Example #2
0
        //执行Action之前操作
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //判断是否登录或是否用权限,如果有那么就进行相应的操作,否则跳转到登录页或者授权页面
            string s_accountId = AES.DecryptStr(CookiesHelper.GetCookieValue("UserID"));

            int i_accountId = 0;

            //判断是否有cookie
            if (int.TryParse(s_accountId, out i_accountId))
            {
                AchieveEntity.UserEntity m_account = new AchieveBLL.UserBLL().GetUserById(i_accountId.ToString());
                if (m_account != null)
                {
                    accountmodelJudgment = m_account;
                    filterContext.Controller.ViewData["Account"]     = m_account;
                    filterContext.Controller.ViewData["AccountName"] = m_account.AccountName;
                    filterContext.Controller.ViewData["RealName"]    = m_account.RealName;

                    //处理Action之前操作内容根据我们提供的规则来定义这部分内容
                    base.OnActionExecuting(filterContext);
                }
                else
                {
                    CookiesHelper.AddCookie("UserID", System.DateTime.Now.AddDays(-1));
                    filterContext.Result = new RedirectResult("/Login/Index");
                }
            }
            else
            {
                filterContext.Result = new RedirectResult("/Login/Index");
            }
        }
Example #3
0
        /// <summary>
        /// 获取用户的游戏状态
        /// </summary>
        /// <param name="key">UserID</param>
        /// <returns></returns>
        public GameInfo GetGameData(string key)
        {
            var data = new GameInfo();

            try
            {
                //首先从服务端缓存获取
                data = CacheExts <GameInfo> .GetValue(key);

                if (data == null)
                {
                    //缓存不存在,则读取用户本地Cookie解析成游戏对象
                    var cookieStr = CookiesHelper.GetCookieValue(key);
                    var json      = EncryptAndDecrypt.Decrypt(cookieStr);
                    data = JsonConvert.DeserializeObject <GameInfo>(json);
                }
            }
            catch {}
            if (data == null)
            {
                //如果都没有,则初始化一个游戏对象
                data = new GameInfo();
                RefNum(ref data);
            }
            return(data);
        }
Example #4
0
        public ActionResult Logged()
        {
            var vm = new LoggedView();

            vm.UserName = CookiesHelper.GetCookieValue("uname");
            vm.RoleType = CookiesHelper.GetCookieValue("utype");

            return(PartialView("_Logged", vm));
        }
Example #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    ReferUrl = Request.Url.AbsolutePath;

                    var user = CookiesHelper.GetCookieValue("juncheng_platform_user", "uinfo");
                    if (user == null || user == "")
                    {
                        Page.Response.Redirect("login.html?referUrl=" + ReferUrl);
                        return;
                    }
                    user     = HttpUtility.UrlDecode(user);
                    UInfo    = user;
                    UserData = JsonHelper.Build <CustomerLoginData>(user);
                    if (UserData == null)
                    {
                        Page.Response.Redirect("login.html?referUrl=" + ReferUrl);
                        return;
                    }


                    var menus = Utilities.Cache.Instance["juncheng_platform_menu_" + UserData.UserRoleID];
                    if (menus == null)
                    {
                        Page.Response.Redirect("login.html?referUrl=" + ReferUrl);
                        Page.Response.End();
                        return;
                    }
                    MenuDatas = (List <MenuData>)menus;

                    var extends = Utilities.Cache.Instance["juncheng_rolemenuextends_" + UserData.UserRoleID];
                    if (extends != null)
                    {
                        RightKeys = JsonHelper.ReBuilder(((List <MenuExtentData>)extends).Where(c => c.Url == ReferUrl).Select(c => c.RightKey).ToArray());
                    }
                }
                catch (Exception ex)
                {
                    if (ex.GetType().Name != "ThreadAbortException")
                    {
                        Logger.WriteToFile("【登录】", ex);
                    }
                }

                //Page.DataBind();
            }
        }
Example #6
0
        /// <summary>
        /// 当前登录员工ID
        /// </summary>
        /// <returns></returns>
        private static string GetCurrentEmployeeName()
        {
            string Md5ID = CookiesHelper.GetCookieValue("EmployeeName");

            if (string.IsNullOrEmpty(Md5ID))
            {
                return(Md5ID);
            }
            Md5ID = Md5Helper.Md5Decrypt(Md5ID);
            int indexof = Md5ID.IndexOf("sharp_");

            if (indexof == 0)
            {
                Md5ID = Md5ID.Replace("sharp_", "");
            }
            return(Md5ID);
        }
Example #7
0
        protected override void ShowPage()
        {
            pagetitle = "投票";
            //修正请求页数中可能的错误
            pageid = pageid < 1 ? 1 : pageid;
            aid    = DNTRequest.GetInt("aid", 0);
            uid    = DNTRequest.GetInt("uid", 0);
            Attachments.UpdateAttachmentviewnum(aid);

            dr_vote = Attachments.GetVotelistByUid(aid, uid, pageid, 1, ref totalvote).Tables[0].Rows[0];

            //获取总页数
            pagecount = totalvote % 1 == 0 ? totalvote / 1 : totalvote / 1 + 1;
            pagecount = pagecount == 0 ? 1 : pagecount;

            pageid = pageid > pagecount ? pagecount : pageid;

            //得到页码链接
            pagenumbers = Utils.GetPageNumbers(pageid, pagecount, string.Format("vote.aspx{0}", string.Format("?uid={0}", uid)), 8);

            //如果是POST提交...
            if (ispost)
            {
                string checkCode = CookiesHelper.GetCookieValue("CheckCode");
                if (checkCode.Equals(DNTRequest.GetString("vcode")))
                {
                    aid = DNTRequest.GetInt("hidaid", 0);
                    if (Attachments.UpdatePicVote(aid, DNTRequest.GetString("txt_comment")) > 0)
                    {
                        aid     = 0;
                        dr_vote = Attachments.GetVotelistByUid(aid, uid, pageid, 1, ref totalvote).Tables[0].Rows[0];
                        CookiesHelper.AddNoDomainCoolie("userIP", "IPaddress", CookiesHelper.GetCookieValue("IPaddress"), 60 * 24);
                        errormessage = "投票成功,谢谢您的参与!";
                    }
                    else
                    {
                        errormessage = "投票失败!";
                    }
                }
                else
                {
                    errormessage = "验证码错误!";
                }
            }
        }
Example #8
0
        /// <summary>
        /// 当前登录员工ID
        /// </summary>
        /// <returns></returns>
        private int GetCurrentEmployeeID()
        {
            string Md5ID = CookiesHelper.GetCookieValue("Employee");

            if (string.IsNullOrEmpty(Md5ID))
            {
                return(0);
            }
            Md5ID = Md5Helper.Md5Decrypt(Md5ID);
            int indexof = Md5ID.IndexOf("sharp_");

            if (indexof == 0)
            {
                Md5ID = Md5ID.Replace("sharp_", "");
            }
            int ID = Tool.Function.ConverToInt(Md5ID);

            if (ID < 0)
            {
                return(0);
            }
            return(ID);
        }
        public static AuthenticationToken <T> GetCurrentAuthToken <T>() where T : class, new()
        {
            var authToken = HttpContext.Current.Items[FormsAuthentication.FormsCookieName] as AuthenticationToken <T>;

            if (authToken == null)
            {
                try
                {
                    var decryptedToken = FormsAuthentication.Decrypt(
                        CookiesHelper.GetCookieValue(
                            FormsAuthentication.FormsCookieName))
                                         .UserData;

                    if (!string.IsNullOrWhiteSpace(decryptedToken))
                    {
                        authToken = decryptedToken.ToJsonObject <AuthenticationToken <T> >();
                        HttpContext.Current.Items[FormsAuthentication.FormsCookieName] = authToken;
                    }
                }
                catch (Exception) { }
            }
            return(authToken);
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string user_Id  = AES.DecryptStr(CookiesHelper.GetCookieValue("UserID"));
            Guid   guser_Id = Guid.Empty;

            if (Guid.TryParse(user_Id, out guser_Id))
            {
                var user = new UserBLL().GetUserById(guser_Id);
                if (user != null)
                {
                    filterContext.Controller.ViewData["UserData"] = user;
                    base.OnActionExecuting(filterContext);
                }
                else
                {
                    CookiesHelper.AddCookie("UserID", DateTime.Now.AddDays(-1));
                    filterContext.Result = new RedirectResult("/Login/Index");
                }
            }
            else
            {
                filterContext.Result = new RedirectResult("/Login/Index");
            }
        }
Example #11
0
        public bool IsPostBack     = true; //是否首次加载
        #endregion
        protected override void ShowPage()
        {
            pagetitle = "投票";

            //修正请求页数中可能的错误
            pageid = pageid < 1 ? 1 : pageid;
            aid    = DNTRequest.GetInt("aid", 0);
            uid    = DNTRequest.GetInt("uid", 0);
            Attachments.UpdateAttachmentviewnum(aid);

            DataSet ds = Attachments.GetVotelistByUid(aid, uid, pageid, 1, ref totalvote);

            if (ds != null && ds.Tables.Count > 0 & ds.Tables[0].Rows.Count > 0)
            {
                dr_vote = ds.Tables[0].Rows[0];
            }
            else
            {
                SetUrl("taohua_xianzi.aspx");
                SetMetaRefresh();
                AddErrLine("没有信息可读取!");
                return;
            }
            //获取总页数
            pagecount = totalvote % 1 == 0 ? totalvote / 1 : totalvote / 1 + 1;
            pagecount = pagecount == 0 ? 1 : pagecount;

            pageid = pageid > pagecount ? pagecount : pageid;

            prepage = pageid - 1;
            nexpage = pageid + 1;

            prepage = prepage == 0 ? 1 : prepage;
            prepage = prepage > pagecount ? pagecount : prepage;

            nexpage = nexpage == 0 ? 1 : nexpage;
            nexpage = nexpage > pagecount ? pagecount : nexpage;

            //得到页码链接
            pagenumbers = Utils.GetPageNumbers(pageid, pagecount, string.Format("taohuavote.aspx{0}", string.Format("?uid={0}", uid)), 8);

            //如果是POST提交...
            if (ispost)
            {
                DateTime begin = DateTime.Parse(Discuz.Common.ConfigOperator.ConfigReadValue("startvotetime"));
                DateTime end   = DateTime.Parse(Discuz.Common.ConfigOperator.ConfigReadValue("endvotetime")).AddDays(1);
                if (DateTime.Now < begin || end < DateTime.Now)
                {
                    SetUrl("taohua_xianzi.aspx");
                    SetMetaRefresh();
                    AddErrLine("投票时间为:" + begin.ToString("yyyy年MM月dd日") + "到" + end.AddDays(-1).ToString("yyyy年MM月dd日"));
                    return;
                }
                else
                {
                    string     UserIP    = HttpContext.Current.Request.UserHostAddress.ToString();
                    HttpCookie oldCookie = HttpContext.Current.Request.Cookies["userIP"];
                    if (oldCookie == null)
                    {
                        //定义新的Cookie对象
                        HttpCookie newCookie = new HttpCookie("IPaddress");
                        newCookie.Expires = DateTime.Now.AddMinutes(5);
                        //添加新的Cookie变量IPaddress,值为UserIP
                        newCookie.Value = UserIP;
                        //将变量写入Cookie文件中
                        HttpContext.Current.Response.AppendCookie(newCookie);
                    }
                    else
                    {
                        string userIP = oldCookie.Values["IPaddress"];
                        if (UserIP.Trim() == userIP.Trim())
                        {
                            SetUrl("taohua_xianzi.aspx");
                            SetMetaRefresh();
                            AddErrLine("一个IP地址只能投一次票,谢谢您的参与!");
                            return;
                        }
                        else
                        {
                            //定义新的Cookie对象
                            HttpCookie newCookie = new HttpCookie("IPaddress");
                            newCookie.Expires = DateTime.Now.AddMinutes(5);
                            //添加新的Cookie变量IPaddress,值为UserIP
                            newCookie.Value = UserIP;
                            //将变量写入Cookie文件中
                            HttpContext.Current.Response.AppendCookie(newCookie);
                        }
                    }

                    //string checkCode = CookiesHelper.GetCookieValue("CheckCode");
                    //if (checkCode.Equals(DNTRequest.GetString("vcode")))
                    //{
                    aid = DNTRequest.GetInt("hidaid", 0);
                    if (Attachments.UpdatePicVote(aid, DNTRequest.GetString("txt_comment")) > 0)
                    {
                        //aid = 0;
                        //dr_vote = Attachments.GetVotelistByUid(aid, uid, pageid, 1, ref totalvote).Tables[0].Rows[0];
                        CookiesHelper.AddNoDomainCoolie("userIP", "IPaddress", CookiesHelper.GetCookieValue("IPaddress"), 60 * 24);
                        AddMsgLine("投票成功,谢谢您的参与!");
                        //SetUrl(forumpath + "taohuavote.aspx" + HttpContext.Current.Request.Url.PathAndQuery.Substring(HttpContext.Current.Request.Url.PathAndQuery.IndexOf("?")) + "&aid=" + aid);
                        SetUrl(forumpath + "taohuavote.aspx?uid=" + uid + "&aid=" + aid);
                        SetMetaRefresh();
                        SetShowBackLink(false);
                    }
                    else
                    {
                        AddErrLine("投票失败,请稍后重试!");
                        SetUrl("taohua_xianzi.aspx");
                        SetMetaRefresh(5);
                        SetShowBackLink(true);
                    }
                    //}
                    //else
                    //{
                    //    errormessage = "验证码错误!";
                    //}
                }
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Request  = context.Request;
            Response = context.Response;
            switch (Request["operType"])
            {
            case "verifyvote":
                DateTime begin = DateTime.Parse(Discuz.Common.ConfigOperator.ConfigReadValue("startvotetime"));
                DateTime end   = DateTime.Parse(Discuz.Common.ConfigOperator.ConfigReadValue("endvotetime")).AddDays(1);
                if (DateTime.Now < begin)
                {
                    Response.Write("{\"result\":\"0\",\"msg\":\"投票太早了,投票时间为:" + begin.ToString("yyyy年MM月dd日") + "到" + end.AddDays(-1).ToString("yyyy年MM月dd日") + "\"}");
                }
                else if (end < DateTime.Now)
                {
                    Response.Write("{\"result\":\"0\",\"msg\":\"投票来晚了,投票时间为:" + begin.ToString("yyyy年MM月dd日") + "到" + end.AddDays(-1).ToString("yyyy年MM月dd日") + "\"}");
                }
                else
                {
                    //判断指定的IP是否已投过票了,如果已经投过了,则弹出提示对话框
                    string     UserIP    = Request.UserHostAddress.ToString();
                    HttpCookie oldCookie = Request.Cookies["userIP"];
                    if (oldCookie == null)
                    {
                        //定义新的Cookie对象
                        HttpCookie newCookie = new HttpCookie("IPaddress");
                        newCookie.Expires = DateTime.Now.AddMinutes(5);
                        //添加新的Cookie变量IPaddress,值为UserIP
                        newCookie.Value = UserIP;
                        //将变量写入Cookie文件中
                        Response.AppendCookie(newCookie);
                        Response.Write("{\"result\":\"1\"}");
                    }
                    else
                    {
                        string userIP = oldCookie.Values["IPaddress"];
                        if (UserIP.Trim() == userIP.Trim())
                        {
                            Response.Write("{\"result\":\"0\",\"msg\":\"一个IP地址只能投一次票,谢谢您的参与!\"}");
                        }
                        else
                        {
                            //定义新的Cookie对象
                            HttpCookie newCookie = new HttpCookie("IPaddress");
                            newCookie.Expires = DateTime.Now.AddMinutes(5);
                            //添加新的Cookie变量IPaddress,值为UserIP
                            newCookie.Value = UserIP;
                            //将变量写入Cookie文件中
                            Response.AppendCookie(newCookie);
                            Response.Write("{\"result\":\"1\"}");
                        }
                    }
                }
                break;

            case "vote":
                if (Attachments.UpdatePicVote(int.Parse(Request["Aid"]), string.Empty) > 0)
                {
                    CookiesHelper.AddNoDomainCoolie("userIP", "IPaddress", CookiesHelper.GetCookieValue("IPaddress"), 60 * 24);
                    Response.Write("{\"result\":\"1\",\"msg\":\"投票成功,谢谢您的参与!\"}");
                }
                else
                {
                    Response.Write("{\"result\":\"0\",\"msg\":\"投票失败,请稍后重试!\"}");
                }

                break;
            }
        }