Exemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
         if (Request.Form["u_username"] == "" || Request.Form["u_password"] == "")
         {
             runClientScript("addError", "parent.layer.msg('用户名或密码为空!', { time: 2500 });closeLayer();");
             return;
         }
         T_user user = new T_user()
         {
             u_username = Request.Form["u_username"].Trim(),
             u_password = md5.MD5Encrypt(Request.Form["u_password"].Trim(), md5.GetKey()),
             u_actor    = Request.Form["actor"].Trim()
         };
         dataContext.T_users.InsertOnSubmit(user);
         try
         {
             dataContext.SubmitChanges();
             runClientScript("addOK", "parent.layer.msg('用户添加成功!', { time: 2500 });closeLayer();");
         }
         catch (Exception catchMessage)
         {
             runClientScript("addError", "parent.layer.msg('服务器失败:" + catchMessage.Message + "', { time: 2500 });closeLayer();");
         }
     }
 }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string re = "true";

            if (context.Request["username"] != null)
            {
                T_user s = dataContext.T_users.Where(u => u.u_username == context.Request["username"].ToString()).SingleOrDefault();
                if (s != null)
                {
                    re = "false";
                }
            }
            context.Response.Write(re);
        }
Exemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         //初始化
         string u_id = Request["u_id"] != null ? Request["u_id"].ToString() : "-1";
         T_user user = udb.T_users.Where(u => u.u_id == Int32.Parse(u_id)).SingleOrDefault();
         if (user == null)
         {
             return;
         }
         u_username.Value = user.u_username;
         hfU_id.Value     = u_id;
         runClientScript("radioCheck", "$('input[value=" + user.u_actor + "]').attr(\"checked\",\"true\");");
         //$('input[value=user]').attr("checked","true");
     }
     else
     {
         //保存
         string u_id = hfU_id.Value;
         if (Request.Form["u_password"].ToString().Trim() == "")
         {
             runClientScript("addError", "parent.layer.msg('用户名或密码不能为空!', { time: 2500 });");
             return;
         }
         T_user user = udb.T_users.Where(u => u.u_id == Int32.Parse(u_id)).SingleOrDefault();
         if (Request.Form["u_old_password"].ToString() != md5.MD5Decrypt(user.u_password, md5.GetKey()))
         {
             runClientScript("addError", "parent.layer.msg('原始密码错误!', { time: 2500 });");
             return;
         }
         user.u_password = md5.MD5Encrypt(Request.Form["u_password"].ToString().Trim(), md5.GetKey());
         try
         {
             udb.SubmitChanges();
             runClientScript("addOK", "parent.layer.msg('修改成功!', { time: 2500 });closeLayer();");
         }
         catch (Exception exc)
         {
             runClientScript("addError", "parent.layer.msg('修改失败:'" + exc.Message + ", { time: 2500 });");
         }
     }
 }
Exemplo n.º 4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Request.Form["username"] == "" || Request.Form["password"] == "")
            {
                App_RegisterClientScriptBlock("infoMessage", "错误", "用户名或密码为空!");
                return;
            }
            T_user user = new T_user()
            {
                u_username = Request.Form["username"],
                u_password = md5.MD5Encrypt(Request.Form["password"], md5.GetKey()),
                u_actor    = Request.Form["select_actor"]
            };

            dataContext.T_users.InsertOnSubmit(user);
            try
            {
                dataContext.SubmitChanges();
                App_RegisterClientScriptBlock("infoMessage", "提示", "用户" + Request.Form["username"] + "添加成功!");
            }
            catch (Exception catchMessage)
            {
                App_RegisterClientScriptBlock("infoMessage", "错误", "用户添加失败,请重试!错误代码:" + catchMessage.Message);
            }


            //ado.net模式
            //string sqlAdd = "insert into T_user values(@username,@password,@actor)";

            //if (Sqlhelper.ExcuteNonQuery(sqlAdd, new SqlParameter("username", Request.Form["username"]), new SqlParameter("password", md5.MD5Encrypt(Request.Form["password"], md5.GetKey())), new SqlParameter("actor", Request.Form["select_actor"])) > 0)
            //{
            //    App_RegisterClientScriptBlock("infoMessage", "提示", "用户" + Request.Form["username"] + "添加成功!");
            //}
            //else
            //{
            //    App_RegisterClientScriptBlock("infoMessage", "错误", "用户" + Request.Form["username"] + "添加失败,请重试!");
            //}
        }
Exemplo n.º 5
0
        protected void btn_login_Click(object sender, EventArgs e)
        {
            string username = txt_count.Text.Trim();
            string password = txt_pass.Text.Trim();

            if (username == "" || password == "")
            {
                App_RegisterClientScriptBlock("infoMessage", "错误", "帐号或密码不能为空!");
                return;
            }

            password = md5.MD5Encrypt(password, md5.GetKey());
            T_user user = dataContext.T_users.SingleOrDefault(u => u.u_username == username && u.u_password == password);

            if (user == null)
            {
                App_RegisterClientScriptBlock("infoMessage", "错误", "帐号或密码错误,请重试!");
            }
            else
            {
                Response.Redirect("main.aspx", false);
            }
        }
Exemplo n.º 6
0
        public JsonResult userRegister(string name, string pwd, string rePwd)
        {
            //var s = new
            //{
            //    userName = name,
            //    userPassword = pwd,
            //    userPowerId = 2,
            //    userClose = 0
            //};

            var obj = new
            {
                msg  = "注册失败",
                code = 201
            };

            if (string.IsNullOrEmpty(name))
            {
                obj = new
                {
                    msg  = "用户名不能为空",
                    code = 203
                };
                return(Json(obj));
            }
            if (string.IsNullOrEmpty(pwd))
            {
                obj = new
                {
                    msg  = "密码不能为空",
                    code = 204
                };
                return(Json(obj));
            }


            if (string.IsNullOrEmpty(rePwd))
            {
                obj = new
                {
                    msg  = "再次输入密码不能为空",
                    code = 205
                };
                return(Json(obj));
            }
            if (pwd != rePwd)
            {
                obj = new
                {
                    msg  = "两次输入密码不一样",
                    code = 206
                };
                return(Json(obj));
            }
            GoShoesDBEntities db = new GoShoesDBEntities();
            var abc = db.T_user.Where(c => c.userName == name).FirstOrDefault();

            if (abc != null)
            {
                obj = new
                {
                    msg  = "注册失败,用户存在",
                    code = 202
                };
                return(Json(obj));
            }
            T_user s = new T_user();

            s.userName     = name;
            s.userPassword = pwd;
            s.userPowerId  = 2;
            s.userClose    = 0;
            db.T_user.Add(s);
            int rs = db.SaveChanges();

            if (rs > 0)
            {
                obj = new { msg = "注册成功", code = 200 }
            }
            ;

            var ss = db.T_user.Where(c => c.userName == s.userName).FirstOrDefault();

            HttpContext.Cache["c_User"] = s;

            return(Json(obj));
        }
    }