コード例 #1
0
ファイル: LoginController.cs プロジェクト: lintsGitHub/XMSHOP
 /// <summary>
 /// 处理登录的信息
 /// </summary>
 /// <param name="userInfo"></param>
 /// <param name="CookieExpires">cookie有效期</param>
 /// <returns></returns>
 public ActionResult CheckUserLogin(string CookieExpires)
 {
     try
     {
         var iUserDal    = DALUtility.User;
         var currentUser = iUserDal.UserLogin(Request["user_AN"], Request["user_pwd"]);
         if (currentUser != null)
         {
             //记录登录cookie
             CookiesHelper.SetCookie("UserID", AES.EncryptStr(currentUser.id.ToString()));
             log(Request["user_AN"].ToString(), "账号登录", "true", "登录成功");
             return(OperationReturn(true, "登录成功!"));
         }
         else
         {
             log(Request["user_AN"].ToString(), "账号登录", "false", "用户名或者密码错误");
             return(OperationReturn(false, "登录失败!用户名或者密码错误!"));
         }
     }
     catch (Exception ex)
     {
         log(Request["user_AN"].ToString(), "账号登录", "false", "登录异常," + ex.Message);
         return(OperationReturn(false, "登录异常," + ex.Message));
     }
 }
コード例 #2
0
ファイル: BaseController.cs プロジェクト: LanccBy2016/C2048
        public LoginInfoModel GetLoginInfo()
        {
            var model       = new LoginInfoModel();
            var loginCookie = CookiesHelper.GetCookie(WebConfigOperation.CookieName);//是否已存在登录的用户cookie

            if (loginCookie != null)
            {
                //2.获取用户信息
                model.UserInfo = new LoginBLL().GetUserInfo(loginCookie.Value);
                if (model.UserInfo == null)
                {
                    return(model);
                }
            }
            var ykCookie = CookiesHelper.GetCookie(WebConfigOperation.YkCookieName);

            if (ykCookie == null)
            {
                var yk = EncryptAndDecrypt.Encrypt(DateTime.Now.ToString());
                CookiesHelper.AddCookie(WebConfigOperation.YkCookieName, yk);
                CookiesHelper.SetCookie(WebConfigOperation.YkCookieName, DateTime.Now.AddMonths(1));
                model.ykCookie = yk;
            }
            else
            {
                model.ykCookie = ykCookie.Value.ToString();
            }

            return(model);
        }
コード例 #3
0
ファイル: Consult.aspx.cs プロジェクト: qubianzhong/luckysign
        protected void SetCommentCookies(int sysno)
        {
            string tmpstr = "";

            if (Request.Cookies["upup1000"] != null && Request.Cookies["upup1000"]["QuestComment"] != null && Request.Cookies["upup1000"]["QuestComment"] != string.Empty)
            {
                tmpstr = CommonTools.Decode(Request.Cookies["upup1000"]["QuestComment"]) + "|" + sysno + "," + DateTime.Now.ToString("yyyy-MM-dd");
            }
            else
            {
                tmpstr = sysno.ToString() + "," + DateTime.Now.ToString("yyyy-MM-dd");
            }

            HttpCookie Cookie = CookiesHelper.GetCookie("upup1000");

            if (Cookie == null || Cookie.Value == null || Cookie.Value == "")
            {
                Cookie = new HttpCookie("upup1000");
                Cookie.Values.Add("QuestComment", CommonTools.Encode(tmpstr));
                //设置Cookie过期时间
                Cookie.Expires = DateTime.Now.AddYears(50);
                CookiesHelper.AddCookie(Cookie);
            }
            else
            {
                CookiesHelper.SetCookie("upup1000", "QuestComment", CommonTools.Encode(tmpstr), DateTime.Now.AddYears(50));
            }
        }
コード例 #4
0
ファイル: Consult.aspx.cs プロジェクト: qubianzhong/luckysign
        protected bool CheckCommentCookies(int sysno)
        {
            bool ret = false;

            string[] tmpstr;
            string   newstr = "";

            if (Request.Cookies["upup1000"] != null && Request.Cookies["upup1000"]["QuestComment"] != null && Request.Cookies["upup1000"]["QuestComment"] != string.Empty)
            {
                tmpstr = CommonTools.Decode(Request.Cookies["upup1000"]["QuestComment"]).Split(new char[] { '|' });
                for (int i = 0; i < tmpstr.Length; i++)
                {
                    if (sysno.ToString() == tmpstr[i].Split(new char[] { ',' })[0])
                    {
                        ret = true;
                    }
                    if (DateTime.Now - DateTime.Parse(tmpstr[i].Split(new char[] { ',' })[1]) < new TimeSpan(7, 0, 0, 0))
                    {
                        newstr += tmpstr[i] + "|";
                    }
                }
                newstr = newstr.Remove(newstr.LastIndexOf("|"));
                CookiesHelper.SetCookie("upup1000", "QuestComment", CommonTools.Encode(newstr), DateTime.Now.AddYears(50));
            }
            return(ret);
        }
コード例 #5
0
ファイル: Default.aspx.cs プロジェクト: qubianzhong/luckysign
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Request.QueryString["type"] == "logout")
         {
             Session[AppConfig.AdminSession] = null;
             HttpCookie Cookie = CookiesHelper.GetCookie("upup1000Admin");
             if (Cookie != null && Cookie.Value != null && Cookie.Value != "")
             {
                 CookiesHelper.SetCookie("upup1000Admin", "uname", "", DateTime.Now.AddYears(-1));
                 CookiesHelper.SetCookie("upup1000Admin", "psd", "", DateTime.Now.AddYears(-1));
             }
         }
         try
         {
             if (Request.Cookies["upup1000Admin"]["uname"] != null && Request.Cookies["upup1000Admin"]["uname"] != string.Empty &&
                 Request.Cookies["upup1000Admin"]["psd"] != null && Request.Cookies["upup1000Admin"]["psd"] != string.Empty)
             {
                 string username = CommonTools.Decode(Request.Cookies["upup1000Admin"]["uname"]);
                 string password = CommonTools.Decode(Request.Cookies["upup1000Admin"]["psd"]);
                 LoginCheck(username, password);
                 Response.Cache.SetCacheability(HttpCacheability.NoCache);
             }
         }catch {}
     }
 }
