public void CreateLoginLog(Login_Log log) { using (chargebitEntities db = new chargebitEntities()) { if(log!=null) { if(!string.IsNullOrEmpty(log.LoginIP) && log.UserId>0 && log.LoginTime>0) { db.Login_Log.Add(log); db.SaveChanges(); } } } }
private ActionResult RedirectToLocal(string loginEmail,string returnUrl) { UserManagement umgt=new UserManagement(loginEmail); if (umgt.CurrentLoginUser != null) { Login_Log log = new Login_Log() { UserId = umgt.CurrentLoginUser.User.Id, LoginTime = KMBit.Util.DateTimeUtil.ConvertDateTimeToInt(DateTime.Now), LoginIP = Request.UserHostAddress }; if(!umgt.CurrentLoginUser.User.Enabled) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); log.Message = "账户被锁定,不能登陆系统,请联系管理员"; log.Succeed = false; umgt.CreateLoginLog(log); return RedirectToAction("LoginError", "Account",new { message= "账户被锁定,不能登陆系统,请联系管理员" }); } log.Message = ""; log.Succeed = true; umgt.CreateLoginLog(log); if (umgt.CurrentLoginUser.IsAdmin) { return RedirectToAction("Index", "Admin"); } else { return RedirectToAction("Index", "Agent"); } } if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } if (string.IsNullOrEmpty(loginEmail)) { return RedirectToAction("Index", "Home"); } return RedirectToAction("Index", "Home"); }