Ejemplo n.º 1
0
        public JsonResult Login(Sys_User entity)
        {
            try
            {
                int a = 10;
                int b = 0;
                int c = a / b;
            }
            catch (Exception ex)
            {
                NLogUtil.Error(ex.ToString());
                //throw;
            }
            Sys_User user = _sysUserService.LoadEntities(c => c.UserName.Equals(entity.UserName)).SingleOrDefault();

            if (user == null)
            {
                return(Json(new { state = 201, message = "用户名或密码错误" }, JsonRequestBehavior.AllowGet));
            }
            if (user.PassWord.Equals(EncryptUtil.Md5(entity.PassWord)))
            {
                Session["YD_USER"] = user;
                string  ip  = Request.UserHostAddress;
                Sys_Log log = _logService.AddEntity(new Sys_Log {
                    OccurTime = DateTime.Now, UserId = user.Id, Type = 1, LoginIp = ip
                });
                return(Json(new { state = 200, messgae = "登录成功" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { state = 201, message = "用户名或密码错误" }, JsonRequestBehavior.AllowGet));
        }