コード例 #6
0
        /// <summary>
        /// 获取信息 加入缓存
        /// </summary>
        public void GetMajors()
        {
            //写入专业缓存
            CookiesHelper.SetCookie("Majors", HttpUtility.UrlEncode(JsonConvert.SerializeObject(student_BLL.GetMajors())), DateTime.Now.AddDays(7));
            //写入班级缓存
            CookiesHelper.SetCookie("Classes", HttpUtility.UrlEncode(JsonConvert.SerializeObject(student_BLL.QueryBySid())), DateTime.Now.AddDays(7));
            //写入阶段缓存
            CookiesHelper.SetCookie("Stages", HttpUtility.UrlEncode(JsonConvert.SerializeObject(student_BLL.GetStages())), DateTime.Now.AddDays(7));
            //写入学院缓存
            CookiesHelper.SetCookie("Colleges", HttpUtility.UrlEncode(JsonConvert.SerializeObject(user_BLL.GetColleges())), DateTime.Now.AddDays(7));
            //记录数量
            var majorNum = 0;

            majorNum = student_BLL.GetMajors().Count;
            var classNum = 0;

            classNum = student_BLL.QueryBySid().Count;
            var stageNum = 0;

            stageNum = student_BLL.GetStages().Count;
            var collegesNum = 0;

            collegesNum         = user_BLL.GetColleges().Count;
            ViewBag.majorNum    = majorNum;
            ViewBag.classNum    = classNum;
            ViewBag.stageNum    = stageNum;
            ViewBag.collegesNum = collegesNum;
        }
コード例 #7
0
 public string QueryByEQId(string ExamQuestionId, int typeId = 0)
 {
     try
     {
         var list = examquestion_BLL.QueryByEQId(ExamQuestionId);
         List <Questions> result = list;
         if (typeId == 0)
         {
             List <TestPage> test = new List <TestPage>();
             for (int i = 0; i < result.Count(); i++)
             {
                 TestPage m = new TestPage
                 {
                     QuestionNum = result[i].QuestionNum,
                     Answer      = result[i].Answer
                 };
                 test.Add(m);
                 result[i].Answer = CookiesHelper.GetCookie(result[i].QuestionNum);
             }
             //写入Cookie
             CookiesHelper.SetCookie(ExamQuestionId, JsonConvert.SerializeObject(test), DateTime.Now.AddDays(1));
             result = RandomQuestions(list, list.Count());
         }
         return(JsonConvert.SerializeObject(result));
     }
     catch (Exception ex)
     {
         ErrorLog.WriteLog(ex);
         return(null);
     }
 }
コード例 #8
0
ファイル: LoginBLL.cs プロジェクト: LanccBy2016/C2048
        /// <summary>
        /// 设置登陆cookie
        /// </summary>
        /// <param name="user"></param>
        public void SetLoginCookie(UserInfo user)
        {
            var userInfo  = JsonConvert.SerializeObject(new { user.UserID, user.CreateTime });
            var cookieStr = EncryptAndDecrypt.Encrypt(userInfo);

            CookiesHelper.AddCookie(WebConfigOperation.CookieName, cookieStr);
            CookiesHelper.SetCookie(WebConfigOperation.CookieName, DateTime.Now.AddMonths(1));
        }
コード例 #9
0
ファイル: LoginController.cs プロジェクト: winterone/AFeiDemo
        public ActionResult GetValidatorGraphics()
        {
            string code = new ValidatorCode().NewValidateCode();

            //采用cookie
            CookiesHelper.SetCookie("ValidatorCode", code);
            byte[] graphic = new ValidatorCode().NewValidateCodeGraphic(code);
            return(File(graphic, @"image/jpeg"));
        }
コード例 #10
0
        public ActionResult GetValidatorGraphics()
        {
            ValidatorCodeTools obj = new ValidatorCodeTools();

            string code = obj.CreateValidateCode(5);

            //采用cookie
            CookiesHelper.SetCookie("ValidatorCode", code);
            byte[] graphic = obj.CreateValidateGraphic(code);
            return(File(graphic, @"image/jpeg"));
        }
コード例 #11
0
ファイル: GameInfoBLL.cs プロジェクト: LanccBy2016/C2048
        /// <summary>
        /// 保存游戏数据
        /// </summary>
        /// <param name="game"></param>
        public void SetGameData(string key, GameInfo game)
        {
            //IIS缓存
            CacheExts <GameInfo> .SetValue(key, game, noSlidingExpiration : false);

            //客户端持久化存储
            var json      = JsonConvert.SerializeObject(game);
            var cookieStr = EncryptAndDecrypt.Encrypt(json);

            CookiesHelper.AddCookie(key, cookieStr);
            CookiesHelper.SetCookie(key, DateTime.Now.AddMonths(1));
        }
コード例 #12
0
        /// <summary>
        /// 用户登录成功后,将用户信息缓存起来
        /// </summary>
        /// <param name="userData"></param>
        public static void WriteDataToCookie(UserManagement userData)
        {
            //将实体对象序列化为json字符串
            var strUserData = new JavaScriptSerializer().Serialize(userData);

            //将json字符串生成对应的令牌数据  persistent 持久化
            var ticket    = new FormsAuthenticationTicket(1, userData.Id.ToString(), DateTime.Now, DateTime.Now.AddHours(12), false, strUserData);
            var ticketVal = FormsAuthentication.Encrypt(ticket);

            CookiesHelper.SetCookie(FormsAuthentication.FormsCookieName, ticketVal, ticket.Expiration);

            RedisHelper.Set <UserManagement>(userData.Id.ToString(), userData);
        }
