public IActionResult Login([FromBody] Models.User.UserLoginInfoViewModel userInfo) { Util.Return.ReturnResult returnValue = new Util.Return.ReturnResult(); try { bool validateResult; String strErrorMsg = null; (validateResult, strErrorMsg) = ValidateData(userInfo); if (validateResult) { //使用用户名到数据库获取用户信息 DataBll.User.UserInfoDataBll userInfoDataBll = new DataBll.User.UserInfoDataBll(); Model.User.UserInfo user = userInfoDataBll.Get(userInfo.UserName); if (null != user && user.State == Model.EnumType.UserState.Normal && !String.IsNullOrWhiteSpace(userInfo.Password)) { String strPassword = Util.EncryptionAlgorithm.Md5Algorithm.Encryption32(userInfo.Password); if (strPassword == user.Password) { //生成Token Int32 expired = 1; if (userInfo.RememberMe) { expired = 30; } DateTime expiredTime = System.DateTime.UtcNow.AddDays(expired); HttpContext.Response.Cookies.Append( Util.LoginTokenHelper.LoginTokenName , Util.LoginTokenHelper.GetToken(userInfo.UserName, expiredTime) , new Microsoft.AspNetCore.Http.CookieOptions() { Expires = expiredTime }); returnValue.IsOperateSuccess = true; returnValue.Description = "Success"; } else { returnValue.Description = "Wrong password, please re-enter."; } } else { returnValue.Description = "This user not exist.Please re-enter your username and password."; } } else { returnValue.Description = strErrorMsg; } } catch (Exception ex) { returnValue.Description = "The server is abnormal, please try again later."; m_log.Error("Login fail.", ex); } return(new JsonResult(returnValue)); }
public ActionResult Login(string username, string pwd, string idt, string autoLogin) { if (string.IsNullOrWhiteSpace(username)) { //手机号/会员名/邮箱 为空 return(GetJson(0, new { flag = 1 })); } if (string.IsNullOrWhiteSpace(pwd)) { //密码 为空 return(GetJson(0, new { flag = 2 })); } if (string.IsNullOrWhiteSpace(idt) || !new List <string>() { "p", "s" }.Any(item => item == idt)) { //非法操作 return(GetJson(0, new { flag = 3 })); } //是否勾选 '7天自动登录' bool isChecked = false; if (!string.IsNullOrWhiteSpace(autoLogin) && autoLogin == "1") { isChecked = true; } pwd = pwd.ToMd5(); Model.User.UserInfo userInfo = null; if (idt == "p") //求职者登录 { Model.Person person = _PersonServices.QueryWhere(item => (item.Phne == username || item.Email == username || item.RealName == username) && item.Password.Equals(pwd, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); if (person == null) { //用户名或密码错误 return(GetJson(2, new { flag = 1, idt = idt })); } else { userInfo = new Model.User.UserInfo() { IdentityType = Model.User.IdentityType.Person, UserId = person.PerID, RealName = person.RealName, Phone = person.Phne, Email = person.Email }; //求职者登录成功 UserManage.SetCurrentUserInfo(userInfo); } } else if (idt == "s") //经纪人登录 { Model.ServerUser serverUser = _ServerUserServices.QueryWhere(item => (item.Phone == username || item.Email == username || item.RealName == username) && item.Password.Equals(pwd, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); if (serverUser == null) { //用户名或密码错误 return(GetJson(2, new { flag = 1, idt = idt })); } else { userInfo = new Model.User.UserInfo() { IdentityType = Model.User.IdentityType.ServerUser, UserId = serverUser.SerUserID, RealName = serverUser.RealName, Phone = serverUser.Phone, Email = serverUser.Email }; //求职者登录成功 UserManage.SetCurrentUserInfo(userInfo); } } else { //非法操作 return(GetJson(0, new { flag = 3 })); } //登录成功 //设置cookie值,7天内自动登录 if (isChecked) { //字符串连接 '用户名|身份标识' string userCookieStr = UserManage.GetUserCookieStr(userInfo.UserId, userInfo.IdentityType); CookieHelper.Set(Keys.UserInfo, userCookieStr.EncryptStr(), DateTime.Now.AddDays(7)); } else { CookieHelper.Remove(Keys.UserInfo); } return(GetJson(1)); }
/// <summary> /// /// </summary> /// <param name="supplierId">接口供应商ID</param> /// <param name="orderInfo">订单信息</param> /// <param name="supplierOrderId"></param> /// <param name="status"></param> /// <param name="opstate">状态码</param> /// <param name="msg">返回信息</param> /// <param name="tranAmt">结算金额</param> /// <param name="suppSettleAmt">供应商给平台的结算价</param> /// <returns></returns> public static FunExecResult InsertToDb(int supplierId , OrderBankInfo orderInfo , string supplierOrderId , int status , string opstate , string msg , decimal tranAmt , decimal suppSettleAmt) { var result = new FunExecResult() { ErrCode = 0, ErrMsg = "" }; string cacheKey = "OrderBankComplete" + orderInfo.orderid + orderInfo.supplierId.ToString(CultureInfo.InvariantCulture); object flag = Cache.WebCache.GetCacheService().RetrieveObject(cacheKey); if (flag != null) { return(result); } try { orderInfo.supplierId = supplierId; orderInfo.status = status; orderInfo.deduct = 0; #region 扣量 if (BLL.Sys.TransactionSettings.OpenDeduct && status == 2) { Model.User.UserInfo userInfo = BLL.User.Factory.GetCacheUserBaseInfo(orderInfo.userid); if (userInfo != null) { //0x3e8 1000 扣率 扣率 = 被扣单的机率是多少 if (new Random(Guid.NewGuid().GetHashCode()).Next(1, 1000) <= userInfo.CPSDrate) { orderInfo.deduct = 1; } } } #endregion orderInfo.realvalue = tranAmt; orderInfo.supplierId = supplierId; orderInfo.completetime = DateTime.Now; orderInfo.payRate = 0M; orderInfo.payAmt = 0M; orderInfo.promRate = 0M; orderInfo.promAmt = 0M; orderInfo.supplierRate = 0M; orderInfo.supplierAmt = 0M; orderInfo.profits = 0M; if (status == 2) { if (orderInfo.deduct == 0) { #region 计算费率 if (orderInfo.payRate <= 0M) { orderInfo.payRate = BLL.Finance.PayRate.Instance.GetUserPayRate(orderInfo.userid, orderInfo.typeId); } orderInfo.payAmt = orderInfo.payRate * tranAmt; if (orderInfo.agentId > 0) { //代理费率 orderInfo.promRate = BLL.Finance.PayRate.Instance.GetUserPayRate(orderInfo.agentId, orderInfo.typeId); //代理金额 orderInfo.promAmt = (orderInfo.promRate - orderInfo.payRate) * tranAmt; if (orderInfo.promAmt < 0) { orderInfo.promAmt = 0; } } #endregion } if (orderInfo.supplierRate <= 0M) { #region 计算平台费率 var chanelInfo = BLL.Channel.Channel.GetModel(orderInfo.paymodeId, orderInfo.userid, false); if (chanelInfo != null) { orderInfo.supplierRate = chanelInfo.supprate; } #endregion } orderInfo.supplierAmt = suppSettleAmt; if (suppSettleAmt > 0 && tranAmt > 0) { orderInfo.supplierRate = suppSettleAmt / tranAmt; } //利润 orderInfo.profits = orderInfo.supplierAmt - orderInfo.payAmt - orderInfo.promAmt; } orderInfo.opstate = opstate; orderInfo.msg = msg; orderInfo.supplierOrder = ""; if (!string.IsNullOrEmpty(supplierOrderId)) { orderInfo.supplierOrder = supplierOrderId; } BLLBank.Complete(orderInfo); result.ErrCode = 0; result.ErrMsg = "success"; Cache.WebCache.GetCacheService().AddObject(cacheKey, status, 5); } catch (System.Threading.ThreadAbortException ex) { result.ErrCode = 98; result.ErrMsg = ex.Message; // } catch (Exception ex) { result.ErrCode = 99; result.ErrMsg = ex.Message; } return(result); }
/// <summary> /// 设置业务平台客户开户初始化 /// </summary> /// <param name="strCustomerInfo">客户信息字符窜</param> /// <param name="strUnitInfo">门店信息字符窜</param> /// <param name="typeId">处理类型typeId=1(总部与门店一起处理);typeId=2(只处理总部,不处理门店);typeId=3(只处理门店,不处理总部)</param> /// <returns></returns> public bool SetBSInitialInfo(string strCustomerInfo, string strUnitInfo, string strMenu, string typeId) { CustomerInfo customerInfo = new CustomerInfo(); #region 获取客户信息 if (!strCustomerInfo.Equals("")) { customerInfo = (cPos.Model.CustomerInfo)cXMLService.Deserialize(strCustomerInfo, typeof(cPos.Model.CustomerInfo)); if (customerInfo == null || customerInfo.ID.Equals("")) { throw new Exception("客户不存在或者没有获取合法客户信息"); } } else { throw new Exception("客户信息不存在."); } #endregion //获取连接数据库信息 LoggingManager loggingManager = new cLoggingManager().GetLoggingManager(customerInfo.ID); #region 判断客户是否已经建立总部 UnitInfo unitHeadInfo = new UnitService().GetUnitTopByCustomerId(loggingManager, customerInfo.ID); if (unitHeadInfo == null || unitHeadInfo.Id.Equals("")) { typeId = "1"; } else { typeId = "3"; } #endregion UnitInfo unitShopInfo = new UnitInfo();//门店 if (!strUnitInfo.Equals("")) { unitShopInfo = (cPos.Model.UnitInfo)cXMLService.Deserialize(strUnitInfo, typeof(cPos.Model.UnitInfo)); } else { throw new Exception("门店信息不存在."); } #region 门店是否存在 UnitInfo unitStoreInfo2 = new UnitInfo(); try { unitStoreInfo2 = new UnitService().GetUnitById(loggingManager, unitShopInfo.Id); } catch (Exception ex) { throw new Exception("用户插入管理平台失败:" + ex.ToString()); } if (unitStoreInfo2 != null && string.IsNullOrEmpty(unitStoreInfo2.Id)) { throw new Exception("门店信息已经存在."); } #endregion cSqlMapper.Instance(loggingManager).BeginTransaction(); //try //{ bool bReturn = false; #region 处理用户信息 cPos.Model.User.UserInfo userInfo = new Model.User.UserInfo(); if (typeId.Equals("1")) { userInfo.User_Id = NewGuid(); //用户标识 userInfo.customer_id = customerInfo.ID; //客户标识 userInfo.User_Code = "admin"; userInfo.User_Name = "管理员"; userInfo.User_Gender = "1"; userInfo.User_Password = "******"; userInfo.User_Status = "1"; userInfo.User_Status_Desc = "正常"; bReturn = new cUserService().SetUserTableInfo(loggingManager, userInfo); if (!bReturn) { throw new Exception("保存用户失败"); } } else { userInfo = new cUserService().GetUserDefaultByCustomerId(loggingManager, customerInfo.ID); } #endregion #region 处理新建客户总部 cPos.Model.UnitInfo unitInfo = new Model.UnitInfo(); if (typeId.Equals("1") || typeId.Equals("2")) { unitInfo.Id = NewGuid(); unitInfo.TypeId = "2F35F85CF7FF4DF087188A7FB05DED1D"; unitInfo.Code = customerInfo.Code + "总部"; unitInfo.Name = customerInfo.Name + "总部"; unitInfo.CityId = customerInfo.city_id; unitInfo.Status = "1"; unitInfo.Status_Desc = "正常"; unitInfo.CustomerLevel = 1; unitInfo.customer_id = customerInfo.ID; unitInfo.Parent_Unit_Id = "-99"; bReturn = new UnitService().SetUnitTableInfo(loggingManager, unitInfo, userInfo); if (!bReturn) { throw new Exception("新建客户总部失败"); } } else { unitInfo = new UnitService().GetUnitTopByCustomerId(loggingManager, customerInfo.ID); } #endregion #region 处理门店 cPos.Model.UnitInfo storeInfo = new UnitInfo(); storeInfo.Id = unitShopInfo.Id; storeInfo.TypeId = "EB58F1B053694283B2B7610C9AAD2742"; storeInfo.Code = customerInfo.Code; storeInfo.Name = customerInfo.Name; storeInfo.CityId = customerInfo.city_id; storeInfo.Status = "1"; storeInfo.Status_Desc = "正常"; storeInfo.CustomerLevel = 1; storeInfo.customer_id = customerInfo.ID; storeInfo.Parent_Unit_Id = unitInfo.Id; bReturn = new UnitService().SetUnitTableInfo(loggingManager, storeInfo, userInfo); if (!bReturn) { throw new Exception("新建门店失败"); } #endregion #region 新建角色 cPos.Model.RoleModel roleInfo = new RoleModel(); if (typeId.Equals("1")) { roleInfo.Role_Id = NewGuid(); roleInfo.Def_App_Id = "D8C5FF6041AA4EA19D83F924DBF56F93"; roleInfo.Role_Code = "Admin"; roleInfo.Role_Name = "管理员"; roleInfo.Role_Eng_Name = "administrator"; roleInfo.Is_Sys = 1; roleInfo.Status = 1; roleInfo.customer_id = customerInfo.ID; roleInfo.Create_User_Id = userInfo.User_Id; roleInfo.Create_Time = GetCurrentDateTime(); bReturn = new RoleService().SetRoleInfo(loggingManager, roleInfo); if (!bReturn) { throw new Exception("新建角色失败"); } } else { roleInfo = new RoleService().GetRoleDefaultByCustomerId(loggingManager, customerInfo.ID); } #endregion #region 插入用户与角色与客户总部关系 IList <cPos.Model.User.UserRoleInfo> userRoleInfoList = new List <cPos.Model.User.UserRoleInfo>(); if (typeId.Equals("1") || typeId.Equals("2")) { cPos.Model.User.UserRoleInfo userRoleInfo = new Model.User.UserRoleInfo(); userRoleInfo.Id = NewGuid(); userRoleInfo.UserId = userInfo.User_Id; userRoleInfo.RoleId = roleInfo.Role_Id; userRoleInfo.UnitId = unitInfo.Id; userRoleInfo.Status = "1"; userRoleInfo.DefaultFlag = 1; userRoleInfoList.Add(userRoleInfo); } cPos.Model.User.UserRoleInfo userRoleInfo1 = new Model.User.UserRoleInfo(); userRoleInfo1.Id = NewGuid(); userRoleInfo1.UserId = userInfo.User_Id; userRoleInfo1.RoleId = roleInfo.Role_Id; userRoleInfo1.UnitId = storeInfo.Id; userRoleInfo1.Status = "1"; userRoleInfo1.DefaultFlag = 1; userRoleInfoList.Add(userRoleInfo1); bReturn = new cUserService().SetUserRoleTableInfo(loggingManager, userRoleInfoList, userInfo); if (!bReturn) { throw new Exception("新建角色用户门店关系失败"); } #endregion #region 添加仓库以及仓库与门店关系 cPos.Model.Pos.WarehouseInfo warehouseInfo = new cPos.Model.Pos.WarehouseInfo(); warehouseInfo.ID = NewGuid(); warehouseInfo.Code = storeInfo.Code + "_wh"; warehouseInfo.Name = storeInfo.Name + "仓库"; warehouseInfo.IsDefault = 1; warehouseInfo.Status = 1; warehouseInfo.CreateUserID = userInfo.User_Id; warehouseInfo.CreateTime = Convert.ToDateTime(GetCurrentDateTime()); warehouseInfo.CreateUserName = userInfo.User_Name; warehouseInfo.Unit = storeInfo; cPos.Service.PosService posService = new PosService(); bReturn = posService.InsertWarehouse(loggingManager, warehouseInfo, false); if (!bReturn) { throw new Exception("新建仓库失败"); } #endregion #region 设置菜单信息 if (typeId.Equals("1") || typeId.Equals("2")) { if (!strMenu.Equals("")) { bReturn = new cMenuService().SetMenuInfo(strMenu, customerInfo.ID, false); if (!bReturn) { throw new Exception("新建菜单失败"); } } } #endregion #region 角色与流程关系 if (typeId.Equals("1")) { Hashtable _ht = new Hashtable(); _ht.Add("RoleId", roleInfo.Role_Id); bReturn = new cBillService().SetBatBillActionRole(_ht, loggingManager); if (!bReturn) { throw new Exception("创建角色与流程关系失败"); } } #endregion #region 管理平台--插入客户下的用户信息 //if (typeId.Equals("1")) //{ // try // { // bReturn = new cUserService().SetManagerExchangeUserInfo(loggingManager, userInfo, 1); // if (!bReturn) { throw new Exception("用户插入管理平台失败"); } // } // catch (Exception ex) { // cSqlMapper.Instance(loggingManager).RollBackTransaction(); // throw new Exception("用户插入管理平台失败:" + ex.ToString()); // } //} #endregion #region 管理平台--插入客户下的门店信息 //bReturn = new UnitService().SetManagerExchangeUnitInfo(loggingManager, storeInfo, 1); //if (!bReturn) { throw new Exception("门店插入管理平台失败"); } #endregion #region 中间层--插入用户,客户关系 //if (typeId.Equals("1")) //{ // try // { // string strError = string.Empty; // userInfo.customer_id = customerInfo.ID; // bReturn = new cUserService().SetDexUserCertificate(customerInfo.Code, userInfo, out strError); // if (!bReturn) { throw new Exception(strError); } // } // catch (Exception ex) // { // cSqlMapper.Instance(loggingManager).RollBackTransaction(); // throw new Exception("插入中间层失败:" + ex.ToString()); // } //} #endregion cSqlMapper.Instance(loggingManager).CommitTransaction(); return(bReturn); }
/// <summary> /// 统一验证Session[Keys.UserInfo],如果为null,则跳转到登录页面 /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { //0.0 判断是否有贴[SkipCheckLogin]的特性标签 if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLoginAttribute), false)) { return; } if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLoginAttribute), false)) { return; } //▲思路: //1.0 判断Session[Keys.UserInfo]是否为null //1.0.1 查询Cookie[Keys.IsMember]是否不为空,如果成立则模拟用户登录, //再将用户实体数据存入Session[Keys.UserInfo]中 //1.1 取出Cookie中存入的Id的值 //1.2 根据Id查询用户的实体 //1.2.1 先要从缓存中获取Autofac容器对象 //var container = CacheHelper.GetData<IContainer>(Keys.AutofacContainer); //1.2.2 找Autofac容器获取IUserServices接口的具体实现类的对象实例 //IUserServices userServices = container.Resolve<IUserServices>(); //1.3 根据userServices结合Id查询数据 //var userInfo = userServices.QueryWhere(c => c.Id == userId).FirstOrDefault(); //if (userInfo != null) //{ // //1.4 将userInfo存入Session中 // filterContext.HttpContext.Session[Keys.UserInfo] = userInfo; //} //else //{ // ToLoginView(filterContext); //} //1.0 判断Session[Keys.UserInfo]是否为null filterContext.HttpContext.Session[Keys.UserInfo] = null; if (filterContext.HttpContext.Session[Keys.UserInfo] == null) { //1.0.1 查询Cookie[Keys.IsMember]是否不为空,如果成立则模拟用户登录, //再将用户实体数据存入Session[Keys.UserInfo]中 //1.1 取出Cookie中存入的Id的值 var userEnCryptCookieStr = CookieHelper.Get(Keys.UserInfo); var userCookieStr = ""; if (!string.IsNullOrWhiteSpace(userEnCryptCookieStr)) { userCookieStr = userEnCryptCookieStr.DecryptStr(); Match match = Regex.Match(userCookieStr, @"([\S]+)\|(\d+)"); if (match.Success) { //模拟登录 string userIdStr = match.Groups[1].Value; string idtStr = match.Groups[2].Value; int userId = 0; int.TryParse(userIdStr, out userId); int idt = 0; int.TryParse(idtStr, out idt); switch (idt) { //求职者 case 1: { //1.2 根据Id查询用户的实体 //1.2.1 先要从缓存中获取Autofac容器对象 var container = CacheHelper.GetData <IContainer>(Keys.AutofacContainer); //1.2.2 找Autofac容器获取IUserServices接口的具体实现类的对象实例 IPersonServices personServices = container.Resolve <IPersonServices>(); //1.3 根据personServices结合userId查询数据 var person = personServices.QueryWhere(item => item.PerID == userId).FirstOrDefault(); if (person != null) { Model.User.UserInfo userInfo = new Model.User.UserInfo() { IdentityType = Model.User.IdentityType.Person, UserId = person.PerID, RealName = person.RealName, Phone = person.Phne, Email = person.Email }; //求职者登录成功 //1.4 将userInfo存入Session中 UserManage.SetCurrentUserInfo(userInfo); } else { ToLoginView(filterContext); } } break; //经纪人 case 2: { var container = CacheHelper.GetData <IContainer>(Keys.AutofacContainer); IServerUserServices serverUserServices = container.Resolve <IServerUserServices>(); var serverUser = serverUserServices.QueryWhere(item => item.SerUserID == userId).FirstOrDefault(); if (serverUser != null) { Model.User.UserInfo userInfo = new Model.User.UserInfo() { IdentityType = Model.User.IdentityType.ServerUser, UserId = serverUser.SerUserID, RealName = serverUser.RealName, Phone = serverUser.Phone, Email = serverUser.Email }; UserManage.SetCurrentUserInfo(userInfo); } else { ToLoginView(filterContext); } } break; default: { ToLoginView(filterContext); } break; } } else { ToLoginView(filterContext); } } else { ToLoginView(filterContext); } } base.OnActionExecuting(filterContext); }