Beispiel #1
0
        public JsonResult ChangePassword(UserModel user)
        {
            if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString()))
            {
                Redirect("Login/Index");
                return(null);
            }
            JsonResult json = new JsonResult()
            {
                ContentType = "text/html"
            };
            int result = 0;

            user.UserName = Session[CookieModel.UserName.ToString()].ToString();
            string message = ValidateInput(user);

            if (!string.IsNullOrEmpty(message))
            {
                json.Data = new { Result = 0, Message = message };
                return(json);
            }
            try
            {
                user.Password     = Md5Encrypt.CreateInstance().Encrypt(user.Password);
                user.Password_New = Md5Encrypt.CreateInstance().Encrypt(user.Password_New);
                result            = ServiceModel.CreateInstance().Client.ModifyPassword(user.UserName, user.Password, user.Password_New);
                switch (result)
                {
                case -1:
                    message = "没有权限";
                    break;

                case 0:
                    message = "旧密码输入不正确";
                    break;

                case 1:
                    message = "修改成功";
                    break;
                }
            }
            catch (Exception ex)
            {
                result  = 0;
                message = ex.Message;
            }
            json.Data = new { Result = result, Message = message };
            return(json);
        }
Beispiel #2
0
        public JsonResult Add(UserModel user)
        {
            if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString()))
            {
                Redirect("Login/Index");
                return(null);
            }
            JsonResult json = new JsonResult()
            {
                ContentType = "text/html"
            };
            int    result  = 0;
            string message = ValidateInput(user);

            if (!string.IsNullOrEmpty(message))
            {
                json.Data = new { Result = result, Message = message };
                return(json);
            }
            try
            {
                user.Password = string.IsNullOrEmpty(user.Password) ? "123456" : user.Password;
                user.Password = Md5Encrypt.CreateInstance().Encrypt(user.Password);
                result        = ServiceModel.CreateInstance().Client.AddUser(Session[CookieModel.UserName.ToString()].ToString(), user.UserName, user.RealName, user.Phone, user.IsAdmin);
                switch (result)
                {
                case -1:
                    message = "没有权限";
                    break;

                case 0:
                    message = "添加失败";
                    break;

                case 1:
                    message = "添加成功";
                    break;
                }
            }
            catch (Exception ex)
            {
                result  = 0;
                message = ex.Message;
            }
            json.Data = new { Result = result, Message = message };
            return(json);
        }
Beispiel #3
0
        public ActionResult Index(UserModel user)
        {
            if (!ModelState.IsValid)
            {
                return(View(user));
            }
            if (!ValidateInput(user))
            {
                return(View(user));
            }
            string  password = Md5Encrypt.CreateInstance().Encrypt(user.Password);
            DataSet dst      = ServiceModel.CreateInstance().Client.UserLogin(user.UserName, password);

            if (dst == null || dst.Tables.Count == 0)
            {
                ViewBag.ErrorMessage = "用户名或密码错误";
                return(View(user));
            }
            if (user.RememberMe)
            {
                FormsAuthentication.SetAuthCookie(user.UserName, true, FormsAuthentication.FormsCookiePath);
                FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddTicks(FormsAuthentication.Timeout.Ticks), false, JsonConvert.SerializeObject(user));
                string hashTicket = FormsAuthentication.Encrypt(Ticket);

                HttpCookie cookie = new HttpCookie(CookieModel.Logistics_User_Cookie.ToString(), hashTicket);
                cookie[CookieModel.UserName.ToString()] = user.UserName;
                password = DESEncrypt.CreateInstance().Encrypt(password);
                cookie[CookieModel.Password.ToString()] = password;
                cookie.Expires = DateTime.Now.AddMonths(1);
                Response.Cookies.Add(cookie);
            }
            else
            {
                HttpCookie cookie = new HttpCookie(CookieModel.Logistics_User_Cookie.ToString());
                cookie.Expires = DateTime.Now.AddMonths(-1);
                Request.Cookies.Add(cookie);
                cookie[CookieModel.UserName.ToString()] = null;
                cookie[CookieModel.Password.ToString()] = null;
                Response.Cookies.Add(cookie);
            }
            user.Password = DESEncrypt.CreateInstance().Encrypt(Md5Encrypt.CreateInstance().Encrypt(user.Password));
            AddHttpContextItems(user);
            Session[CookieModel.UserName.ToString()] = user.UserName;
            return(RedirectToAction("Index", "Home"));
        }