public virtual ActionResult Login(UserLoginModel model) { if (ModelState.IsValid) { string _UserName = model.Username; CMSUser predictedUser = CMSUser.GetByUsername(model.Username); if (predictedUser == null) { ModelState.AddModelError("", "Invalid UserName or password"); return(View()); } string _Password = GetEncriptedPassword(model.Password, predictedUser.UserPrivateSecret); CMSUser _User = CMSUser.GetByUsernameAndPassword(_UserName, _Password); if (_User == null) { ModelState.AddModelError("", "Invalid Email or password"); return(View()); } else { CookieHelper.RemoveAll(); CookieHelper.Add("Administrator_Username", _User.Username, false, true); return(RedirectToAction(MVC.Home.Index())); } } return(View()); }
public ActionResult Sign(LoginParameter loginPara) { string res = mUserMgr.Login(loginPara.MobileOrEmail, loginPara.Password); MsgInfo loginMsg = JsonConvert.DeserializeObject <MsgInfo>(res); if (!loginMsg.IsError) { LoginUsers loginUser = JsonConvert.DeserializeObject <LoginUsers>(loginMsg.Msg); string strUserData = JsonConvert.SerializeObject(loginUser); //保存身份信息 FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, loginUser.Mobile, DateTime.Now, DateTime.Now.AddHours(12), false, strUserData); CookieHelper.Add(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(Ticket), RootDomain);//加密身份信息,保存至Cookie loginMsg.Msg = loginPara.ReturnUrl; if (loginPara.IsRemember) { CookieHelper.Add("remember", loginUser.Mobile + "$" + Security.DESEncrypt(loginPara.Password), RootDomain); } else { CookieHelper.Remove("remember"); } } return(Json(loginMsg)); }
public AjaxResult Login(string eid, string pwd) { AjaxResult ajaxResult = new AjaxResult(false); var result = this.ValidPwd(eid, pwd); if (result != null) { if (result.Flag) { string wwid = GetEID(eid); var user = userRep.GetUser(wwid); if (user != null && user.UserID > 0) { ajaxResult.Type = ResultType.Success; ajaxResult.Msg = "登录成功"; string loginCookieKey = WebConst.UserLoginCookieKey; CookieHelper.Add(loginCookieKey, user.WWID, DateTimeType.Minute, 30); string sessionKey = WebConst.UserLoginSessionKey; SessionHelper.Add(sessionKey, user); } } } if (ajaxResult.Type == ResultType.Error) { ajaxResult.Msg = "登录失败,请检查用户名或密码"; } return(ajaxResult); }
public ActionResult Sign(string account, string password, string rUrl, string remember) { string res = (new SystemAccountManager()).Login(account, password); MsgInfo loginMsg = JsonConvert.DeserializeObject <MsgInfo>(res); if (!loginMsg.IsError) { LoginUsers loginUser = JsonConvert.DeserializeObject <LoginUsers>(loginMsg.Msg); string strUserData = JsonConvert.SerializeObject(loginUser); //保存身份信息 FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, account, DateTime.Now, DateTime.Now.AddHours(12), false, strUserData); CookieHelper.Add(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(Ticket), RootDomain);//加密身份信息,保存至Cookie loginMsg.Msg = rUrl; if (remember == "true") { CookieHelper.Add("remember", loginUser.Account + "$" + Security.DESEncrypt(password), RootDomain); } else { CookieHelper.Add("remember", "", RootDomain); } } return(Json(loginMsg)); }
public ActionResult CheckCode() { string checkCode = CheckCodeHelper.GetEngAndNum(4); Session["CheckCode"] = checkCode; CookieHelper.Add("QTXgt7AC5q5aLlVLwpTw", checkCode, 10); return(File(CheckCodeHelper.CreateToByte(checkCode, false), @"image/jpeg")); }
public ActionResult Index(Register value) { MsgInfo returnMsg = new MsgInfo { IsError = false, Msg = "", MsgNo = (int)ErrorEnum.成功 }; string code = Convert.ToString(CacheHelper.GetCache("code_" + Session.SessionID)); if (code != value.MobileYzm) { returnMsg.IsError = true; returnMsg.Msg = "手机验证码错误"; returnMsg.MsgNo = (int)ErrorEnum.失败; return(Json(returnMsg)); } UserInfo user = new UserInfo { CreateDate = DateTime.Now, CreateIP = this.GetIP, Mobile = value.Mobile, Email = Guid.NewGuid().ToString(), Status = (int)UserStatusEnum.正常, UserType = value.UserType, Password = Security.DESEncrypt(value.Password) }; UserManager userMgr = new UserManager(); int id = userMgr.Create(user); if (id > 0) { LoginUsers loginUser = new LoginUsers { Avatar = string.Empty, Email = string.Empty, Id = id, IsVIP = false, Mobile = value.Mobile }; string strUserData = JsonConvert.SerializeObject(loginUser); //保存身份信息 FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, loginUser.Mobile, DateTime.Now, DateTime.Now.AddHours(12), false, strUserData); CookieHelper.Add(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(Ticket), RootDomain);//加密身份信息,保存至Cookie returnMsg.Msg = "成功"; } else { returnMsg.Msg = "失败"; } return(Json(returnMsg)); }
public void Set <T>(string key, T value, TimeSpan?expire = null) where T : class { string sessionID; if (!CookieHelper.TryGetValue("SessionID", out sessionID)) { sessionID = System.Web.HttpContext.Current.Session.SessionID; CookieHelper.Add("SessionID", sessionID); } Cache.Set <T>(sessionID + "_" + key, value, expire ?? expire); }
private bool CacheTicketStatus(string statusJson = "[]") { DateTime local = DateTime.Now; string uniqueCacheKey = string.Format("TicketStatus_{0}_{1}", UserInfo.Role, local.ToString("yyyyMMdd")); CookieHelper helper = new CookieHelper(); string cache = helper.Get(uniqueCacheKey); if (!string.IsNullOrEmpty(cache)) { helper.Remove(uniqueCacheKey); } helper.Add(uniqueCacheKey, statusJson, local.AddDays(1)); return(true); }
public int Up(int id) { string IPID = JustSay.Common.DotNetEncrypt.Md5Helper.MD5(HttpContext.Current.User.Identity.Name + id.ToString(), 16); if (!CookieHelper.IsExistCookie(JustSay.Config.EncryptConfig.FunnyUpCookieName, IPID)) { CookieHelper.Add(JustSay.Config.EncryptConfig.FunnyUpCookieName, IPID, "1", DateTime.Now.AddDays(1)); Funny funny = GetDetail(f => f.ID == id); funny.Up += 1; db.SaveChanges(); return(funny.Up); } else { return(-1); } }
public int Up(int id) { string IPID = JustSay.Common.DotNetEncrypt.Md5Helper.MD5(HttpContext.Current.User.Identity.Name + id.ToString(), 16); if (!CookieHelper.IsExistCookie(JustSay.Config.EncryptConfig.ConfessUpCookieName, IPID)) { CookieHelper.Add(JustSay.Config.EncryptConfig.ConfessUpCookieName, IPID, "1", DateTime.Now.AddDays(1)); Confess confess = GetDetail(f => f.ID == id); confess.Up += 1; base.Submit(); return(confess.Up); } else { return(-1); } }
public AjaxResult Login(string eid, string pwd) { string msg = string.Empty; bool flag = false; pwd = EncryptHelper.Encrypt(pwd); var user = userRep.GetEntity(m => m.ACCOUNT == eid && m.PWD == pwd && m.STATUS == 1); if (user != null && user.ID > 0) { int minutes = WebConst.UserLoginExpiredMinutes; string loginKey = Guid.NewGuid().ToString(); var browser = HttpContext.Current.Request.Browser; UserLogin login = new UserLogin(); login.IP = UtilityHepler.GetIPAddress(); login.LOGINTIME = DateTime.Now; login.LOGINKEY = loginKey; login.STATUS = true; login.DESCRIPTION = "用户登录系统"; login.EMPLOYEEID = eid; login.EXPIREDTIME = login.LOGINTIME.AddMinutes(minutes); login.BROWSER = string.Format("{0}_{1}", browser.Browser, browser.Version); userRep.Login(login); string loginCookieKey = WebConst.UserLoginCookieKey; CookieHelper.Add(loginCookieKey, loginKey, DateTimeType.Minute, minutes * 10); flag = true; string sessionKey = WebConst.UserLoginSessionKey; SessionHelper.Add(sessionKey, user); } else { msg = "用户名或密码有误"; } return(new AjaxResult(flag, msg)); }
public AjaxResult Login(string eid, string pwd, bool remember) { AjaxResult ajaxResult = new AjaxResult(false); var user = userRep.GetUser(eid); if (user == null || user.Id < 1) { ajaxResult.Msg = "没有找到此用户"; return(ajaxResult); } if (user.CannotLoginUntilDateUtc.HasValue && user.CannotLoginUntilDateUtc.Value > DateTime.UtcNow) { ajaxResult.Msg = "此用户被锁定,请联系管理员"; return(ajaxResult); } var password = userRep.GetUserPassword(user.Id); if (password == null || password.Id < 1) { ajaxResult.Msg = "密码错误"; return(ajaxResult); } bool validPwd = ValidPwd(password, pwd); if (!validPwd) { //wrong password user.FailedLoginAttempts++; int allowedAttempts = UtilityHepler.GetAppSettingInt("PasswordAllowedAttempts"); if (allowedAttempts > 0 && user.FailedLoginAttempts >= allowedAttempts) { int lockedMinutes = UtilityHepler.GetAppSettingInt("PasswordLockedMinutes"); //lock out user.CannotLoginUntilDateUtc = DateTime.UtcNow.AddMinutes(lockedMinutes); //reset the counter user.FailedLoginAttempts = 0; } userRep.UpdateUser(user, false); //_customerService.UpdateCustomer(customer); ajaxResult.Msg = "密码错误"; return(ajaxResult); } //update login details user.FailedLoginAttempts = 0; user.CannotLoginUntilDateUtc = null; user.RequireReLogin = false; user.LastLoginDateUtc = DateTime.UtcNow; bool updatedUser = userRep.UpdateUser(user, true); if (updatedUser) { ajaxResult.Type = ResultType.Success; ajaxResult.Msg = "登录成功"; if (remember) { string loginCookieKey = WebConst.UserLoginCookieKey; string value = encryService.EncryptText(user.Username); CookieHelper.Add(loginCookieKey, value, DateTimeType.Minute, 30); } string sessionKey = WebConst.UserLoginSessionKey; SessionHelper.Add(sessionKey, user); } else { ajaxResult.Msg = "系统错误,暂时无法登录系统"; } return(ajaxResult); }
public static void Add(string key, string value, int day) { key = EncryptKey(key); value = EncryptValue(value); CookieHelper.Add(key, value, day); }
/// <summary> /// 退出系统 /// </summary> /// <returns>执行结果</returns> public ActionResult Exit() { DawnauthHandler.ClearLogin(); CookieHelper.Add("logout", "safe", 1); return(RedirectToAction("Login")); }
/// <summary> /// 退出系统 /// </summary> public static void Exit() { DawnauthHandler.ClearLogin(); CookieHelper.Add("logout", "safe", 1); }