Exemple #1
0
        /// <summary>
        /// 新增或修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddOrUpdate(oyxf.Model.UserInfo model)
        {
            if (model.UserId <= 0)
            {
                //新增
                if (Add(model) > 0)
                {
                    return(true);
                }
            }
            else
            {
                //修改
                if (string.IsNullOrWhiteSpace(model.Password))//是否修改密码
                {
                    //不修改密码
                    return(dal.Update(model, false));
                }
                else
                {
                    //修改密码
                    return(dal.Update(model, true));
                }
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 验证Cookie
        /// </summary>
        private void CheckCookie()
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[Key.COOKIE_CURRENTUSER];

            if (cookie == null)
            {
                ScriptHelper.AlertRedirect("您还未登录", "/login.aspx");
                return;
            }
            if (string.IsNullOrWhiteSpace(cookie.Value))
            {
                ScriptHelper.AlertRedirect("您还未登录", "/login.aspx");
                return;
            }
            string UserIdStr = CryptoHelper.TripleDES_Decrypt(cookie.Value, Key.TRIPLEDES_KEY);

            if (!UserIdStr.IsNumber())
            {
                ScriptHelper.AlertRedirect("您还未登录", "/login.aspx");
                return;
            }
            int userid = Convert.ToInt32(UserIdStr);

            UserInfoBll bll = new UserInfoBll();

            oyxf.Model.UserInfo ui = bll.GetModel(userid);
            if (ui == null)
            {
                ScriptHelper.AlertRedirect("您还未登录", "/login.aspx");
                return;
            }
            HttpContext.Current.Session[Key.SESSION_CURRENTUSER] = ui;
        }
Exemple #3
0
        /// <summary>
        /// 用户名是否已存在
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool IsExistUsername(oyxf.Model.UserInfo model)
        {
            if (dal.GetUsernameCount(model) > 0)
            {
                return(true);
            }

            return(false);
        }
Exemple #4
0
        /// <summary>
        /// 生成Cookie
        /// </summary>
        /// <param name="autologin"></param>
        /// <param name="ui"></param>
        private void GenerateCookie(string autologin, oyxf.Model.UserInfo ui)
        {
            if (autologin == "false")
            {
                return;
            }
            HttpCookie cookie = new HttpCookie(Key.COOKIE_CURRENTUSER, CryptoHelper.TripleDES_Encrypt(ui.UserId.ToString(), Key.TRIPLEDES_KEY));

            cookie.Expires = DateTime.Now.AddDays(1);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
Exemple #5
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string username  = context.Request.Form["username"];
            string password  = context.Request.Form["password"];
            string checkcode = context.Request.Form["checkcode"].ToUpper();
            string autologin = context.Request.Form["autologin"];

            string checkcodeSession = context.Session[Key.CAPTCHA].ToString().ToUpper();

            //1.合法性判断

            //2.验证码是否正确
            if (!checkcode.Equals(checkcodeSession))
            {
                AjaxHelper.WriteError(msg: "验证码错误");
            }

            //3.账号密码是否正确
            UserInfoBll bll = new UserInfoBll();

            oyxf.Model.UserInfo ui = bll.GetModel(username);
            if (ui == null)
            {
                AjaxHelper.WriteError(msg: "账号或密码不正确");
            }
            if (ui.Status == 0)
            {
                AjaxHelper.WriteError(msg: "该用户已被禁用");
            }

            //4.Session
            context.Session[Key.SESSION_CURRENTUSER] = ui;

            //5.Cookie
            GenerateCookie(autologin, ui);

            AjaxHelper.WriteSuccess();
        }
Exemple #6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(oyxf.Model.UserInfo model)
 {
     return(dal.Update(model));
 }
Exemple #7
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(oyxf.Model.UserInfo model)
 {
     return(dal.Add(model));
 }