コード例 #13
0
        public ActionResult Login(string UserName, string UserPwd)
        {
            var pwd    = Md5Helper.MD5Encoding(UserPwd, 123);
            var result = user_BLL.GetUserID(UserName, pwd);

            if (result != null)
            {
                FormsAuthentication.SetAuthCookie(UserName, false);
                //写入缓存
                CookiesHelper.SetCookie("UID", HttpUtility.UrlEncode(JsonConvert.SerializeObject(result)), DateTime.Now.AddDays(7));
                return(Redirect("~/Home/Index"));
            }
            return(Redirect("~/Home/Login"));
        }
コード例 #14
0
ファイル: Default.aspx.cs プロジェクト: qubianzhong/luckysign
        public void LoginCheck(string username, string password)
        {
            SYS_AdminMod m_admin = SYS_AdminBll.GetInstance().CheckAdmin(username, password);

            if (m_admin.CustomerSysNo != AppConst.IntNull)//COOKIES验证成功
            {
                WebForAnalyse.SessionInfo m_session = new SessionInfo();
                m_session.AdminEntity           = m_admin;
                m_session.PrivilegeDt           = SYS_AdminBll.GetInstance().GetAdminPrivilege(m_admin.CustomerSysNo);
                Session[AppConfig.AdminSession] = m_session;
                //记住我
                if (CheckBox1.Checked)
                {
                    HttpCookie Cookie = CookiesHelper.GetCookie("upup1000Admin");
                    if (Cookie == null || Cookie.Value == null || Cookie.Value == "")
                    {
                        Cookie = new HttpCookie("upup1000Admin");
                        Cookie.Values.Add("uname", CommonTools.Encode(username));
                        Cookie.Values.Add("psd", CommonTools.Encode(password));
                        //设置Cookie过期时间
                        Cookie.Expires = DateTime.Now.AddYears(50);
                        CookiesHelper.AddCookie(Cookie);
                    }
                    else
                    {
                        CookiesHelper.SetCookie("upup1000Admin", "uname", CommonTools.Encode(username), DateTime.Now.AddYears(50));
                        CookiesHelper.SetCookie("upup1000Admin", "psd", CommonTools.Encode(password), DateTime.Now.AddYears(50));
                    }
                }
                LogManagement.getInstance().WriteTrace(m_session.AdminEntity, "Login", "IP:" + Request.UserHostAddress + "|AdminID:" + m_session.AdminEntity.Username);
                //跳转
                if (Request.QueryString["url"] != null && Request.QueryString["url"] != "")
                {
                    Response.Redirect(Request.QueryString["url"]);
                }
                else
                {
                    Response.Redirect("BaZi/PatternList.aspx");
                }
            }
            else
            {
                this.ltrNotice.Text = "用户名或密码错误!";
                base.ClientScript.RegisterStartupScript(base.GetType(), "", "document.getElementById('" + divNotice.ClientID + "').style.display='';", true);
            }
        }
