public JsonResult UserLogOn_Pad(FormCollection collection)
        {
            Language lang;
            var      service = new SysUserService();
            SysUser  user    = service.Login(collection["UserName"], collection["Password"]);

            if (user == null || string.Compare(user.Pwd, collection["Password"], false) != 0)
            {
                return(Json(new { success = false, msg = "<=PwdorNameError>" }));
            }
            else
            {
                DateTime dt = DateTime.Today;
                if (!(user.ValidDateFrom <= dt && user.ValidDateTo >= dt) || !user.Active)
                {
                    return(Json(new { success = false, msg = "<=UserExpireError>" }));
                }

                //密码过期修改
                if (!user.PasswordDate.HasValue)
                {
                    string errorMsg = string.Empty;
                    user.PasswordDate = DateTime.Now.Date;
                    bool success = service.Save(user, out errorMsg);
                    if (!success)
                    {
                        return(Json(new { success = false, msg = errorMsg }));
                    }
                }
                else
                {
                    if (user.PasswordDate.Value.AddDays(30).Date <= DateTime.Now.Date)
                    {
                        lang = (Language)int.Parse(collection["Lang"]);
                        Response.Cookies["Lang"].Value   = lang == Language.English ? "English" : "SimplifiedChinese";
                        Response.Cookies["Lang"].Expires = DateTime.Now.AddDays(365);
                        return(Json(new { success = false, msg = "expired" }));
                    }
                }

                FormsService.SignIn(collection["UserName"], false);
                lang = (Language)int.Parse(collection["Lang"]);
                Response.Cookies["Lang"].Value   = lang == Language.English ? "English" : "SimplifiedChinese";
                Response.Cookies["Lang"].Expires = DateTime.Now.AddDays(365);
                string s = "FrogDashboard.Service.Services.MasterData.SysManagement.SysFunctionService";
                ISysFunction <SysFunction> service_ = (ISysFunction <SysFunction>)Assembly.Load("FrogDashboard.Service").CreateInstance(s);
                var userRoleId = user.RoleId;
                if (service_.GetUserFunction(userRoleId).Where(c => c.ControllerName == "OrderManagement" && c.ActionName == "TmsForPad").Count() > 0)
                {
                    return(Json(new { success = true, msg = "<LoginSuccess>", URL = "Pad" }));
                }
                else
                {
                    return(Json(new { success = true, msg = "<LoginSuccess>", URL = "Index" }));
                }
            }
        }
        public JsonResult ChangePasswordPost(FormCollection collection)
        {
            var     service = new SysUserService();
            SysUser user    = service.Login(collection["UserCode"], collection["OldPwd"]);

            if (user == null || string.Compare(user.Pwd, collection["OldPwd"], false) != 0)
            {
                return(Json(new { success = false, msg = "<=OldPwdNotMatched>" }));
            }
            else
            {
                if (string.Compare(collection["NewPwd"], collection["ConfirmPwd"], false) != 0)
                {
                    return(Json(new { success = false, msg = "<=NewPwdNotMatched>" }));
                }

                if (string.Compare(collection["NewPwd"], user.Pwd, false) == 0)
                {
                    return(Json(new { success = false, msg = "<=ForbidMatchOldPwd>" }));
                }

                string errorMsg = string.Empty;
                user.PasswordDate = DateTime.Now.Date;

                user.Pwd = collection["NewPwd"];
                TryUpdateModel <SysUser>(user);

                //判断新密码规则,Operator不受密码规则控制
                var _sysUserRoleService = new SysUserRoleService();
                var _sysRoleService     = new SysRoleService();
                var sysUserRole         = _sysUserRoleService.GetList().Where(o => o.SysUserId == user.SysUserId).Select(o => o.SysRoleId).Distinct().ToList();
                var sysRole             = _sysRoleService.GetList().Where(o => sysUserRole.Contains(o.SysRoleId) || o.SysRoleId == user.RoleId).ToList();
                if (sysRole.Count() > 0 && (sysRole.Count() != 1 || sysRole.Where(o => o.RoleCode.Contains("Operator")).Count() <= 0))
                {
                    if (!this.PassWordIsValid(user.Pwd))
                    {
                        return(Json(new { success = false, msg = "<=PasswordError>" }, JsonRequestBehavior.AllowGet));
                    }
                }
                if (!ModelState.IsValid)
                {
                    List <string> errorList = ModelStateExtension.GetModelError(ViewData);
                    string        str       = string.Join(",", errorList.ToArray());
                    return(Json(new { success = false, msg = str }, JsonRequestBehavior.AllowGet));
                }
                bool success = service.Save(user, out errorMsg);
                if (!success)
                {
                    return(Json(new { success = false, msg = errorMsg }));
                }

                FormsService.SignIn(collection["UserCode"], false);
                return(Json(new { success = true, msg = "<=ModifySuccess>" }));
            }
        }
Beispiel #3
0
 public ResultDto <SysUserDto> Save([FromForm] SysUserSaveDto saveDto)
 {
     return(_service.Save(saveDto));
 }
        public JsonResult UserLogOn(FormCollection collection)
        {
            Language lang;
            var      service = new SysUserService();
            SysUser  user    = service.Login(collection["UserName"], collection["Password"]);

            #region authentication for exterior user
            //if (!string.IsNullOrEmpty(collection["KeyCode"]))
            //NameValueCollection appSettings = ConfigurationManager.AppSettings;
            //string strUrl = appSettings["ExteriorUrl"];
            //if (Request.ServerVariables["server_name"].ToLower() == strUrl.ToLower())
            //{
            //    string strkey = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            //    strkey = collection["UserName"].ToLower() + strkey;

            //    MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
            //    UTF8Encoding encoder = new UTF8Encoding();
            //    byte[] hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(strkey));

            //    string strResult = BitConverter.ToString(hashedDataBytes).Replace("-", string.Empty);
            //    if (strResult.ToLower() != collection["KeyCode"].ToLower())
            //        return Json(new { success = false, msg = "<=KeyCodeError>" });

            //}
            #endregion

            if (user == null || string.Compare(user.Pwd, collection["Password"], false) != 0)
            {
                return(Json(new { success = false, msg = "<=PwdorNameError>" }));
            }
            else
            {
                DateTime dt = DateTime.Today;
                if (!(user.ValidDateFrom <= dt && user.ValidDateTo >= dt) || !user.Active)
                {
                    return(Json(new { success = false, msg = "<=UserExpireError>" }));
                }

                //密码过期修改
                if (!user.PasswordDate.HasValue)
                {
                    string errorMsg = string.Empty;
                    user.PasswordDate = DateTime.Now.Date;
                    bool success = service.Save(user, out errorMsg);
                    if (!success)
                    {
                        return(Json(new { success = false, msg = errorMsg }));
                    }
                }
                else
                {
                    if (user.PasswordDate.Value.AddDays(30).Date <= DateTime.Now.Date)
                    {
                        lang = (Language)int.Parse(collection["Lang"]);
                        Response.Cookies["Lang"].Value   = lang == Language.English ? "English" : "SimplifiedChinese";
                        Response.Cookies["Lang"].Expires = DateTime.Now.AddDays(365);
                        return(Json(new { success = false, msg = "expired" }));
                    }
                }

                FormsService.SignIn(collection["UserName"], false);
                lang = (Language)int.Parse(collection["Lang"]);
                Response.Cookies["Lang"].Value   = lang == Language.English ? "English" : "SimplifiedChinese";
                Response.Cookies["Lang"].Expires = DateTime.Now.AddDays(365);
                return(Json(new { success = true, msg = "<LoginSuccess>" }));
            }
        }