public ActionResult AddAjax(SysAccountInfoEntity accountEntity)
 {
     try
     {
         if (!Request.IsAjaxRequest())
         {
             return Content("{\"result\":\"failure\",\"msg\":\"非法请求\"}");
         }
         string msg = "";
         if (ModelState.IsValid)
         {
             ISysAccountInfoService accountService = ServiceContainer.Instance.Container.Resolve<ISysAccountInfoService>();
             SysAccountInfoQuery queryEntity = new SysAccountInfoQuery();
             queryEntity.LoginName = WKT.Common.Security.SecurityUtils.SafeSqlString(accountEntity.LoginName);
             IList<SysAccountInfoEntity> list = accountService.GetSysAccountInfoList(queryEntity);
             if (list.Count > 0)
             {
                 msg = "{\"result\":\"failure\",\"msg\":\"该登录名已经存在\"}";
             }
             else
             {
                 accountEntity.Pwd = WKT.Common.Security.DES.Encrypt(accountEntity.Pwd);
                 bool flag = accountService.AddSysAccountInfo(accountEntity);
                 if (flag)
                 {
                     msg = "{\"result\":\"success\"}";
                 }
                 else
                 {
                     msg = "{\"result\":\"failure\",\"msg\":\"添加失败,请检查\"}";
                 }
             }
         }
         else
         {
             msg = "{\"result\":\"failure\",\"msg\":\"" + this.ExpendErrors() + "\"}";
         }
         return Content(msg);
     }
     catch(Exception ex)
     {
         LogProvider.Instance.Error("添加管理账户失败:" + ex.Message);
         return Content("{\"result\":\"error\",\"msg\":\"" + ex.Message + "\"}");
     }
 }
 /// <summary>
 /// 分页获取符合查询条件的数据
 /// </summary>
 /// <param name="sysAccountInfoQuery">SysAccountInfoQuery查询实体对象</param>
 /// <returns>Pager<SysAccountInfoEntity></returns>
 public Pager<SysAccountInfoEntity> GetSysAccountInfoPageList(SysAccountInfoQuery sysAccountInfoQuery)
 {
     return SysAccountInfoBusiness.GetSysAccountInfoPageList(sysAccountInfoQuery);
 }
 /// <summary>
 /// 获取所有符合查询条件的数据
 /// </summary>
 /// <param name="sysAccountInfoQuery">SysAccountInfoQuery查询实体对象</param>
 /// <returns>List<SysAccountInfoEntity></returns>
 public List<SysAccountInfoEntity> GetSysAccountInfoList(SysAccountInfoQuery sysAccountInfoQuery)
 {
     return SysAccountInfoBusiness.GetSysAccountInfoList(sysAccountInfoQuery);
 }