コード例 #15
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <returns></returns>
        public ActionResult CheckLogin()
        {
            ResultInfo result   = new ResultInfo();
            string     userId   = Request["userId"];
            string     password = Request["password"];

            if (string.IsNullOrEmpty(userId))
            {
                result.ErrorCode = 10;
                result.Message   = "用户名不能为空!";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrEmpty(password))
            {
                result.ErrorCode = 11;
                result.Message   = "密码不能为空!";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            UserInfo userInfo = new UserInfo();

            userInfo.UserID   = userId;
            userInfo.Password = password;
            UserService user = new UserService();

            if (user.CheckLogin(userId, password, ref userInfo))
            {
                Session["CurrentUser"] = userInfo.UserID;
                Session["AuthorToken"] = Guid.NewGuid();
                CookiesHelper.SetCookie(userInfo);

                System.Web.HttpContext.Current.Application.Lock();
                System.Web.HttpContext.Current.Application["count"] = Convert.ToInt32(System.Web.HttpContext.Current.Application["count"]) + 1;
                System.Web.HttpContext.Current.Application.UnLock();

                result.IsSuccess = true;
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                result.ErrorCode = 12;
                result.Message   = "用户名和密码不匹配!";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #16
0
 public void SetAnswers(string qid, string answer, DateTime time, int tid)
 {
     try
     {
         if (tid == 0)
         {
             CookiesHelper.SetCookie(qid, answer, time.AddSeconds(10));
         }
         else
         {
             CookiesHelper.SetCookie(qid, "", time.AddSeconds(10));
         }
     }
     catch (Exception ex)
     {
         ErrorLog.WriteLog(ex);
     }
 }
コード例 #17
0
        protected void Unnamed2_Click(object sender, EventArgs e)
        {
            string username = txtEmail.Text.Trim();
            string password = txtPass.Text.Trim();

            #region 验证邮箱有效性
            #endregion

            USR_CustomerMod m_user = USR_CustomerBll.GetInstance().CheckUser(username, password);
            if (m_user.SysNo != AppConst.IntNull)//COOKIES验证成功
            {
                SessionInfo m_session = new SessionInfo();
                m_session.CustomerEntity           = m_user;
                m_session.GradeEntity              = USR_GradeBll.GetInstance().GetModel(m_user.SysNo);
                Session[AppConfig.CustomerSession] = m_session;
                //记住我
                if (chkRemember.Checked)
                {
                    HttpCookie Cookie = CookiesHelper.GetCookie("upup1000");
                    if (Cookie == null || Cookie.Value == null || Cookie.Value == "")
                    {
                        Cookie = new HttpCookie("upup1000");
                        Cookie.Values.Add("uname", CommonTools.Encode(username));
                        Cookie.Values.Add("psd", CommonTools.Encode(password));
                        //设置Cookie过期时间
                        Cookie.Expires = DateTime.Now.AddYears(50);
                        CookiesHelper.AddCookie(Cookie);
                    }
                    else
                    {
                        CookiesHelper.SetCookie("upup1000", "uname", CommonTools.Encode(username), DateTime.Now.AddYears(50));
                        CookiesHelper.SetCookie("upup1000", "psd", CommonTools.Encode(password), DateTime.Now.AddYears(50));
                    }
                }
                LogManagement.getInstance().WriteTrace("前台会员登录", "Login", "IP:" + Request.UserHostAddress + "|AdminID:" + m_session.CustomerEntity.Email);
                //跳转
                Response.Redirect("Qin/View/" + m_user.SysNo);
            }
            else
            {
                Response.Redirect("Passport/Login.aspx?email=" + txtEmail.Text.Trim() + "&error=" + (int)AppEnum.ErrorType.WrongAccount);
            }
        }
コード例 #18
0
ファイル: LoginController.cs プロジェクト: lintsGitHub/YMOA
        /// <summary>
        /// 处理登录的信息
        /// </summary>
        /// <param name="userInfo"></param>
        /// <param name="CookieExpires">cookie有效期</param>
        /// <returns></returns>
        public ActionResult CheckUserLogin(UserEntity userInfo, string CookieExpires)
        {
            try
            {
                var iUserDal    = DALUtility.User;
                var currentUser = iUserDal.UserLogin(userInfo.AccountName, Md5.GetMD5String(userInfo.Password));
                if (currentUser != null)
                {
                    if (currentUser.IsAble == false)
                    {
                        return(Content("用户已被禁用,请您联系管理员"));
                    }
                    //记录登录cookie
                    CookiesHelper.SetCookie("UserID", AES.EncryptStr(currentUser.ID.ToString()));
                    //记录用户登录所在IP
                    LoginIpLogEntity logEntity = new LoginIpLogEntity();
                    string           ip        = CommFunc.Get_ClientIP();
                    if (string.IsNullOrEmpty(ip))
                    {
                        logEntity.IpAddress = "localhost";
                    }
                    else
                    {
                        logEntity.IpAddress = ip;
                    }
                    logEntity.CreateBy   = currentUser.AccountName;
                    logEntity.CreateTime = DateTime.Now;
                    logEntity.UpdateBy   = currentUser.AccountName;
                    logEntity.UpdateTime = DateTime.Now;
                    DALUtility.LoginIpLog.Add(logEntity);

                    return(Content("OK"));
                }
                else
                {
                    return(Content("用户名密码错误,请您检查"));
                }
            }
            catch (Exception ex)
            {
                return(Content("登录异常," + ex.Message));
            }
        }
コード例 #19
0
ファイル: Login.aspx.cs プロジェクト: qubianzhong/luckysign
        public void LoginCheck(string username, string password)
        {
            USR_CustomerMod m_user = USR_CustomerBll.GetInstance().CheckUser(username, password);

            if (m_user.SysNo != AppConst.IntNull)//COOKIES验证成功
            {
                SetSession(m_user);
                //记住我
                if (CheckBox1.Checked)
                {
                    HttpCookie Cookie = CookiesHelper.GetCookie("upup1000");
                    if (Cookie == null || Cookie.Value == null || Cookie.Value == "")
                    {
                        Cookie = new HttpCookie("upup1000");
                        Cookie.Values.Add("uname", CommonTools.Encode(username));
                        Cookie.Values.Add("psd", CommonTools.Encode(password));
                        //设置Cookie过期时间
                        Cookie.Expires = DateTime.Now.AddYears(50);
                        CookiesHelper.AddCookie(Cookie);
                    }
                    else
                    {
                        CookiesHelper.SetCookie("upup1000", "uname", CommonTools.Encode(username), DateTime.Now.AddYears(50));
                        CookiesHelper.SetCookie("upup1000", "psd", CommonTools.Encode(password), DateTime.Now.AddYears(50));
                    }
                }
                LogManagement.getInstance().WriteTrace("前台会员登录", "Login", "IP:" + Request.UserHostAddress + "|UserID:" + GetSession().CustomerEntity.Email);
                //跳转
                if (Request.QueryString["url"] != null && Request.QueryString["url"] != "")
                {
                    Response.Redirect(Request.QueryString["url"]);
                }
                else
                {
                    Response.Redirect("../Qin/View/" + m_user.SysNo);
                }
            }
            else
            {
                password1Tip.InnerHtml = AppEnum.GetErrorType(2);
            }
        }
コード例 #20
0
        public ActionResult Index(UserLogin model)
        {
            var result = new Result();

            try
            {
                if (string.IsNullOrEmpty(model.UserName))
                {
                    result.Msg = "用户名不能为空!";
                    return(Json(result));
                }
                if (string.IsNullOrEmpty(model.PassWord))
                {
                    result.Msg = "密码不能为空!";
                    return(Json(result));
                }
                var userLogin = new User {
                    AccountName = model.UserName, PassWord = Md5.GetMD5String(model.PassWord)
                };

                if (!new UserBLL().ValidateUser(userLogin))
                {
                    result.Msg = "用户名或者密码错误!";
                    return(Json(result));
                }
                var user = new UserBLL().GetUserByName(model.UserName);
                if (!user.IsAble)
                {
                    result.Msg = "此用户已禁用!";
                    return(Json(result));
                }
                CookiesHelper.SetCookie("UserID", AES.EncryptStr(user.Id.ToString()));
                result.Success = true;
                return(Json(result));
            }
            catch
            {
                result.Msg = "登录超时!";
                return(Json(result));
            }
        }
コード例 #21
0
ファイル: Login.aspx.cs プロジェクト: qubianzhong/luckysign
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Request.QueryString["type"] == "logout")
         {
             Session[AppConfig.CustomerSession] = null;
             HttpCookie Cookie = CookiesHelper.GetCookie("upup1000");
             if (Cookie != null && Cookie.Value != null && Cookie.Value != "")
             {
                 CookiesHelper.SetCookie("upup1000", "uname", "", DateTime.Now.AddYears(-1));
                 CookiesHelper.SetCookie("upup1000", "psd", "", DateTime.Now.AddYears(-1));
             }
         }
         else if (Request.QueryString["error"] != null && Request.QueryString["error"] != "")
         {
             try
             {
                 email.Text             = Request.QueryString["email"];
                 password1Tip.InnerText = AppEnum.GetErrorType(int.Parse(Request.QueryString["error"]));
                 return;
             }
             catch
             { }
         }
         try
         {
             if (Request.Cookies["upup1000"]["uname"] != null && Request.Cookies["upup1000"]["uname"] != string.Empty &&
                 Request.Cookies["upup1000"]["psd"] != null && Request.Cookies["upup1000"]["psd"] != string.Empty)
             {
                 string username = CommonTools.Decode(Request.Cookies["upup1000"]["uname"]);
                 string password = CommonTools.Decode(Request.Cookies["upup1000"]["psd"]);
                 LoginCheck(username, password);
                 Response.Cache.SetCacheability(HttpCacheability.NoCache);
             }
         }
         catch { }
         Unnamed1.Focus();
     }
 }
