示例#1
0
 public JsonResult ChangePassword(string oldPassword, string newPassword)
 {
     if (string.IsNullOrEmpty(oldPassword))
     {
         return(Json(new { Error = 1, Message = "請輸入舊密碼" }));
     }
     if (string.IsNullOrEmpty(newPassword))
     {
         return(Json(new { Error = 1, Message = "請輸入新密碼" }));
     }
     try
     {
         var          oldPass      = MD5Hash.GetMd5String(oldPassword);
         AdminUserBLL adminUserBll = new AdminUserBLL();
         var          oriPass      = adminUserBll.GetPassHashByUserID(UserID);
         if (!string.Equals(oriPass, oldPass, StringComparison.OrdinalIgnoreCase))
         {
             return(Json(new { Error = 1, Message = "舊密碼錯誤" }));
         }
         var flag = adminUserBll.UpdatePassWordByUserID(UserID, newPassword);
         if (flag)
         {
             return(Json(new { Error = 0 }));
         }
         else
         {
             return(Json(new { Error = 1, Message = "密碼修改失敗" }));
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
         return(Json(new { Error = 1, Message = ex.Message }));
     }
 }
示例#2
0
 /// <summary>
 /// 判断管理员是否已经登录(解决Session超时问题)
 /// </summary>
 public bool IsAdminLogin()
 {
     //如果Session不为Null
     if (Session["admin_userid"] != null && Session["issystem"] != null && Session["Permissions"] != null)
     {
         return(true);
     }
     else
     {
         //检查Cookies
         string adminname = Utils.GetCookie("AdminName", "FZtouch"); //解密用户名
         string adminpwd  = Utils.GetCookie("AdminPwd", "FZtouch");
         if (adminname != "" && adminpwd != "")
         {
             adminname = DESEncrypt.Decrypt(adminname); //解密用户名
             AdminUserBLL bll  = new AdminUserBLL();
             AdminUser    item = bll.UserLogin(adminname, adminpwd);
             if (item != null)
             {
                 Session["admin_userid"] = item.Id;
                 Session["issystem"]     = item.IsSystem;
                 Session["Permissions"]  = bll.GetPermissionsByUserID(item.Id);
                 return(true);
             }
         }
     }
     return(false);
 }
 protected void btncreateuser_Click(object sender, EventArgs e)
 {
     //创建用户的操作
     if (CheckInputForCreate())
     {
         AdminUser user = new AdminUser();
         user.ID              = AdminUserBLL.GetMaxId() + 1;//注意获取最大ID后使用时要在ID基础上+1
         user.UserID          = textboxUserId.Text;
         user.UserPwd         = MD5PWD.EnCode(textboxPwd.Text);
         user.UserCreatedDate = DateTime.Now;
         if (AdminUserBLL.CheckUserId(textboxUserId.Text))
         {
             if (AdminUserBLL.Add(user) != null)
             {
                 JqHelper.ResponseScript("alert(\"创建用户成功!\")");
                 GetAdmins();
             }
             else
             {
                 JqHelper.ResponseScript("alert(\"创建失败,请重新尝试!\")");
             }
         }
         else
         {
             JqHelper.ResponseScript("alert(\"该用户名已经被使用请更换一个!\")");
             textboxUserId.Text = "";
             textboxPwd.Text    = "";
             textboxUserId.Focus();
         }
     }
 }
示例#4
0
        protected void Unnamed_ServerClick(object sender, EventArgs e)
        {
            UserBLL      User      = new UserBLL();
            AdminUserBLL adminUser = new AdminUserBLL();

            string    userName = user.Value;
            string    password = pwd.Value;
            DataTable dt       = User.selectid(userName, password);

            if (userName == "" && password == "")
            {
                JsHelper.Alert("账号或密码不能为空!");
                return;
            }
            Session["ID"] = dt.Rows[0]["id"];
            if (adminUser.UserLoginCheck(userName, password))
            {
                Session["UserName"] = userName;
                Response.Redirect("indexs.aspx");
            }
            else
            {
                JsHelper.Alert("账号或密码不正确!");
            }
        }
示例#5
0
        public ActionResult Login(string Name, string Pw)
        {
            HandleResult hr = new HandleResult();

            if (string.IsNullOrEmpty(Name) || Commons.IsIncludeSqlInjection(Name))
            {
                hr.StatsCode = 103;
                hr.Message   = "姓名不合法";
                return(Content(JsonConvert.SerializeObject(hr)));
            }

            if (string.IsNullOrEmpty(Pw) || Commons.IsIncludeSqlInjection(Pw))
            {
                hr.StatsCode = 104;
                hr.Message   = "密码不合法";
                return(Content(JsonConvert.SerializeObject(hr)));
            }

            AdminUserEntity model = AdminUserBLL.GetLoginByName(Name);

            if (model != null)
            {
                if (model.PassWord == Commons.GetMD5Hash(Pw))
                {
                    Authentication.SetAuthCookie(model.Id, HttpUtility.UrlEncode(model.UserName, Encoding.GetEncoding("UTF-8")));
                    hr.StatsCode = 200;
                    hr.Message   = "登陆成功";
                    return(Content(JsonConvert.SerializeObject(hr)));
                }
                hr.Message = "用户不存在或密码错误";
                return(Content(JsonConvert.SerializeObject(hr)));
            }
            hr.Message = "用户不存在或密码错误";
            return(Content(JsonConvert.SerializeObject(hr)));
        }
示例#6
0
        public ActionResult GetAdminUser()
        {
            AdminUserBLL objAdminUserBll = new AdminUserBLL();

            var list = objAdminUserBll.GetAllAdminUser().ToList();

            return(Json(new { data = list }, JsonRequestBehavior.AllowGet));
        }
示例#7
0
        public ActionResult Save(AdminUser objAdminUser)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                AdminUserBLL objAdminUserBll = new AdminUserBLL();

                objAdminUserBll.CreateAdminUser(objAdminUser);

                status = true;
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
示例#8
0
        protected void Unnamed_ServerClick1(object sender, EventArgs e)
        {
            AdminUserBLL adminUser = new AdminUserBLL();
            string       userName  = user.Value;
            string       password  = pwd.Value;

            if (adminUser.UserLoginCheck(userName, password))
            {
                Session["UserName"] = userName;
                Response.Redirect("index.aspx");
            }
            else
            {
                JsHelper.Alert("账号或密码不正确!");
            }
        }
示例#9
0
        //public void Bind()
        //{
        //    string username = user.Value;
        //    string password = pwd.Value;
        //    if (username == "" || password == "")
        //    {
        //        JSHelper.Alert("用户名或密码不正确");
        //        return;
        //    }
        //    string sql = $"select * from AdminUser where UserName='******' and PassWord='******'";
        //    DataTable dt = SqlHelper.GetDataTable(sql);
        //    int sq = dt.Rows.Count;
        //    if (sq >= 1)
        //    {
        //        string Lv = dt.Rows[0]["Level"].ToString();
        //        Session["Level"] = Lv;
        //        JSHelper.Alert("登陆成功");
        //        Response.Redirect($"index.aspx?Level={Lv}");
        //    }
        //    else
        //    {
        //        JSHelper.Alert("用户名或密码错误");
        //    }
        //}
        protected void Unnamed_ServerClick(object sender, EventArgs e)
        {
            //Session["UserName"] = user.Value;
            //Session["PassWord"] = pwd.Value;
            //Bind();

            AdminUserBLL adUser = new AdminUserBLL();

            //string userName = user.Value;
            //string passWord = pwd.Value;
            //SqlDataReader dr = adUser.UserLoginCheck(userName, passWord);
            //if (dr.Read()/*adUser.UserLoginCheck(userName, passWord)*/)
            //{
            //    Session["UserName"] = user.Value;
            //    Session["ID"] = Convert.ToInt32(dr["id"]);
            //    Session["PassWord"] = pwd.Value;
            //    dr.Close();
            //    Response.Redirect("Index.aspx");
            //}
            //else
            //{
            //    JSHelper.Alert("账号或密码不正确");
            //    dr.Close();
            //    return;
            //}

            string name = user.Value;
            string pass = pwd.Value;

            DataTable dt = adUser.UserLoginCheck(name, pass);

            if (adUser.UserLoginCheck(name, pass).Rows.Count == 1)
            {
                Session["UserName"] = name;
                Session["PassWord"] = pass;
                Session["id"]       = dt.Rows[0]["id"].ToString();
                Session["level"]    = dt.Rows[0]["level"].ToString();
                Response.Redirect("index.aspx");
            }
            else
            {
                JSHelper.Alert("账号或密码不正确");
            }
        }
示例#10
0
 /// <summary>
 /// 弹出提示框
 /// </summary>
 private void PageInit()
 {
     if (Session["admin_show"] != null && Session["admin_show"].ToString() == "1")
     {
         AdminUser User = new AdminUserBLL().GetUserByUserID(Convert.ToInt32(Session["admin_userid"]));
         if (User != null)
         {
             StringBuilder sql = new StringBuilder();
             sql.Append("<script type=\"text/javascript\">");
             sql.Append("$(document).ready(function() {$.messager.show({");
             sql.Append("title: '提示信息',msg: '" + User.UserName + ",欢迎您的登录<br/>上次登录时间:" + User.LastLoginTime + "',");
             sql.Append("timeout: 5000,showType: 'slide'");
             sql.Append("});});");
             sql.Append("</script>");
             ltl_script.Text = sql.ToString();
         }
         Session.Remove("admin_show");
     }
 }
示例#11
0
        public void LoadInfo(string itemId)
        {
            AdminUser user = new AdminUser();

            user = new AdminUserBLL().GetByUserID(itemId);
            if (user != null)
            {
                if (!string.IsNullOrEmpty(user.Gender))
                {
                    input_gender.Value = user.Gender.Trim();
                }
                if (!string.IsNullOrEmpty(user.Address))
                {
                    input_homeAddress.Value = user.Address.Trim();
                }
                if (!string.IsNullOrEmpty(user.UserID))
                {
                    input_loginName.Value = user.UserID.Trim();
                }
                if (!string.IsNullOrEmpty(user.Email))
                {
                    input_mailAddress.Value = user.Email.Trim();
                }
                if (!string.IsNullOrEmpty(user.UserName))
                {
                    input_name.Value = user.UserName.Trim();
                }
                if (!string.IsNullOrEmpty(user.PhoneNum))
                {
                    input_phoneNum.Value = user.PhoneNum.Trim();
                }
                if (!string.IsNullOrEmpty(user.EmployeeId.ToString()))
                {
                    input_employeeId.Value = user.EmployeeId.ToString().Trim();
                }
                if (!string.IsNullOrEmpty(userPwd))
                {
                    userPwd = user.UserPwd.Trim();
                }
            }
        }
        public void GetAdmins()
        {
            StringBuilder           sb       = new StringBuilder();
            IEnumerable <AdminUser> userlist = new AdminUserBLL().GetPagedData(10, 0);

            if (userlist == null)
            {
            }
            else
            {
                foreach (AdminUser item in userlist)
                {
                    sb.Append("<tr id=\"tr" + item.ID + "\"><th>");
                    sb.Append(item.UserName);
                    sb.Append("</th><th>");
                    sb.Append(item.UserID);
                    sb.Append("</th><th>");
                    sb.Append(item.Gender);
                    sb.Append("</th><th>");
                    sb.Append(item.PhoneNum);
                    sb.Append("</th><th>");
                    sb.Append(item.Email);
                    sb.Append("</th><th>");
                    sb.Append(item.Address);
                    sb.Append("</th><th>");
                    sb.Append(item.UserCreatedDate);
                    sb.Append("</th><th>");
                    if (item.UserID.Trim() == "admin")
                    {
                        sb.Append("&nbsp;");
                    }
                    else
                    {
                        sb.Append("<a href=\"#\" onclick=\"opt('edit_" + item.ID + "')\">编辑</a>&nbsp;&nbsp;<a href=\"#\" onclick=\"opt('delete_" + item.ID + "')\">删除</a>");
                    }

                    sb.Append("</th><tr>");
                }
                littablebody.Text = sb.ToString();
            }
        }
示例#13
0
 public ActionResult Login(LoginModel model)
 {
     if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password))
     {
         var userBll        = new AdminUserBLL();
         var loginUserModel = userBll.GetLoginUserByLogin(model.UserName, model.Password);
         if (loginUserModel != null)
         {
             if (loginUserModel.AdminUserInfo.Status != 1)
             {
                 model.ErrorInfoForUserName = "******";
             }
             else if (loginUserModel.MenuList != null && loginUserModel.MenuList.Count > 0)
             {
                 LoginHelper.Cache(loginUserModel);
                 if (string.IsNullOrEmpty(model.ReturnUrl))
                 {
                     return(RedirectToAction("Index", "Home"));
                 }
                 else
                 {
                     return(Redirect(model.ReturnUrl));
                 }
             }
             else
             {
                 model.ErrorInfoForUserName = "******";
             }
         }
         else
         {
             model.ErrorInfoForUserName = "******";
         }
     }
     else
     {
         model.ErrorInfoForUserName = "******";
         model.ErrorInfoForPassword = "******";
     }
     return(View(model));
 }
