/// <summary> /// 添加登录信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(SysLogLoginModel model) { StringBuilder sql = new StringBuilder(); sql.AppendLine("INSERT INTO SYS_LOG_LOGIN"); sql.AppendLine(" (LOGIN_ID,"); sql.AppendLine(" USER_CODE,"); sql.AppendLine(" USER_PWD,"); sql.AppendLine(" USER_PWD_LAWS,"); sql.AppendLine(" LOGIN_IP,"); sql.AppendLine(" LOGIN_RESULT,"); sql.AppendLine(" LOGIN_MSG,"); sql.AppendLine(" CREATE_USER,"); sql.AppendLine(" LM_USER)"); sql.AppendLine("VALUES"); sql.AppendLine(" ($LOGIN_ID,"); sql.AppendLine(" $USER_CODE,"); sql.AppendLine(" $USER_PWD,"); sql.AppendLine(" $USER_PWD_LAWS,"); sql.AppendLine(" $LOGIN_IP,"); sql.AppendLine(" $LOGIN_RESULT,"); sql.AppendLine(" $LOGIN_MSG,"); sql.AppendLine(" $CREATE_USER,"); sql.AppendLine(" $LM_USER)"); SQLParameter[] parms = { new SQLParameter("LOGIN_ID", typeof(string), model.LOGIN_ID), new SQLParameter("USER_CODE", typeof(string), model.USER_CODE), new SQLParameter("USER_PWD", typeof(string), model.USER_PWD), new SQLParameter("USER_PWD_LAWS", typeof(string), model.USER_PWD_LAWS), new SQLParameter("LOGIN_IP", typeof(string), model.LOGIN_IP), new SQLParameter("LOGIN_RESULT", typeof(string), model.LOGIN_RESULT), new SQLParameter("LOGIN_MSG", typeof(string), model.LOGIN_MSG), new SQLParameter("CREATE_USER", typeof(string), model.CREATE_USER), new SQLParameter("LM_USER", typeof(string), model.LM_USER) }; int result = DB.CustomExecuteWithReturn(new SQLParamCondition(sql.ToString(), parms)); return(result); }
/// <summary> /// 用户登录 /// </summary> /// <param name="model">返回用户信息</param> /// <param name="user_id">登录名</param> /// <param name="pwd">密码</param> /// <returns></returns> public JsonMessage Login(ref AccountModel model, string user_id, string pwd) { JsonMessage jsonMsg = new JsonMessage(); //返回Json int result = -1; //类型(成功 、失败) try { if (ValidateHelper.IsNullOrEmpty(StringHelper.Trim(user_id))) { throw new CustomException(0, "用户名不能为空"); } if (ValidateHelper.IsNullOrEmpty(pwd)) { throw new CustomException(0, "密码不能为空"); } //UserID = userId; DataTable dt = _userRep.Login(user_id, MD5Cryption.MD5(pwd)); IList <SysUserModel> list = ConverHelper.ToList <SysUserModel>(dt); if (list.Count < 1) { throw new CustomException(2, "用户名或密码错误");//用户名或密码错误 } if (!ConverHelper.ToBool(list[0].IS_ABLED)) { throw new CustomException(3, "账号已被禁用,请联系系统管理员");//账号是否被禁用 } model.UserCode = list[0].USER_CODE; model.UserName = list[0].USER_NAME; model.LoginNo = list[0].USER_CODE; model.QRCode = list[0].QR_CODE; model.DeptCode = list[0].DEPT_CODE; jsonMsg = ServiceResult.Message(1, "登录成功"); SessionHelper.SetSession("Account", model); CookieHelper.SetCookie("Account", DESCryption.Encrypt(ConverHelper.ToJson(model))); } catch (CustomException ex) { jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message); } catch (Exception ex) { jsonMsg = ServiceResult.Message(-1, ex.Message); } //写入log SysLogLoginModel log = new SysLogLoginModel(); log.LOGIN_ID = GuidHelper.GenerateComb().ToString(); log.USER_CODE = user_id; log.USER_PWD = MD5Cryption.MD5(pwd); log.USER_PWD_LAWS = pwd; log.LOGIN_IP = NetHelper.GetUserIp; log.LOGIN_RESULT = jsonMsg.type == 1 ? "SUCCESS" : "FAIL"; log.LOGIN_MSG = jsonMsg.message; _loglRep.Insert(log); return(jsonMsg); }
/// <summary> /// 用户登录 /// </summary> /// <param name="model">返回用户信息</param> /// <param name="user_id">登录名</param> /// <param name="pwd">密码</param> /// <returns></returns> public JsonMessage Login(string user_id, string pwd, string qr_code) { JsonMessage jsonMsg = new JsonMessage(); //返回Json int result = -1; //类型(成功 、失败) try { if (ValidateHelper.IsNullOrEmpty(user_id) && ValidateHelper.IsNullOrEmpty(qr_code)) { throw new CustomException(0, "用户名和二维码不能同时为空"); } if (ValidateHelper.IsNullOrEmpty(pwd) && ValidateHelper.IsNullOrEmpty(qr_code)) { throw new CustomException(0, "密码和二维码不能同时为空"); } DataTable dt; if (ValidateHelper.IsNullOrEmpty(qr_code)) { dt = _userRep.Login(user_id, pwd); } else { dt = _userRep.Login(qr_code); } IList <SysUserModel> list = ConverHelper.ToList <SysUserModel>(dt); if (list.Count < 1) { if (ValidateHelper.IsNullOrEmpty(qr_code)) { throw new CustomException(2, "用户名或密码错误");//用户名或密码错误 } else { throw new CustomException(2, "二维码不正确");//二维码不正确 } } if (!ConverHelper.ToBool(list[0].IS_ABLED)) { throw new CustomException(3, "账号已被禁用,请联系系统管理员");//账号是否被禁用 } jsonMsg = ServiceResult.Message(1, "登录成功", list[0]); } catch (CustomException ex) { jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message); } catch (Exception ex) { jsonMsg = ServiceResult.Message(-1, ex.Message); } //写入log SysLogLoginModel log = new SysLogLoginModel(); log.LOGIN_ID = GuidHelper.GenerateComb().ToString(); log.USER_CODE = user_id; log.USER_PWD = MD5Cryption.MD5(pwd); log.USER_PWD_LAWS = ValidateHelper.IsNullOrEmpty(user_id) ? qr_code : pwd; log.LOGIN_IP = NetHelper.GetUserIp; log.LOGIN_RESULT = jsonMsg.type == 1 ? "SUCCESS" : "FAIL"; log.LOGIN_MSG = jsonMsg.message; _loglRep.Insert(log); return(jsonMsg); }