コード例 #22
0
 private bool SetCookie(string name, string pwd)
 {
     //下次自动登录
     if (CheckBox1.Checked == true)
     {
         if (!Convert.ToBoolean(hfIsEnableCookie.Value))
         {
             // Response.Write("<script language='javascript'>alert('提示!您的浏览器不接受cookie,将影响一些功能的正常使用,请将浏览器cookie启用!')</script>");
             msg.InnerHtml = "【友情提示】:您的浏览器不接受cookie,将影响一些功能的正常使用,请将浏览器cookie启用!";
             return(false);
         }
         else
         {
             HttpCookie Cookie = CookiesHelper.GetCookie("UserInfo");
             if (Cookie == null)
             {
                 Cookie = new HttpCookie("UserInfo");
                 Cookie.Values.Add("userName", name);
                 Cookie.Values.Add("usertPwd", pwd);
                 //设置Cookie过期时间
                 Cookie.Expires = DateTime.Now.AddMonths(1);//DateTime.Now.AddDays(365);
                 CookiesHelper.AddCookie(Cookie);
             }
             else if (!Cookie.Values["userName"].Equals(name) || !Cookie.Values["usertPwd"].Equals(pwd))
             {
                 CookiesHelper.SetCookie("UserInfo", "userName", name);
                 CookiesHelper.SetCookie("UserInfo", "usertPwd", pwd);
             }
             return(true);
         }
     }
     else
     {
         CookiesHelper.RemoveCookie("UserInfo");
         HttpCookie Cookie = CookiesHelper.GetCookie("UserInfo");
         int        a      = Request.Cookies.Count;
         return(true);
     }
 }
コード例 #23
0
        void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
        {
            var locale = AppConfig.DefaultLocale;
            var now    = Util.Utilities.DateTimeNow();

            if (!string.IsNullOrWhiteSpace(filterContext.HttpContext.Request.QueryString["Lang"]))
            {
                locale = filterContext.HttpContext.Request.QueryString["Lang"];
            }
            else
            {
                locale = CookiesHelper.GetCookie(Constants.Keys.CurrentCultureCookieKey) ?? AppConfig.DefaultLocale;
            }

            CookiesHelper.SetCookie(Constants.Keys.CurrentCultureCookieKey, locale, now.AddYears(1));

            CookiesHelper.SetCookie(Constants.Keys.CurrentCultureDirectionCookieKey, LanguageHelper.GetLocaleDirection(locale), now.AddYears(1));

            filterContext.HttpContext.Session[Constants.Keys.CurrentCultureSessionKey] = locale;

            this.OnActionExecuting(filterContext);
        }
コード例 #24
0
        public ActionResult StudentLogin(string name, string pwd)
        {
            try
            {
                var Pwd    = Md5Helper.MD5Encoding(pwd, 123);
                var result = student_BLL.StudentLogin(name, Pwd);
                if (result != null)
                {
                    FormsAuthentication.SetAuthCookie(name, true);

                    GetOnline(name);

                    CookiesHelper.SetCookie("SId", HttpUtility.UrlEncode(JsonConvert.SerializeObject(result)), DateTime.Now.AddDays(7));
                    return(Redirect("~/Exam/Index"));
                }
                return(Redirect("/Exam/Login"));
            }
            catch (Exception ex)
            {
                ErrorLog.WriteLog(ex);
                return(null);
            }
        }
コード例 #25
0
 /// <param name="CookieExpires">cookie有效期</param>
 /// <returns></returns>
 public ActionResult CheckUserLogin(string CookieExpires)
 {
     try
     {
         var iUserDal    = DALUtility.User;
         var currentUser = iUserDal.UserLogin(Request["user_AN"], Request["user_pwd"]);
         if (currentUser != null)
         {
             //记录登录cookie
             CookiesHelper.SetCookie("UserID", AES.EncryptStr(currentUser.id.ToString()));
             Dictionary <string, object> paras = new Dictionary <string, object>();
             paras["r_id"] = currentUser.RoleID;
             var roleMenus = DALUtility.RoleMenu.QryRoleMenu <Navbar>(paras);
             Session["RoleMenu"] = roleMenus;
             Session["RoleID"]   = currentUser.RoleID;
             Session["User"]     = currentUser;
             DateTime dateTime = DateTime.Now;
             Session["LoginTime"] = dateTime;
             Hashtable htOnline = (Hashtable)System.Web.HttpContext.Current.Application["CurrentOnline"];
             if (htOnline == null)
             {
                 htOnline = new Hashtable();
             }
             htOnline[Session["User"].ToString()] = dateTime;
             return(OperationReturn(true, "登录成功!"));
         }
         else
         {
             return(OperationReturn(false, "登录失败!用户名或者密码错误!"));
         }
     }
     catch (Exception ex)
     {
         return(OperationReturn(false, "登录异常," + ex.Message));
     }
 }
