/// <summary> /// 增加一条数据 /// </summary> public void Add(LoginLog model) { using (DBHelper db = DBHelper.Create()) { db.Insert<LoginLog>(model); } }
/// <summary> /// 增加一条数据 /// </summary> public void Add(Ajax.Model.LoginLog model) { try { dal.Add(model); } catch { } }
/// <summary> /// 日志查询 /// <param name="log"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// </summary> public List<LoginLog> GetList(LoginLog log, DateTime startTime, DateTime endTime) { Dictionary<string, object> paramDic = new Dictionary<string, object>(); using (DBHelper db = DBHelper.Create()) { string strWhereSql = " "; if (!string.IsNullOrEmpty(log.OperatorID)) { strWhereSql += " and OperatorID=@OperatorID"; paramDic.Add("OperatorID", log.OperatorID); } if (startTime != DateTime.MinValue && endTime != DateTime.MinValue) { strWhereSql += string.Format(" and CreateTime between '{0}' and '{1}'", startTime, endTime); } return db.GetList<LoginLog>(strWhereSql, paramDic, "", ""); } }
/// <summary> /// 用户登录 /// </summary> /// <returns></returns> public ActionResult GoLogin(string userName, string pwd, string validateCode) { AjaxResult result = new AjaxResult(); OperatorRule operatorRule = new OperatorRule(); #if DEBUG validateCode = Session["ValidateCode"].ToString(); #endif if (validateCode != Session["ValidateCode"].ToString()) { result.Success = false; result.Message = "验证码输入错误。"; } else { Logon logon = new Logon() { Password = pwd, Username = userName }; if (UserManager.ValidateUser(logon, Response)) { List<Ticket> currentTicketList = new List<Ticket>(); if (HttpContext.Cache["UserList"] != null) { currentTicketList = HttpContext.Cache["UserList"] as List<Ticket>; } if (currentTicketList.Count == 1) { //MyTicket.CurrentTicket = currentTicketList[0]; //唯一角色的用户直接进入系统 result.Success = true; result.Url = "/Home/Index"; //记录登录日志 LoginLog log = new LoginLog(); log.OperatorID = MyTicket.CurrentTicket.UserID; log.CreateTime = DateTime.Now; log.Type = 1; log.ID = WebHelper.GetNewGuidUpper(); new LoginLogRule().Add(log); return Json(result, JsonRequestBehavior.AllowGet); } else { return Json(currentTicketList, JsonRequestBehavior.AllowGet); } } else { result.Success = false; result.Message = "用户名或者密码错误。"; return Json(result, JsonRequestBehavior.AllowGet); } List<dynamic> userList = operatorRule.Login(userName, pwd); if (userList == null || userList.Count == 0) { result.Success = false; result.Message = "用户名或者密码错误。"; } else { List<Ticket> currentTicketList = new List<Ticket>(); foreach (dynamic t in userList) { if (currentTicketList.Count<Ticket>(ct => ct.GroupName == t.GROUPNAME) > 0) { continue;//同一用户多账号相同角色去重复 } Ticket myTicket = new Ticket(); myTicket.DeptID = t.DEPTID; myTicket.DeptName = t.DEPTNAME; myTicket.EmployeeID = t.EMPID; myTicket.EmployeeName = t.EMPNAME; myTicket.GroupID = t.GROUPID; myTicket.GroupName = t.GROUPNAME; myTicket.UserID = t.ID; myTicket.UserName = t.OPERNAME; myTicket.IsAdmin = (t.ISADMIN == "1") ? true : false; //myTicket.VoteList = new GroupVoteRule().GetOperVotes(t.GROUPID, t.ID);//获取权限列表 myTicket.VoteDic = new Dictionary<string, int>(); foreach (OperatorVote item in new GroupVoteRule().GetOperVotes(t.GROUPID, t.ID)) { myTicket.VoteDic.Add(item.PoupID, item.VoteType); } //myTicket.CurrentOperator = operatorRule.GetModel(t.ID); currentTicketList.Add(myTicket); } if (currentTicketList.Count == 1) { //MyTicket.CurrentTicket = currentTicketList[0];//唯一角色的用户直接进入系统 result.Success = true; result.Url = "/Home/Index"; //记录登录日志 LoginLog log = new LoginLog(); log.OperatorID = MyTicket.CurrentTicket.UserID; log.CreateTime = DateTime.Now; log.Type = 1; log.ID = WebHelper.GetNewGuidUpper(); new LoginLogRule().Add(log); } else { Session["currentUserList"] = currentTicketList;//记录角色列表,等待用户选择 return Json(currentTicketList, JsonRequestBehavior.AllowGet); } } } return Json(result, JsonRequestBehavior.AllowGet); }
/// <summary> /// 设置登录角色 /// </summary> /// <returns></returns> public ActionResult SetLoginGroup(string groupID) { List<Ticket> currentTicketList = (List<Ticket>)HttpContext.Cache["UserList"] as List<Ticket>; foreach (Ticket t in currentTicketList) { if (t.GroupID == groupID) { HttpContext.Items["User"] = t; UserManager.ChangeRole(t, Response); //MyTicket.CurrentTicket = t; //记录登录日志 LoginLog log = new LoginLog(); log.OperatorID = t.UserID; log.CreateTime = DateTime.Now; log.Type = 1; log.ID = WebHelper.GetNewGuidUpper(); new LoginLogRule().Add(log); break; } } return RedirectToAction("Index", "Home"); }
/// <summary> /// 退出登录 /// </summary> /// <returns></returns> public ActionResult LoginOut() { //记录登录日志 if (MyTicket.CurrentTicket != null) { LoginLog log = new LoginLog(); log.OperatorID = MyTicket.CurrentTicket.UserID; log.CreateTime = DateTime.Now; log.Type = 0; log.ID = WebHelper.GetNewGuidUpper(); new LoginLogRule().Add(log); } //MyTicket.CurrentTicket = null; Session["currentUserList"] = null; Session.Clear(); UserManager.Logoff(Session, Response); return RedirectToAction("Login", "Home"); }