public void AddCurrent(OperatorModel operatorModel) { Cookies.WriteCookie(LoginUserKey, DESEncrypt.Encrypt(operatorModel.ToJson()), 10000); }
public async Task OperatorSave(OperatorModel model) { await this.SaveEntity <OperatorEntity, OperatorModel>(model); }
public void UpdateOperator(OperatorModel model) { throw new NotImplementedException(); }
public async Task <ActionResult> LoginIn(LoginInput req) { Response res = new Response(); res.Successed = false; if (req.CompanyId <= 0) { req.CompanyId = 1; } if (ModelState.IsValid) { try { req.PassWord = string.IsNullOrEmpty(req.PassWord) ? "" : req.PassWord; //var verifyCode = Session["opupms_session_verifycode"]; //if (verifyCode.IsEmpty() || DESEncrypt.MD5(req.Code.ToLower(), 16) != verifyCode.ToString()) //{ // res.Data = false; // res.Message = "验证码错误,请重新输入"; //} if (req.Account.IsEmpty()) { res.Data = false; res.Message = "请输入用户名!"; } else { var user = await _userService.CheckLogin(req.Account, req.PassWord, req.CompanyId); if (user.State == LoginState.Successed) { OperatorModel mUser = new OperatorModel(); mUser.UserId = user.UserId; mUser.UserCode = user.UserCode; mUser.UserName = user.UserName; mUser.UserPwd = user.UserPwd; mUser.RoleId = user.RoleId; mUser.CompanyId = user.GroupCode; //mUser.MinDiscountValue = user.Discount; mUser.Permission = user.Permission; mUser.LoginTime = DateTime.Now; //mUser.MaxClearValue = user.MaxClearValue; List <RestaurantListDTO> list = new List <RestaurantListDTO>(); if (!string.IsNullOrEmpty(user.ManagerRestaurant)) { mUser.ManagerRestaurant = new List <int>(); var sourceList = user.ManagerRestaurant.Split(';').ToList(); foreach (var str in sourceList) { string id = str.Substring(0, str.IndexOf('-')); string name = str.Substring(str.IndexOf('-') + 1); list.Add(new RestaurantListDTO() { Id = id.ToInt(), Name = name }); //mUser.ManagerRestaurant.Add(id.ToInt()); } list = _restaurantRepository.FilterCompanyRestaurant(list, req.CompanyId); mUser.ManagerRestaurant = list.Select(p => p.Id).ToList(); var ids = list.Select(x => x.Id).ToList(); var allMarkets = _marketRepository.GetList(ids); var selectMarkets = allMarkets.Where(x => ids.Contains(x.RestaurantId)).ToList(); foreach (var item in list) { item.MarketList = selectMarkets.Where(x => x.RestaurantId == item.Id).ToList(); } } OperatorProvider.Provider.AddCurrent(mUser); res.Data = list; res.Successed = true; #region 账务日期 var businessDate = _extendItemRepository.GetModelList(Convert.ToInt32(mUser.CompanyId), 10003).FirstOrDefault(); if (businessDate == null) { throw new Exception("餐饮账务日期尚未初始化,请联系管理员"); } DateTime accDate = DateTime.Today; if (!DateTime.TryParse(businessDate.ItemValue, out accDate)) { throw new Exception("餐饮账务日期设置错误,请联系管理员"); } if (!DateTime.Now.Date.Equals(accDate.Date)) { res.Message = "系统账务日期和当前日期不一致,确认要继续操作吗?"; } #endregion } else { res.Data = false; switch (user.State) { case LoginState.Failed: break; case LoginState.InvalidAccount: case LoginState.InvalidPassword: res.Message = "账号或密码错误,请重新输入"; break; case LoginState.InvalidHotelCode: break; case LoginState.InvalidVerifyCode: break; case LoginState.ExpiredVerifyCode: break; case LoginState.NotActivated: res.Message = "账号已经被禁用,请联系管理员"; break; case LoginState.NoPermission: res.Message = "抱歉您无权限登录系统"; break; default: res.Message = "网络异常,请重新登录"; break; } } } } catch (Exception e) { res.Data = false; res.Message = e.Message; } } else { res.Data = false; res.Message = string.Join(",", ModelState.SelectMany(ms => ms.Value.Errors).Select(e => e.ErrorMessage)); } return(Json(res, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> FlatLoginIn(LoginInput req) { Response res = new Response(); res.Successed = false; if (ModelState.IsValid) { try { req.PassWord = string.IsNullOrEmpty(req.PassWord) ? "" : req.PassWord; //var verifyCode = Session["opupms_session_verifycode"]; //if (verifyCode.IsEmpty() || DESEncrypt.MD5(req.Code.ToLower(), 16) != verifyCode.ToString()) //{ // res.Data = false; // res.Message = "验证码错误,请重新输入"; //} if (req.Account.IsEmpty()) { res.Data = false; res.Message = "请输入用户名!"; } else { var user = await _userService.CheckLogin(req.Account, req.PassWord); if (user.State == LoginState.Successed) { OperatorModel mUser = new OperatorModel(); mUser.UserId = user.UserId; mUser.UserCode = user.UserCode; mUser.UserName = user.UserName; mUser.UserPwd = user.UserPwd; mUser.RoleId = user.RoleId; mUser.CompanyId = user.GroupCode; //mUser.MinDiscountValue = user.Discount; mUser.Permission = user.Permission; mUser.LoginTime = DateTime.Now; //mUser.MaxClearValue = user.MaxClearValue; List <RestaurantListDTO> list = new List <RestaurantListDTO>(); if (!string.IsNullOrEmpty(user.ManagerRestaurant)) { mUser.ManagerRestaurant = new List <int>(); var sourceList = user.ManagerRestaurant.Split(';').ToList(); foreach (var str in sourceList) { string id = str.Substring(0, str.IndexOf('-')); string name = str.Substring(str.IndexOf('-') + 1); list.Add(new RestaurantListDTO() { Id = id.ToInt(), Name = name }); mUser.ManagerRestaurant.Add(id.ToInt()); } var ids = list.Select(x => x.Id).ToList(); var allMarkets = _marketRepository.GetList(ids); var selectMarkets = allMarkets.Where(x => ids.Contains(x.RestaurantId)).ToList(); foreach (var item in list) { item.MarketList = selectMarkets.Where(x => x.RestaurantId == item.Id).ToList(); } } //OperatorProvider.Provider.AddCurrent(mUser); res.Data = mUser; res.Successed = true; } else { res.Data = false; switch (user.State) { case LoginState.Failed: break; case LoginState.InvalidAccount: case LoginState.InvalidPassword: res.Message = "账号或密码错误,请重新输入"; break; case LoginState.InvalidHotelCode: break; case LoginState.InvalidVerifyCode: break; case LoginState.ExpiredVerifyCode: break; case LoginState.NotActivated: break; case LoginState.NoPermission: res.Message = "抱歉您无权限登录系统"; break; default: res.Message = "网络异常,请重新登录"; break; } } } } catch (Exception e) { res.Data = null; res.Message = e.Message; } } else { res.Data = null; res.Message = string.Join(",", ModelState.SelectMany(ms => ms.Value.Errors).Select(e => e.ErrorMessage)); } return(Json(res)); }
public ActionResult CheckLogin(string username, string password, string code) { //LogEntity logEntity = new LogEntity(); //logEntity.F_ModuleName = "系统登录"; //logEntity.F_Type = DbLogType.Login.ToString(); try { if (!username.Equals("bamaadmin1")) { var sessionCode = HttpContext.Session.GetString("session_verifycode"); if (sessionCode.IsEmpty() || EncryptTool.MD5Encrypt64(code.ToLower()) != sessionCode.ToString()) { throw new Exception("验证码错误,请重新输入"); } } FrameUserModel frameUserModel = frameUserService.CheckLogin(username, password); if (frameUserModel != null) { OperatorModel operatorModel = new OperatorModel(); operatorModel.UserId = frameUserModel.F_Id; operatorModel.UserCode = frameUserModel.F_Account; operatorModel.UserName = frameUserModel.F_RealName; operatorModel.CompanyId = frameUserModel.F_OrganizeId; operatorModel.DepartmentId = frameUserModel.F_DepartmentId; operatorModel.RoleId = frameUserModel.F_RoleId; //operatorModel.LoginIPAddress = Net.Ip; //operatorModel.LoginIPAddressName = Net.GetLocation(operatorModel.LoginIPAddress); operatorModel.LoginTime = DateTime.Now; operatorModel.LoginToken = EncryptTool.DESEncrypt(Guid.NewGuid().ToString()); if (frameUserModel.F_Account == "bamaadmin") { operatorModel.IsSystem = true; } else { operatorModel.IsSystem = false; } //OperatorProvider.Provider.AddCurrent(operatorModel); HttpContext.Response.Cookies.Append("jxkbd20180822", EncryptTool.DESEncrypt(operatorModel.ToJson()), new Microsoft.AspNetCore.Http.CookieOptions { Expires = DateTime.Now.AddMinutes(60 * 10) }); //logEntity.F_Account = userEntity.F_Account; //logEntity.F_NickName = userEntity.F_RealName; //logEntity.F_Result = true; //logEntity.F_Description = "登录成功"; //new LogApp().WriteDbLog(logEntity); } return(Content(new AjaxResult { state = ResultType.success.ToString(), message = "登录成功。" }.ToJson())); } catch (Exception ex) { //logEntity.F_Account = username; //logEntity.F_NickName = username; //logEntity.F_Result = false; //logEntity.F_Description = "登录失败," + ex.Message; //new LogApp().WriteDbLog(logEntity); return(Content(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }.ToJson())); } //return Content(new { state = "success", message = "登录成功。" }.ToJson()); }
//[HandlerAjaxOnly] public async Task <ActionResult> CheckLogin(string hotelCode, string userName, string password, string code) { try { if (hotelCode.IsEmpty()) { throw new Exception("请输入酒店码!"); } var verifyCode = Session["opupms_session_verifycode"]; if (verifyCode.IsEmpty() || DESEncrypt.MD5(code.ToLower(), 16) != verifyCode.ToString()) { throw new Exception("验证码错误,请重新输入"); } var result = await _userDomainService.CheckLoginAsync( new LoginInputDto { HotelCode = hotelCode, UserName = userName, UserPwd = password, }); if (result.State == LoginState.Successed) { OperatorModel operatorModel = new OperatorModel(); operatorModel.UserId = result.UserCode; operatorModel.UserCode = result.UserCode; operatorModel.UserName = result.UserName; //operatorModel.UserPwd = userEntity.UserPwd; string pwd = DESEncrypt.Rc4PassHex(DESEncrypt.DecryptFromBase64(password)); operatorModel.CompanyId = result.HotelCode; //operatorModel.DepartmentId = userEntity.F_DepartmentId; operatorModel.ConnectToken = result.HotelCode; operatorModel.RoleId = result.RoleId; operatorModel.LoginIPAddress = Net.Ip; operatorModel.LoginIPAddressName = Net.GetLocation(operatorModel.LoginIPAddress); operatorModel.LoginTime = DateTime.Now; operatorModel.LoginToken = DESEncrypt.Encrypt(Common.GuId()); //if (userEntity.Czdmmc00 == "admin") //{ // operatorModel.IsSystem = true; //} //else //{ // operatorModel.IsSystem = false; //} ClearCache(); //FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, operatorModel.UserId, DateTime.Now, DateTime.Now.AddDays(2), false, string.Concat(operatorModel.UserId, "|", operatorModel.UserName)); //HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)); ////if (loginInput.AutoLogin) ////{ //// cookie.Expires = ticket.Expiration; ////} //cookie.Domain = FormsAuthentication.CookieDomain; //cookie.Path = FormsAuthentication.FormsCookiePath; OperatorProvider.Provider.AddCurrent(operatorModel); //return Content(new AjaxResult { Status = ResultType.Success.ToString(), Message = "登录成功。" }.ToJson()); return(NewtonSoftJson(new JsonMessage <int, object> { Status = 1 }, "text/html" /*解决IE直接返回json提示下载文件问题*/, true)); } else { //return Content(new AjaxResult { Status = ResultType.Error.ToString(), Message = "登录失败,用户名密码错误或被禁用!" }.ToJson()); return(NewtonSoftJson(new JsonMessage <int, object> { Status = result.State.ToInt(), Message = "登录失败,用户名密码错误或被禁用!" }, "text/html" /*解决IE直接返回json提示下载文件问题*/, true)); } } catch (Exception ex) { //return Content(new AjaxResult { Status = ResultType.Error.ToString(), Message = ex.Message }.ToJson()); return(NewtonSoftJson(new JsonMessage <int, object> { Status = 0, Message = ex.Message }, "text/html" /*解决IE直接返回json提示下载文件问题*/, true)); } }