コード例 #26
0
        public JsonResult Login(BlogUsersSet user, string ischeck)
        {
            JSData objJson = new JSData();
            //var listUser = CacheData.GetAllUserInfo().Where(t => (t.UserName == user.UserName || t.UserMail == user.UserName) && t.UserPass == user.UserPass.MD5().MD5());
            var pass     = user.UserPass.MD5().MD5();
            var listUser = GetDataHelper.GetAllUser(t => t.UserInfo).Where(t => (t.UserName == user.UserName || t.UserMail == user.UserName) && t.UserPass == pass);

            if (listUser.Count() > 0)
            {
                Session[tempUserinfo] = listUser.FirstOrDefault();

                #region 1.验证邮箱是否有效  无效则跳转到邮箱验证页面
                if (listUser.Where(t => t.UserMail == "无效" || string.IsNullOrEmpty(t.UserMail)).Count() > 0)
                {
                    objJson.State = EnumState.失败;
                    objJson.Messg = "检测到你注册的邮箱无效~请输入正确的邮箱~";
                    objJson.JSurl = "/UserManage/EmailValidation";
                }
                #endregion

                #region 2.用户是否是激活状态 否:发送激活码 并跳转到激活页面
                else if (listUser.Where(t => t.IsLock == true).Count() > 0)
                {
                    //邮件发送激活码
                    //JSData jsdata;
                    GetActivate(out objJson);
                    //return Json(jsdata);
                }
                #endregion

                #region 3.登录成功
                else
                {
                    //  var objuser = GetDataHelper.GetAllUser(t => t.UserInfo).Where(t => t.UserName == lodname.Trim() && t.UserPass == lodpass.Trim().MD5().MD5() && t.IsLock == false).FirstOrDefault();

                    BLLSession.UserInfoSessioin = listUser.FirstOrDefault();  //Messg = "登录成功",  //不给提示     直接跳转
                    objJson.State = EnumState.正常重定向;
                    if (!string.IsNullOrEmpty(Request.QueryString["href"]))
                    {
                        objJson.JSurl = Request.QueryString["href"];
                    }
                    else
                    {
                        objJson.JSurl = "/";
                    }
                    if (ischeck == "on")
                    {
                        //Helper.CookiesHelper.AddCookie("hib_name", user.UserName);
                        //Helper.CookiesHelper.AddCookie("hib_pass", user.UserPass);

                        HttpCookie Cookie = CookiesHelper.GetCookie("userInfo");
                        if (Cookie == null)
                        {
                            Cookie = new HttpCookie("userInfo");
                            Cookie.Values.Add("userName", user.UserName);
                            Cookie.Values.Add("userPass", user.UserPass);
                            //设置Cookie过期时间
                            Cookie.Expires = DateTime.Now.AddDays(365);
                            CookiesHelper.AddCookie(Cookie);
                        }
                        else
                        {
                            if (!Cookie.Values["userName"].Equals(user.UserName))
                            {
                                CookiesHelper.SetCookie("userInfo", "userName", user.UserName);
                            }
                            if (!Cookie.Values["userPass"].Equals(user.UserPass))
                            {
                                CookiesHelper.SetCookie("userInfo", "userPass", user.UserPass);
                            }
                        }
                    }
                    else
                    {
                        Helper.CookiesHelper.RemoveCookie("userInfo");
                    }
                }
                #endregion
            }
            else
            {
                objJson.Messg = "用户名或密码错误~";
                objJson.State = EnumState.失败;
            }
            return(Json(objJson)); //json;
        }
コード例 #27
0
        /// <summary>
        /// 根据博客id 获取博客
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public Dictionary <string, object> GetUserBlog(string name, int id)
        {
            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();

            #region 优化前
            //var blogobj = blog.GetList(t => t.Id == id && t.Users.UserName == name).FirstOrDefault();

            ////这里看 能不能只查询一次
            //var blogNext = blog.GetList(t => t.Id > id && t.Users.UserName == name).OrderBy(t => t.Id).FirstOrDefault();
            //var blogLast = blog.GetList(t => t.Id < id && t.Users.UserName == name).OrderBy(t => t.Id).FirstOrDefault();
            #endregion

            //优化后 只查一次数据库
            //比如id 为3 那么 last取3,4  next取2,3
            var last = blog.GetList(t => t.Id >= id && t.User.UserName == name, isAsNoTracking: false, tableName: t => t.User).OrderBy(t => t.Id).Take(2);
            var next = blog.GetList(t => t.Id <= id && t.User.UserName == name, isAsNoTracking: false, tableName: t => t.User).OrderByDescending(t => t.Id).Take(2);
            //去重复合并
            var blogUnion = (from c in last select c).Union(from a in next select a).ToList();

            var blogNext = blogUnion.Where(t => t.Id > id).FirstOrDefault();
            var blogLast = blogUnion.Where(t => t.Id < id).FirstOrDefault();
            var blogobj  = blogUnion.Where(t => t.Id == id).FirstOrDefault();

            Dictionary <string, object> dic = new Dictionary <string, object>();
            dic.Add("blog", blogobj);
            dic.Add("blogNext", blogNext);
            dic.Add("blogLast", blogLast);
            dic.Add("contentBlogType", blogobj.Types == null ? new List <BlogType>() : blogobj.Types.ToList()); //当前博客所属的类型
            dic.Add("contentBlogTag", blogobj.Tags == null ? new List <BlogTag>() : blogobj.Tags.ToList());     //当前博客所有的tag标签

            //Description 网页描述
            var BlogContent = MyHtmlHelper.GetHtmlText(blogobj.Content);
            BlogContent = BlogContent.Length >= 300 ? BlogContent.Substring(0, 300) : BlogContent;
            dic.Add("blogConText", BlogContent);

            SetDic(dic, name);

            #region 保存 标记 此文已经阅读过
            var        BlogReadInfo = "BlogReadInfo";
            HttpCookie Cookie       = CookiesHelper.GetCookie(BlogReadInfo);
            if (null == Cookie)
            {
                Cookie = new HttpCookie(BlogReadInfo);
                Cookie.Values.Add(blogobj.Id.ToString(), "true");
                //设置Cookie过期时间
                Cookie.Expires = DateTime.Now.AddHours(24);//一天
                CookiesHelper.AddCookie(Cookie);
                //........................异步调用....................
                new SaveReadDelegate(SaveReadNum).BeginInvoke(blogobj, GetUserDistinguish(Request), null, null);
            }
            else
            {
                if (Cookie.Values[blogobj.Id.ToString()] == null || !Cookie.Values[blogobj.Id.ToString()].Equals("true"))
                {
                    CookiesHelper.SetCookie(BlogReadInfo, blogobj.Id.ToString(), "true");
                    //........................异步调用....................
                    new SaveReadDelegate(SaveReadNum).BeginInvoke(blogobj, GetUserDistinguish(Request), null, null);
                }
            }
            #endregion

            return(dic);
        }