Beispiel #4
0
        public ActionResult LoginAjax(string LoginName, string Password, string VerifyCode)
        {
            string returnUrl = "/";

            # region func define

            Func<SysAccountInfoEntity, string, JsonResult> loginFunc = (accountEntity, pwd) =>
            {
                if (accountEntity == null)
                    return Json(new { result = "failure", msg = "用户名或密码错误!", url = returnUrl });
                if (accountEntity.Status == 1)// 禁用
                    return Json(new { result = "failure", msg = "您的账号已经禁用!", url = returnUrl });
                if (!accountEntity.Pwd.Equals(pwd))
                    return Json(new { result = "failure", msg = "用户名或密码错误!", url = returnUrl });

                accountEntity.LogOnTimes = accountEntity.LogOnTimes + 1;
                accountEntity.LastIP = WKT.Common.Utils.Utils.GetRealIP();
                accountEntity.LoginDate = DateTime.Now;

                # region 更新登录情况

                ISysAccountInfoService accountService = ServiceContainer.Instance.Container.Resolve<ISysAccountInfoService>();
                accountService.UpdateAccountLoginInfo(accountEntity.AdminID, accountEntity.LastIP, accountEntity.LoginDate.ToString("yyyy-MM-dd HH:mm:ss"));

                # endregion

                string jsonObject = JsonConvert.SerializeObject(accountEntity);
                // 保存登录ticket
                TicketTool.SetCookie(accountEntity.AdminID.ToString(), jsonObject);

                return Json(new { result = "success", msg = "登录成功!", url = returnUrl });
            };

            # endregion

            try
            {
                # region 得到验证码

                string code = "";
                HttpCookie cookie = Request.Cookies[VERFIYCODEKEY];
                if (cookie != null)
                {
                    code = cookie.Value.ToString();
                }
                # endregion

                if (WKT.Common.Security.DES.Encrypt(VerifyCode.ToLower()) == code)
                {
                    ISysAccountInfoService accountService = ServiceContainer.Instance.Container.Resolve<ISysAccountInfoService>();
                    SysAccountInfoQuery queryEntity = new SysAccountInfoQuery();
                    queryEntity.LoginName = SecurityUtils.SafeSqlString(LoginName);
                    IList<SysAccountInfoEntity> list = accountService.GetSysAccountInfoList(queryEntity);
                    if (list == null || list.Count == 0)
                        return Json(new { result = "failure", msg = "用户名或密码错误!"});
                    if (list.Count == 1)
                    {
                        Password = DES.Encrypt(Password);
                        return loginFunc(list[0], Password);
                    }
                    else
                        return Json(new { result = "failure", msg = "用户名重复,请确认是否输入正确"});
                }
                else
                {
                    return Json(new { result = "failure", msg = "请输入正确的验证码!"});
                }
            }
 /// <summary>
 /// 获取所有符合查询条件的数据
 /// </summary>
 /// <param name="sysAccountInfoQuery">SysAccountInfoQuery查询实体对象</param>
 /// <returns>List<SysAccountInfoEntity></returns>
 public List<SysAccountInfoEntity> GetSysAccountInfoList(SysAccountInfoQuery sysAccountInfoQuery)
 {
     return SysAccountInfoDataAccess.Instance.GetSysAccountInfoList(sysAccountInfoQuery);
 }
 /// <summary>
 /// 将查询实体转换为Where语句
 /// <param name="query">查询实体</param>
 /// <returns>获取Where语句,不包含Where</returns>
 /// </summary>
 public string SysAccountInfoQueryToSQLWhere(SysAccountInfoQuery query)
 {
     StringBuilder sbWhere = new StringBuilder(" 1=1 ");
     if (query.Status != null)
     {
         sbWhere.Append(" AND Status= ").Append(query.Status.Value);
     }
     if (!string.IsNullOrEmpty(query.LoginName))
     {
         sbWhere.AppendFormat( " AND LoginName='{0}'",WKT.Common.Security.SecurityUtils.SafeSqlString(query.LoginName));
     }
     if (sbWhere.ToString() == " 1=1 ")
     {
         return string.Empty;
     }
     else
     {
         return sbWhere.ToString();
     }
 }
 /// <summary>
 /// 将查询实体转换为Order语句
 /// <param name="query">查询实体</param>
 /// <returns>获取Order语句,不包含Order</returns>
 /// </summary>
 public string SysAccountInfoQueryToSQLOrder(SysAccountInfoQuery query)
 {
     return " AdminID DESC";
 }
 public Pager<SysAccountInfoEntity> GetSysAccountInfoPageList(SysAccountInfoQuery query)
 {
     int recordCount = 0;
     string whereSQL = SysAccountInfoQueryToSQLWhere(query);
     string orderBy = SysAccountInfoQueryToSQLOrder(query);
     DataSet ds = db.GetPagingData("SysAccountInfo", "AdminID,UserName,LoginName,Pwd,Gender,Email,Mobile,Status,LastIP,LoginDate,LogOnTimes,AddDate", orderBy, whereSQL, query.CurrentPage, query.PageSize, out recordCount);
     Pager<SysAccountInfoEntity> pager = new Pager<SysAccountInfoEntity>();
     if (ds != null && ds.Tables.Count > 0)
     {
         pager.ItemList = MakeSysAccountInfoList(ds.Tables[0]);
     }
     pager.CurrentPage = query.CurrentPage;
     pager.PageSize = query.PageSize;
     pager.TotalRecords = recordCount;
     return pager;
 }
 public List<SysAccountInfoEntity> GetSysAccountInfoList(SysAccountInfoQuery query)
 {
     List<SysAccountInfoEntity> list = new List<SysAccountInfoEntity>();
     StringBuilder sqlCommandText = new StringBuilder();
     sqlCommandText.Append("SELECT AdminID,UserName,LoginName,Pwd,Gender,Email,Mobile,Status,LastIP,LoginDate,LogOnTimes,AddDate FROM dbo.SysAccountInfo WITH(NOLOCK)");
     string whereSQL = SysAccountInfoQueryToSQLWhere(query);
     string orderBy = SysAccountInfoQueryToSQLOrder(query);
     if (!string.IsNullOrEmpty(whereSQL)) sqlCommandText.Append(" WHERE " + whereSQL);
     if (!string.IsNullOrEmpty(orderBy)) sqlCommandText.Append(" ORDER BY " + orderBy);
     DbCommand cmd = db.GetSqlStringCommand(sqlCommandText.ToString());
     using (IDataReader dr = db.ExecuteReader(cmd))
     {
         list = MakeSysAccountInfoList(dr);
     }
     return list;
 }
 public ActionResult IndexAjax(SysAccountInfoQuery queryEntity)
 {
     if (!Request.IsAjaxRequest())
     {
         return Content("{\"result\":\"error\",\"msg\":\"非法访问\"}");
     }
     else
     {
         ISysAccountInfoService accountService = ServiceContainer.Instance.Container.Resolve<ISysAccountInfoService>();
         queryEntity.CurrentPage = queryEntity.CurrentPage + 1;
         WKT.Model.Pager<SysAccountInfoEntity> sysAccountList = accountService.GetSysAccountInfoPageList(queryEntity);
         if (sysAccountList != null)
         {
             return Content("{\"result\":\"success\",\"msg\":\"成功\",\"data\":" + JsonConvert.SerializeObject(sysAccountList) + "}");
         }
         else
         {
             return Content("{\"result\":\"error\",\"msg\":\"系统出现异常,请稍后再试\"}");
         }
     }
 }
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            ViewBag.TotalCount = 0;
            ISysAccountInfoService accountService = ServiceContainer.Instance.Container.Resolve<ISysAccountInfoService>();
            SysAccountInfoQuery queryEntity = new SysAccountInfoQuery();
            queryEntity.CurrentPage = 1;
            Pager<SysAccountInfoEntity> pagerAccountList = accountService.GetSysAccountInfoPageList(queryEntity);
            IList<SysAccountInfoEntity> listAccount = new List<SysAccountInfoEntity>();
            if (pagerAccountList != null)
            {
                listAccount = pagerAccountList.ItemList;
                ViewBag.TotalCount = pagerAccountList.TotalRecords;
            }

            return View(listAccount);
        }