/// <summary> /// 添加信息 2014-11-05 20:23:33 By 唐有炜 /// </summary> /// <param name="TSysLog">TSysLog</param> /// <returns>添加状态</returns> public bool AddSysLog(TSysLog SysLog) { var status = false; try { status = TSysLogDao.InsertEntity(SysLog); } catch (Exception ex) { LogHelper.Error("获取SysLog失败。", ex); status = false; } return status; }
/// <summary> /// 登录验证并写入登录日志 2014-08-21 07:58:50 By 唐有炜 /// </summary> /// <param name="httpContext">HttpContext</param> /// <param name="type">注册或登录方式(normal,qrcode,usb,footprint)</param> /// <param name="accountType">账号类型(username,email,phone)</param> /// <param name="userName">用户名</param> /// <param name="userPassword">密码</param> /// <param name="remember">记住密码</param> /// <param name="clientIp">客户端ip地址</param> /// /// <param name="clientPlace">客户端地址</param> /// <param name="clientTime">客户端登录时间</param> /// <returns>ResponseMessage</returns> public ResponseMessage Login(HttpContext httpContext, string type, string accountType, string userName, string userPassword, string remember, string clientIp, string clientPlace, string clientTime) { ResponseMessage rmsg = new ResponseMessage(); try { //账户验证 rmsg = ValidateAccount(type, accountType, userName, userPassword); if (!rmsg.Status) { return rmsg; } //判断用户是否被禁用 //获取用户信息 var sysUser = GetSysUserByAccountTypeAndUserLname(accountType, userName); if (sysUser.UserEnable != 1) { rmsg.Status = false; rmsg.Msg = "对不起,该用户已经被禁用!"; return rmsg; } var sysRole = TSysRoleDao.GetEntity(r => r.Id == sysUser.RoleId); //书写SessionCookie WriteSessionCookie(httpContext, sysUser, sysRole, remember); //写日志 var loginUser = sysUser.UserTname; if (String.IsNullOrEmpty(loginUser)) { if (String.IsNullOrEmpty(clientPlace)) { clientPlace = "未知地区"; } loginUser = clientPlace + "网友"; } TSysLog sysLog = new TSysLog() { UserId = sysUser.Id, UserLname = sysUser.UserLname, LogAction = UCEnums.LogActionEnum.Login.ToString(), LogRemark = String.Concat(new[] {"【", loginUser, "】,登录了系统。"}), LogIp = clientIp, LogPlace = clientPlace, LogTime = DateTime.Parse(clientTime) }; TSysLogDao.InsertEntity(sysLog); rmsg.Status = true; rmsg.Msg = "登陆成功"; LogHelper.Info(userName + "登录成功,登录日志已记录。"); } catch (Exception ex) { rmsg.Status = false; rmsg.Msg = "登陆失败"; LogHelper.Debug("登陆错误", ex); } return rmsg; }
/// <summary> /// 修改实体 /// </summary> /// <param name="entity">实体对象</param> public bool UpdateEntity(TSysLog entity) { using (UCDbContext db=new UCDbContext()) { int rows= db.TSysLogs.Update(entity); if (rows > 0) { return true; } else { return false; } } }