コード例 #28
0
ファイル: micrologin.aspx.cs プロジェクト: lvxiangjun1/hqweb
    protected void ibLogin_Click(object sender, ImageClickEventArgs e)
    {
        string name     = txtUSERNAME.Text;
        string password = txtPassword.Text;

        if ("".Equals(name))
        {
            return;
        }
        if ("".Equals(password))
        {
            return;
        }
        string UserName        = name;
        string ConfirmPassword = Names.EncryptPassword(password);

        if (la.ChkAdminExit(UserName, ConfirmPassword))
        {
            DataTable DT = la.GetAdminInfo(UserName);
            if (DT.Rows.Count == 0)
            {
                MessageBox("该用户不存在!");
                return;
            }
            else if (DT.Rows[0]["NB_ZT"].ToString() == "0")
            {
                MessageBox("该用户已无效!");
                return;
            }
            else
            {
                HttpCookie Cookie = CookiesHelper.GetCookie(SiteInfo.CookieName());
                if (Cookie == null)
                {
                    Cookie = new HttpCookie(SiteInfo.CookieName());
                    Cookie.Values.Add("UserId", DT.Rows[0]["NB_ID"].ToString());
                    Cookie.Values.Add("UserName", DT.Rows[0]["VAR_ZH"].ToString());
                    Cookie.Values.Add("Password", DT.Rows[0]["VAR_MM"].ToString());
                    Cookie.Values.Add("NickName", DT.Rows[0]["VAR_NICK_NAME"].ToString());
                    //设置Cookie过期时间
                    Cookie.Expires = DateTime.Now.AddDays(1);
                    CookiesHelper.AddCookie(Cookie);
                }
                if (Cookie.Values.Count <= 0)
                {
                    Cookie = new HttpCookie(SiteInfo.CookieName());
                    Cookie.Values.Add("UserId", DT.Rows[0]["NB_ID"].ToString());
                    Cookie.Values.Add("UserName", DT.Rows[0]["VAR_ZH"].ToString());
                    Cookie.Values.Add("Password", DT.Rows[0]["VAR_MM"].ToString());
                    Cookie.Values.Add("NickName", DT.Rows[0]["VAR_NICK_NAME"].ToString());
                    //设置Cookie过期时间
                    Cookie.Expires = DateTime.Now.AddDays(1);
                    CookiesHelper.AddCookie(Cookie);
                }
                else if ((!Cookie.Values["UserName"].Equals(DT.Rows[0]["VAR_ZH"].ToString())) || (!Cookie.Values["Password"].Equals(DT.Rows[0]["VAR_MM"].ToString())))
                {
                    CookiesHelper.SetCookie(SiteInfo.CookieName(), "UserId", DT.Rows[0]["NB_ID"].ToString());
                    CookiesHelper.SetCookie(SiteInfo.CookieName(), "UserName", DT.Rows[0]["VAR_ZH"].ToString());
                    CookiesHelper.SetCookie(SiteInfo.CookieName(), "Password", DT.Rows[0]["VAR_MM"].ToString());
                    CookiesHelper.SetCookie(SiteInfo.CookieName(), "NickName", DT.Rows[0]["VAR_NICK_NAME"].ToString());
                }
                lbNICK_NAME.Text = DT.Rows[0]["VAR_NICK_NAME"].ToString();

                pnlCookie.Visible = true;
                pnlLogin.Visible  = false;
                return;
            }
        }
        else
        {
            MessageBox("用户名或密码错误!");
            return;
        }
    }
コード例 #29
0
 public void Logout()
 {
     CookiesHelper.SetCookie("Employee", "", DateTime.Now.AddDays(-111));
     CookiesHelper.SetCookie("EmployeeName", "", DateTime.Now.AddDays(-111));
     System.Web.HttpContext.Current.Session.RemoveAll();
 }
