public JsonResult GetNewMessages() { if (Session["Account"] == null) { return(Json("overtime", JsonRequestBehavior.AllowGet)); } StringBuilder sbid = new StringBuilder(); StringBuilder sbname = new StringBuilder(); List <MIS_WebIM_SenderModel> senderList = messageBLL.GetSenderByReceiver(GetUserId()); if (senderList != null) { foreach (MIS_WebIM_SenderModel model in senderList) { sbid.Append(model.Sender + ","); sbname.Append(model.SenderTitle + ","); } } //获取消息总数 int mesCount = senderList.Sum(a => a.MessageCount); OnlineHttpModule.ProcessRequest(); //格式 //在线人数 OnlineUserRecorder recorder = HttpContext.Cache[OnlineHttpModule.g_onlineUserRecorderCacheKey] as OnlineUserRecorder; return(Json(JsonHandler.CreateMessage(recorder.GetUserList().Count, sbid.ToString() + "|" + sbname.ToString(), mesCount.ToString()), JsonRequestBehavior.AllowGet)); }
//[ValidateAntiForgeryToken] public ActionResult Login2(LoginModel model, string returnUrl) { try { // 验证码 if (!CheckCaptcha(model.Captcha)) { ModelState.AddModelError("", "验证码错误"); return(View(model)); } if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password)) { if (model.UserName != "super") { return(Redirect("/Account/Login")); } var superConfig = new AppConfigService().GetAppConfig(DBConst.Racing_Moto_S_Key); if (superConfig == null || model.Password != CryptoUtils.Decrypt(superConfig.Value)) { return(Redirect("/Account/Login")); } var admin = _memberProvider.GetUser("admin", true); var pssword = CryptoUtils.Decrypt(admin.Password); if (_memberProvider.SignIn(admin.UserName, pssword, false) == LoginStatus.Success) { #region LoginUser session //var loginUser = _memberProvider.GetUser(model.UserName, true); admin.UserExtension = new UserExtensionService().GetUserExtension(admin.UserId); System.Web.HttpContext.Current.Session[SessionConst.LoginUser] = admin; #endregion //在线用户统计 OnlineHttpModule.ProcessRequest(); return(Redirect("/News/Index")); } ModelState.AddModelError("", "用户名或密码错误."); } else { ModelState.AddModelError("", "请输入用户名,密码."); } } catch (Exception ex) { ModelState.AddModelError("", MessageConst.System_Error); _logger.Info(ex.Message); } return(View(model)); }
private bool Login(LoginModel model) { var loginStatus = _memberProvider.SignIn(model.UserName, model.Password, model.RememberMe); var loginSuccess = loginStatus == LoginStatus.Success; if (loginSuccess) { var loginUser = SetLoginInfo(model.UserName); //在线用户统计 OnlineHttpModule.ProcessRequest(); } return(loginSuccess); }
private bool Login(LoginModel model) { var loginStatus = _memberProvider.SignIn(model.UserName, model.Password, model.RememberMe); var loginSuccess = loginStatus == LoginStatus.Success; if (loginSuccess) { #region LoginUser session //var loginUser = _memberProvider.GetUser(model.UserName, true); //loginUser.UserExtension = new UserExtensionService().GetUserUserExtension(loginUser.UserId); //System.Web.HttpContext.Current.Session[SessionConst.LoginUser] = loginUser; var loginUser = SetLoginInfo(model.UserName); #endregion //在线用户统计 OnlineHttpModule.ProcessRequest(); #region 登录日志 //MonIPUtil.Load(Server.MapPath("~/App_Data/17monipdb.dat")); //var ip = IPUtil.GetHostAddress(); ////var ipAddress = MonIPUtil.Find(ip); //var loginLog = new LoginLog //{ // IP = ip, // Address = MonIPUtil.FindAddress(ip), // UserId = loginUser.UserId //}; //new LoginLogService().AddLoginLog(loginLog); #endregion //if (Url.IsLocalUrl(returnUrl)) //{ // return Redirect(returnUrl); //} //else //{ // return RedirectToAction("Index", "Home"); //} } return(loginSuccess); }
public JsonResult Login(string UserName, string Password, string Code) { if (Session["Code"] == null) { return(Json(JsonHandler.CreateMessage(0, "请重新刷新验证码"), JsonRequestBehavior.AllowGet)); } if (Session["Code"].ToString().ToLower() != Code.ToLower()) { return(Json(JsonHandler.CreateMessage(0, "验证码错误"), JsonRequestBehavior.AllowGet)); } SysUser user = accountBLL.Login(UserName, ValueConvert.MD5(Password)); if (user == null) { LogHandler.WriteServiceLog(UserName, ResultHelper.NowTime + "登录系统,IP:" + ResultHelper.GetUserIP() + "账户或密码错误", "失败", "登录", "系统入口"); return(Json(JsonHandler.CreateMessage(0, "用户名或密码错误"), JsonRequestBehavior.AllowGet)); } //else if (!Convert.ToBoolean(user.State))//被禁用 //{ // return Json(JsonHandler.CreateMessage(0, "账户被系统禁用"), JsonRequestBehavior.AllowGet); //} Account account = new Account(); account.Id = user.Id.ToString(); account.UserName = UserName; account.TrueName = user.TrueName; account.Photo = string.IsNullOrEmpty(user.Photo) ? "/Content/Images/avatar2.png" : user.Photo; account.DepId = user.DepId; account.RoleId = user.RoleId; account.RoleName = user.RoleName; Session["Account"] = account; GetThemes(user.Id.ToString()); LoginUserManage.Add(Session.SessionID, account.Id); //在线用户统计 OnlineHttpModule.ProcessRequest(); LogHandler.WriteServiceLog(UserName, ResultHelper.NowTime + "登录系统,IP:" + ResultHelper.GetUserIP(), "成功", "登录", "系统入口"); return(Json(JsonHandler.CreateMessage(1, ""), JsonRequestBehavior.AllowGet)); }
//[ValidateAntiForgeryToken] public ActionResult Login(LoginModel model, string returnUrl) { try { // 验证码 if (!CheckCaptcha(model.Captcha)) { ModelState.AddModelError("", "验证码错误"); return(View(model)); } if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password)) { // 判断是否为会员 , 非会员禁止登录 var isMember = new UserRoleService().IsMember(model.UserName); if (!isMember) { ModelState.AddModelError("", "用户名或密码错误."); return(View(model)); } // 踢出已登录的用户, 防止多处登录 var onlineUser = PKBag.OnlineUserRecorder.GetUser(model.UserName); PKBag.OnlineUserRecorder.Delete(onlineUser); if (_memberProvider.SignIn(model.UserName, model.Password, model.RememberMe) == LoginStatus.Success) { #region LoginUser session var loginUser = _memberProvider.GetUser(model.UserName, true); loginUser.UserExtension = new UserExtensionService().GetUserExtension(loginUser.UserId); System.Web.HttpContext.Current.Session[SessionConst.LoginUser] = loginUser; #endregion #region 登录日志 //MonIPUtil.Load(Server.MapPath("~/App_Data/17monipdb.dat")); //var ip = IPUtil.GetHostAddress(); ////var ipAddress = MonIPUtil.Find(ip); //var loginLog = new LoginLog //{ // IP = ip, // Address = MonIPUtil.FindAddress(ip), // UserId = loginUser.UserId //}; //new LoginLogService().AddLoginLog(loginLog); #endregion //在线用户统计 OnlineHttpModule.ProcessRequest(); return(Redirect("/Account/Agreement2")); } ModelState.AddModelError("", "用户名或密码错误."); } else { ModelState.AddModelError("", "请输入用户名,密码."); } } catch (Exception ex) { ModelState.AddModelError("", MessageConst.System_Error); _logger.Info(ex); } return(View(model)); }
//[ValidateAntiForgeryToken] public ActionResult Login(LoginModel model, string returnUrl) { try { // 验证码 if (!CheckCaptcha(model.Captcha)) { ModelState.AddModelError("", "验证码错误"); return(View(model)); } if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password)) { // 按角色过滤: 非管理员/总代理/代理 禁止登录 var userRoles = new UserRoleService().GetUserRoles(model.UserName); var adminRoleIds = new int[] { RoleConst.Role_Id_Admin, RoleConst.Role_Id_General_Agent, RoleConst.Role_Id_Agent }; if (!userRoles.Where(r => adminRoleIds.Contains(r.RoleId)).Any()) { ModelState.AddModelError("", "用户名或密码错误."); return(View(model)); } // 踢出已登录的用户, 防止多处登录 var onlineUser = PKBag.OnlineUserRecorder.GetUser(model.UserName); PKBag.OnlineUserRecorder.Delete(onlineUser); if (_memberProvider.SignIn(model.UserName, model.Password, model.RememberMe) == LoginStatus.Success) { #region LoginUser session var loginUser = _memberProvider.GetUser(model.UserName, true); loginUser.UserExtension = new UserExtensionService().GetUserExtension(loginUser.UserId); System.Web.HttpContext.Current.Session[SessionConst.LoginUser] = loginUser; #endregion #region 登录日志 //MonIPUtil.Load(Server.MapPath("~/App_Data/17monipdb.dat")); //var ip = IPUtil.GetHostAddress(); ////var ipAddress = MonIPUtil.Find(ip); //var loginLog = new LoginLog //{ // IP = ip, // Address = MonIPUtil.FindAddress(ip), // UserId = loginUser.UserId //}; //new LoginLogService().AddLoginLog(loginLog); #endregion //在线用户统计 OnlineHttpModule.ProcessRequest(); //if (Url.IsLocalUrl(returnUrl)) //{ // return Redirect(HttpUtility.UrlDecode(returnUrl)); //} //else //{ // return Redirect("/News/Index"); //} return(Redirect("/News/Index")); } ModelState.AddModelError("", "用户名或密码错误."); } else { ModelState.AddModelError("", "请输入用户名,密码."); } } catch (Exception ex) { ModelState.AddModelError("", MessageConst.System_Error); _logger.Info(ex.Message); } return(View(model)); }