示例#14
0
        protected void Unnamed_ServerClick1(object sender, EventArgs e)
        {
            AdminUserBLL updatepass = new AdminUserBLL();
            UserBLL      userbll    = new UserBLL();
            string       oldpass    = oldpwd.Value;  //旧密码
            string       newspass   = newspwd.Value; //新密码

            if (string.IsNullOrEmpty(oldpass) && string.IsNullOrEmpty(newspass))
            {
                Response.Write("原密码或新密码不能为空!");
                return;
            }
            if (newspass == oldpass)
            {
                Response.Write("新密码不能和原始密码相同!");
                return;
            }
            SqlDataReader dr = userbll.SelectUserPassBLL(Session["username"].ToString(), oldpass);

            if (dr.Read() == true)
            {
                int i = userbll.UpdateUserpassBLL(Session["username"].ToString(), newspass);
                if (i == 1)
                {
                    Response.Write("修改密码成功!");

                    Response.Redirect("denglu.aspx");
                }
                else
                {
                    Response.Write("修改密码错误!");
                    return;
                }
            }
            else
            {
                Response.Write("原密码错误,请重新输入!");

                return;
            }
        }
        protected void btnChangePwd_Click(object sender, EventArgs e)
        {
            btnChangePwd.Enabled = false;
            //更改密码首先验证原始密码,
            //然后在保存用户的新密码
            AdminUser user = Session["Users"] as AdminUser;

            if (user != null && AdminUserBLL.CheckAdminUser(user.UserID, MD5PWD.EnCode(oldpwd.Text)))
            {
                //验证旧的密码成功

                if (new AdminUserBLL().SavaNewPwd(user.ID.ToString(), MD5PWD.EnCode(newpwd.Text)) > 0)
                {
                    JqHelper.ResponseScript("alert(\"修改密码成功!\")");
                }
                else
                {
                    JqHelper.ResponseScript("alert(\"修改密码失败!\")");
                }
            }
            btnChangePwd.Enabled = true;
        }