コード例 #30
0
    protected void Login_Click(object sender, EventArgs e)
    {
        string Account = this.account.Value.Trim();
        string Password = this.password.Text;
        //string Password = this.password.Value.Trim();
        //string Password = "******";
        rolename = text1.InnerText.ToString();
        if (Account != String.Empty && Password != String.Empty)
        {

            if (rolename == "管理员")
            {
                string sql = "select * from Manager where ManagerName = '" + Account + "' and ManagerPassword = '******'";
                SqlConnection con = new SqlConnection(connStr);
                con.Open();
                SqlDataAdapter sdr = new SqlDataAdapter(sql, con);
                DataSet ds = new DataSet();
                sdr.Fill(ds, "Manager");
                if (ds.Tables[0].Rows.Count == 1)
                {
                    if (remME.Checked)
                    //if (!string.IsNullOrEmpty(Request["remME"]))
                    {
                        HttpCookie Cookie = CookiesHelper.GetCookie("UserInfo");
                        if (Cookie == null)
                        {
                            Cookie = new HttpCookie("UserInfo");
                            Cookie.Values.Add("uName", Account);
                            Cookie.Values.Add("uPassword", Password);
                            //设置Cookie过期时间
                            Cookie.Expires = DateTime.Now.AddDays(365);
                            CookiesHelper.AddCookie(Cookie);
                        }
                        else if (!Cookie.Values["uName"].Equals(Account))
                            CookiesHelper.SetCookie("UserInfo", "uName", Account);
                        else if (!Cookie.Values["uPassword"].Equals(Password))
                        {
                            CookiesHelper.SetCookie("UserInfo", "uPassword", Password);
                        }
                    }
                    Response.Write("<script>alert('登陆成功!');</script>");
                    Session["UserID"] = ds.Tables[0].Rows[0]["managerid"].ToString();
                    Session["Laccount"]=Account;
                    Session["Lpassword"] = Password;
                    Response.Redirect("index.aspx", true);
                }

                else
                {
                    string sql1 = "select * from Manager where ManagerAccount = '" + Account + "' and ManagerPassword = '******'";
                    //SqlConnection con = new SqlConnection(connStr);
                    //con.Open();
                    SqlDataAdapter sdr1 = new SqlDataAdapter(sql1, con);
                    DataSet ds1 = new DataSet();
                    sdr1.Fill(ds1, "Manager");
                    if (ds1.Tables[0].Rows.Count == 1)
                    {
                        if (remME.Checked)
                        //if (!string.IsNullOrEmpty(Request["remME"]))
                        {
                            HttpCookie Cookie = CookiesHelper.GetCookie("UserInfo");
                            if (Cookie == null)
                            {
                                Cookie = new HttpCookie("UserInfo");
                                Cookie.Values.Add("uName", Account);
                                Cookie.Values.Add("uPassword", Password);
                                //设置Cookie过期时间
                                Cookie.Expires = DateTime.Now.AddDays(365);
                                CookiesHelper.AddCookie(Cookie);
                            }
                            else if (!Cookie.Values["uName"].Equals(Account))
                                CookiesHelper.SetCookie("UserInfo", "uName", Account);
                            else if (!Cookie.Values["uPassword"].Equals(Password))
                            {
                                CookiesHelper.SetCookie("UserInfo", "uPassword", Password);
                            }
                        }
                        Session["Laccount"] = Account;
                        Session["Lpassword"] = Password;
                        Session["UserID"] = ds.Tables[0].Rows[0]["managerid"].ToString();
                        Response.Write("<script>alert('登陆成功!');</script>");
                        Response.Redirect("index.aspx", true);
                    }
                    else
                    {
                        Response.Write("<script>alert('用户名或密码错误!');</script>");
                        Response.Redirect("Login.aspx", true);
                    }
                }
            }
            else if (rolename == "学员")
            {
                string sql = "select * from Student where StudentName = '" + Account + "' and StudentPassword = '******'";
                SqlConnection con = new SqlConnection(connStr);
                con.Open();
                SqlDataAdapter sdr = new SqlDataAdapter(sql, con);
                DataSet ds = new DataSet();
                sdr.Fill(ds, "Student");
                if (ds.Tables[0].Rows.Count == 1)
                {
                    if (remME.Checked)
                    //if (!string.IsNullOrEmpty(Request["remME"]))
                    {
                        HttpCookie Cookie = CookiesHelper.GetCookie("UserInfo");
                        if (Cookie == null)
                        {
                            Cookie = new HttpCookie("UserInfo");
                            Cookie.Values.Add("uName", Account);
                            Cookie.Values.Add("uPassword", Password);
                            //设置Cookie过期时间
                            Cookie.Expires = DateTime.Now.AddDays(7);
                            CookiesHelper.AddCookie(Cookie);
                        }
                        else if (!Cookie.Values["uName"].Equals(Account))
                            CookiesHelper.SetCookie("UserInfo", "uName", Account);
                        else if (!Cookie.Values["uPassword"].Equals(Password))
                        {
                            CookiesHelper.SetCookie("UserInfo", "uPassword", Password);
                        }
                    }
                    Session["Laccount"] = Account;
                    Session["Lpassword"] = Password;
                    Session["UserID"] = ds.Tables[0].Rows[0]["managerid"].ToString();
                    Response.Write("<script>alert('登陆成功!');</script>");
                    Response.Redirect("index.aspx", true);
                }
                else
                {
                    string sql1 = "select * from Student where Telephone = '" + Account + "' and StudentPassword = '******'";
                    SqlDataAdapter sdr1 = new SqlDataAdapter(sql1, con);
                    DataSet ds1 = new DataSet();
                    sdr1.Fill(ds1, "Student");
                    if (ds1.Tables[0].Rows.Count == 1)
                    {
                        if (remME.Checked)
                        //if (!string.IsNullOrEmpty(Request["remME"]))
                        {
                            HttpCookie Cookie = CookiesHelper.GetCookie("UserInfo");
                            if (Cookie == null)
                            {
                                Cookie = new HttpCookie("UserInfo");
                                Cookie.Values.Add("uName", Account);
                                Cookie.Values.Add("uPassword", Password);
                                //设置Cookie过期时间
                                Cookie.Expires = DateTime.Now.AddDays(365);
                                CookiesHelper.AddCookie(Cookie);
                            }
                            else if (!Cookie.Values["uName"].Equals(Account))
                                CookiesHelper.SetCookie("UserInfo", "uName", Account);
                            else if (!Cookie.Values["uPassword"].Equals(Password))
                            {
                                CookiesHelper.SetCookie("UserInfo", "uPassword", Password);
                            }
                        }
                        Session["Laccount"] = Account;
                        Session["Lpassword"] = Password;
                        Session["UserID"] = ds.Tables[0].Rows[0]["managerid"].ToString();
                        Response.Write("alert('登陆成功!');</script>");
                        Response.Redirect("index.aspx", true);
                    }
                    else
                    {
                        Response.Write("<script>alert('用户名或密码错误!');</script>");
                        Response.Redirect("Login.aspx", true);
                    }
                }
            }
            else
            {
                Response.Write("<script>alert('请您选择角色!');</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('用户名和密码不可为空!');</script>");
        }
    }