public ActionResult Login(LoginViewModel loginViewModel) { if (ModelState.IsValid) { string _password = Security.SHA256(loginViewModel.Password); var _response = adminManager.Login(loginViewModel.Accounts, _password); //修改 if (_response.Code == 1) { var _admin = adminManager.Find(loginViewModel.Accounts); CurrUser.Serialize(_admin.ID, _admin.Accounts, "admin"); _admin.LoginTime = DateTime.Now; _admin.LoginIP = Request.UserHostAddress; adminManager.Update(_admin); //记录日志 log.Info(Utils.GetIP(), _admin.Accounts, Request.Url.ToString(), "Login", "后台登录成功"); return(RedirectToAction("Index", "Admin", new { Areas = "Control" })); } else if (_response.Code == 2) { ModelState.AddModelError("Accounts", _response.Message); } else if (_response.Code == 3) { ModelState.AddModelError("Password", _response.Message); } else { ModelState.AddModelError("", _response.Message); } log.Info(Utils.GetIP(), loginViewModel.Accounts, Request.Url.ToString(), "Login", "后台登录失败"); } return(View(loginViewModel)); }
public static void Info(string clientUser, string requestUri, string action, object message, Exception t = null) { if (t == null) { logmonitor.Info(GetIP(), clientUser, requestUri, action, message); } else { logmonitor.Info(GetIP(), clientUser, requestUri, action, message, t); } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); var Request = filterContext.HttpContext.Request; string ViewTime = DateTime.Now.ToString("yyyy-MM-dd"); string ViewIp = Request.UserHostAddress; //记录日志 log.Info(Utils.GetIP(), "一般访问者", "Home", "Index", "访问网站! 时间:" + ViewTime + "IP:" + ViewIp); }
/// <summary> /// 向日志文件写入运行时信息 /// </summary> /// <param name="className">类名</param> /// <param name="content">写入内容</param> public static void Info(string className, string content) { var methodinfo = SystemModule(); IExtLog extLog = ExtLogManager.GetLogger(dblog); string url = ""; if (HttpContext.Current != null) { url = HttpContext.Current.Request.Url.ToString(); } extLog.Info(GetIPAddress(), methodinfo, url, className, content); }
/// <summary> /// 登录验证 /// </summary> /// <param name="email"></param> /// <param name="pwd"></param> /// <returns></returns> //[ValidateAntiForgeryToken] public ActionResult UserLogin(string email, string pwd) { var json = new JsonHelper() { Msg = "", Status = "" }; try { var user = userManage.UserLogin(email, pwd); if (user != null) { if (user.UserStatu == "1") { json.Msg = "用户状态已经被锁定,请联系管理员进行解锁"; log.Warn(Utils.GetIP(), user.UserEmail, Request.Url.ToString(), "Login", "用户登录,结果为:" + json.Msg); return(Json(json)); } json.Msg = "登录成功"; json.Status = "Y"; log.Info(Utils.GetIP(), user.UserEmail, Request.Url.ToString(), "Login", "用户登录,结果为:" + json.Msg); return(RedirectToAction("index", "Home")); } else { json.Msg = "密码错误或者用户名错误"; log.Error(Utils.GetIP(), email, Request.Url.ToString(), "Login", "用户登录,结果为:" + json.Msg); return(Json(json)); } } catch (Exception e) { json.Msg = e.Message; log.Error(Utils.GetIP(), email, Request.Url.ToString(), "Login", "用户登录,结果为:" + json.Msg); } return(Json(json, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 操作日志 /// </summary> public void WriteLog(Common.Enums.enumOperator action, string message, Common.Enums.enumLog4net logLevel) { switch (logLevel) { case Common.Enums.enumLog4net.INFO: _log.Info(Utils.GetIP(), this.CurrentUser.Name, Request.Url.ToString(), action.ToString(), message); break; case Common.Enums.enumLog4net.WARN: _log.Warn(Utils.GetIP(), this.CurrentUser.Name, Request.Url.ToString(), action.ToString(), message); break; default: _log.Error(Utils.GetIP(), this.CurrentUser.Name, Request.Url.ToString(), action.ToString(), message); break; } }
public void WriteLog(enumOperator action, string message, enumLog4net logLevel) { switch (logLevel) { case enumLog4net.INFO: _log.Info(Utils.GetIP(), CurrentUser.Name, Request.Url.ToString(), action.ToString(), message); return; case enumLog4net.WARN: _log.Warn(Utils.GetIP(), CurrentUser.Name, Request.Url.ToString(), action.ToString(), message); return; default: _log.Error(Utils.GetIP(), CurrentUser.Name, Request.Url.ToString(), action.ToString(), message); return; } }
public ActionResult Login(Domain.SYS_USER item) { var json = new JsonHelper() { Msg = "登录成功", Status = "n" }; try { //获取表单验证码 var code = Request.Form["code"]; if (Session["gif"] != null) { //判断用户输入的验证码是否正确 if (!string.IsNullOrEmpty(code) && code.ToLower() == Session["gif"].ToString().ToLower()) { //调用登录验证接口 返回用户实体类 var users = UserManage.UserLogin(item.ACCOUNT.Trim(), item.PASSWORD.Trim()); if (users != null) { //是否锁定 if (users.ISCANLOGIN) { json.Msg = "用户已锁定,禁止登录,请联系管理员进行解锁"; log.Warn(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg); return(Json(json)); } var acconut = this.UserManage.GetAccountByUser(users); //系统访问正常 if (acconut.System_Id.Count > 0) { //是否启用单用户登录 if (System.Configuration.ConfigurationManager.AppSettings["IsSingleLogin"] == "True") { var UserOnline = UserOnlineManage.LoadListAll(p => p.FK_UserId == users.ID).FirstOrDefault(); if (UserOnline != null && UserOnline.IsOnline) { json.Msg = "当前用户已登录,系统不允许重复登录!登录IP:" + UserOnline.UserIP; log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "重复登录:" + json.Msg); } else { //写入Session 当前登录用户 SessionHelper.SetSession("CurrentUser", acconut); //记录用户信息到Cookies string cookievalue = "{\"id\":\"" + acconut.Id + "\",\"username\":\"" + acconut.LogName + "\",\"password\":\"" + acconut.PassWord + "\",\"ToKen\":\"" + Session.SessionID + "\"}"; CookieHelper.SetCookie("cookie_rememberme", new Common.CryptHelper.AESCrypt().Encrypt(cookievalue), null); json.Status = "y"; json.ReUrl = "/Sys/Home/Index"; log.Info(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg); } } else { //写入Session 当前登录用户 SessionHelper.SetSession("CurrentUser", acconut); //记录用户信息到Cookies string cookievalue = "{\"id\":\"" + acconut.Id + "\",\"username\":\"" + acconut.LogName + "\",\"password\":\"" + acconut.PassWord + "\",\"ToKen\":\"" + Session.SessionID + "\"}"; CookieHelper.SetCookie("cookie_rememberme", new Common.CryptHelper.AESCrypt().Encrypt(cookievalue), null); json.Status = "y"; json.ReUrl = "/Sys/Home/Index"; log.Info(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg); } } else { json.Msg = "站点来源不可信,系统拒绝登录"; log.Warn(Utils.GetIP(), "其他系统访问者", "", "Login", "其他系统登录失败,原因:系统验证错误,系统拒绝登录"); } } else { json.Msg = "用户名或密码不正确"; log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg); } } else { json.Msg = "验证码不正确"; log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg); } } else { json.Msg = "验证码已过期,请刷新验证码"; log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg); } } catch (Exception e) { json.Msg = e.Message; log.Error(Utils.GetIP(), item.ACCOUNT, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg); } return(Json(json, JsonRequestBehavior.AllowGet)); }
public static void Info(string Msg) { loginfo.Info(Msg); }