示例#16
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="UserPwd">密码</param>
        /// <returns>登录是否成功</returns>
        private bool UserLogin(string UserName, string UserPwd)
        {
            AdminUserBLL UserBiz = new AdminUserBLL();
            AdminUser    item    = UserBiz.UserLogin(UserName, UserPwd);

            if (item != null)
            {
                Session["AdminName"]    = UserName;
                Session["admin_userid"] = item.Id;
                Session["admin_show"]   = 1;
                Session["issystem"]     = item.IsSystem;
                Session["Permissions"]  = UserBiz.GetPermissionsByUserID(item.Id);
                UserBiz.UpdateUser(item.Id, Utils.GetTrueIPAddress());
                //写入Cookies
                Utils.WriteCookie("AdminName", "FZtouch", DESEncrypt.Encrypt(UserName));
                Utils.WriteCookie("AdminPwd", "FZtouch", UserPwd);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#17
0
 protected void button_login_Click(object sender, EventArgs e)
 {
     //添加必填验证
     if (CheckInput())
     {
         button_login.Enabled = false;
         if (AdminUserBLL.CheckAdminUser(textbox_userId.Text, MD5PWD.EnCode(textbox_pwd.Text)))
         {
             AdminUser admin = new AdminUser();
             admin.UserID  = textbox_userId.Text;
             admin.UserPwd = MD5PWD.EnCode(textbox_pwd.Text);
             //登录按钮操作事件
             //Session["pwd"] = textbox_pwd.Text;
             admin            = new AdminUserBLL().GetByID(textbox_userId.Text);
             Session["Users"] = admin;//将用户存入到Session中
             Response.Redirect("../AdminManagerment/Index.aspx");
         }
         else
         {
             JqHelper.ResponseScript("alert(\"登录密码或用户名错误!\")");
             button_login.Enabled = true;
         }
     }
 }
示例#18
0
        protected void Unnamed_ServerClick1(object sender, EventArgs e)
        {
            AdminUserBLL adminuserbll = new AdminUserBLL();
            UserBLL      userbll      = new UserBLL();
            string       Userpass     = pwd.Value;
            string       Username     = user.Value;

            if (Username == "" || Userpass == "")
            {
                Response.Write("<script language='javascript'> alert('不能为空');</script>");
                return;
            }
            if (userbll.CheckUser(Username) == 1)
            {
                JsHelper.Alert("管理员不能重复");
                user.Value = null;
                return;
            }
            int i = userbll.AddUserBLL(Username, Userpass);

            if (i == 1)
            {
                Response.Write("<script langeuage='javascript'>alert('添加成功');</script>");

                user.Value = null;
                pwd.Value  = null;
                return;
            }
            else
            {
                Response.Write("添加失败!");
                user.Value = "";
                pwd.Value  = "";
                return;
            }
        }
示例#19
0
        protected void Unnamed_ServerClick(object sender, EventArgs e)
        {
            NewModel     model = new NewModel();
            AdminUserBLL bll   = new AdminUserBLL();

            model.UserName = user.Value;
            model.PassWord = pwd.Value;
            model.Level    = level.Value;
            int admin = Convert.ToInt32(Session["level"]);

            if (user.Value == "")
            {
                JSHelper.Alert("用户名不能为空");
                return;
            }
            string name = user.Value;
            string sql  = $"select count(*) from AdminUser where UserName='******'";
            int    num  = Convert.ToInt32(SqlHelper.ExScalar(sql));

            if (num == 1)
            {
                JSHelper.Alert("用户名不能重复添加");
                return;
            }
            if (level.Value == "")
            {
                JSHelper.Alert("添加管理员时,权限不能为空");
                return;
            }
            if (pwd.Value == "")
            {
                JSHelper.Alert("密码不能为空");
                return;
            }
            string newpwd = newpass.Value;

            if (string.IsNullOrEmpty(newpwd))
            {
                JSHelper.Alert("请再次输入密码");
                return;
            }
            if (pwd.Value != newpwd)
            {
                JSHelper.Alert("两次密码输入不一致,添加失败");
                return;
            }
            //if (level.Value != "1" && level.Value != "2")
            //{
            //    JSHelper.Alert("超级管理员请填'1',普通管理员请填'2'");
            //    return;
            //}
            if (admin != 1)
            {
                JSHelper.Alert("权限不足,无法添加");
                return;
            }
            if (bll.AddAdmin(model) == 1)
            {
                JSHelper.Alert("添加成功");
            }
            else
            {
                JSHelper.Alert("添加失败");
            }
            //NewModel newModel = new NewModel
            //{
            //    UserName = user.Value,
            //    PassWord = pass.Value,
            //    Level = level.Value
            //};

            //string name = user.Value;
            //if (string.IsNullOrEmpty(name))
            //{
            //    JSHelper.Alert("用户名不能为空");
            //    return;
            //}
            //string sql = $"select count(*) from AdminUser where UserName='******'";
            //int num = Convert.ToInt32(SqlHelper.ExScalar(sql));
            //if (num == 1)
            //{
            //    JSHelper.Alert("用户名不能重复添加");
            //    return;
            //}
            //string Lv = level.Value;
            //if (string.IsNullOrEmpty(Lv))
            //{
            //    JSHelper.Alert("用户等级权限不能为空");
            //    return;
            //}
            //string password = pass.Value;
            //if (string.IsNullOrEmpty(password))
            //{
            //    JSHelper.Alert("密码不能为空");
            //    return;
            //}
            //string newpassword = newpass.Value;
            //if(string.IsNullOrEmpty(newpassword))
            //{
            //    JSHelper.Alert("请再次输入密码");
            //    return;
            //}
            //if (password == newpassword)
            //{
            //    if (adUser.AddAdmin(newModel) == 1)
            //    {
            //            JSHelper.Alert("添加成功");
            //          //Response.Redirect("AdminList.aspx");
            //            user.Value = string.Empty;
            //            pass.Value = string.Empty;
            //            newpass.Value = string.Empty;
            //            level.Value = string.Empty;
            //    }
            //    else
            //    {
            //        JSHelper.Alert("添加失败");
            //        return;
            //    }
            //}
            //    else
            //    {
            //        JSHelper.Alert("两次密码不一致");
            //        return;
            //    }
        }