public HttpResponseMessage ModifyPassword(PasswordModify pw)
        {
            JavaScriptSerializer        Json = new JavaScriptSerializer();
            Dictionary <string, string> res  = new Dictionary <string, string>();
            var cookie = HttpContext.Current.Request.Cookies["account"];

            if (cookie == null)
            {
                res.Add("Message", "Cookie不存在");
                return(ConvertToJson(res));
            }
            int           AdministratorID = int.Parse(cookie["AdminID"]);
            Administrator find            = db.Administrator.Find(AdministratorID);

            if (find.Password == pw.oldPasswd)
            {
                find.Password = pw.newPasswd;
                db.SaveChanges();
                res.Add("Message", "success");
                return(ConvertToJson(res));
            }
            else if (find.Password != pw.oldPasswd)
            {
                res.Add("Message", "密码错误");
                return(ConvertToJson(res));
            }
            else
            {
                res.Add("Message", "未知错误");
                return(ConvertToJson(res));
            }
        }
Beispiel #2
0
        public HttpResponseMessage ModifyPassword(PasswordModify pw)
        {
            Dictionary <string, string> res = new Dictionary <string, string>();
            var cookie = HttpContext.Current.Request.Cookies["account"];

            if (cookie == null)
            {
                res.Add("Message", "Cookie不存在");
                return(ConvertToJson(res));
            }
            int   userID = int.Parse(cookie["UserID"]);
            Users find   = db.Users.Find(userID);

            if (find.Password == pw.oldPasswd)
            {
                find.Password = pw.newPasswd;
                db.SaveChanges();
                res.Add("Message", "success");
                return(ConvertToJson(res));
            }
            else if (find.Password != pw.oldPasswd)
            {
                res.Add("Message", "密码错误");
                return(ConvertToJson(res));
            }
            else
            {
                res.Add("Message", "未知错误");
                return(ConvertToJson(res));
            }
        }