public string currlang = APPConfig.GetAPPConfig().GetConfigValue("currlang", ""); //默认语种 public CommonBaseService() { //支持CROSS访问 if (OperationContext.Current != null) { //wcf通道不存在跨域问题 } if (WebOperationContext.Current != null) { #region 跨域访问 if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS") { if (WebOperationContext.Current.OutgoingResponse.Headers["Access-Control-Allow-Methods"] == null) { WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Origin, Cache-Control, X-Requested-With, Content-Type, Accept, token"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Max-Age", "1728000"); } } else { if (WebOperationContext.Current.OutgoingResponse.Headers["Access-Control-Allow-Methods"] == null) { WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type"); } } #endregion } if (HttpContext.Current != null) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (HttpContext.Current.Request.HttpMethod == "OPTIONS") { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Origin, Cache-Control, X-Requested-With, Content-Type, Accept, token"); HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000"); HttpContext.Current.Response.End(); } } envirObj = new SysEnvironmentSerialize(); try { //获取框架环境 string token = this.GetToken(); if (!string.IsNullOrEmpty(token)) { //bool temps = JsonSerializer.Deserialize<SysEnvironmentSerialize>(Encoding.Default.GetString(Convert.FromBase64String(token)), out envirObj); //TODO 后续考虑js的base64处理 envirObj = json.Deserialize <SysEnvironmentSerialize>(token); } else { envirObj.I18nCurrLang = currlang; } //赋值框架实例到静态框架环境 ManagerSysEnvironment.GetSysEnvironmentSerialize2SysEnvironment(envirObj); //这里装载框架级语言包,具体模块在模块内装载 DataTable comlangtmp = (DataTable)currCache.Get("i18nCommonCurrLang"); if (comlangtmp != null) { if (currlang == envirObj.I18nCurrLang) { i18nCommonCurrLang = comlangtmp; } else { string commoni18nLangPath = string.Format(APPConfig.GetAPPConfig().GetConfigValue("Commoni18nLang", ""), envirObj.I18nCurrLang); i18nCommonCurrLang = this.GetI18nLang(commoni18nLangPath); } } else { string commoni18nLangPath = string.Format(APPConfig.GetAPPConfig().GetConfigValue("Commoni18nLang", ""), envirObj.I18nCurrLang); i18nCommonCurrLang = this.GetI18nLang(commoni18nLangPath); } //装载服务配置 //serviceConfig = this.GetServiceConfig(APPConfig.GetAPPConfig().GetConfigValue("ServiceConfigPath", "")); DataTable dttmp = (DataTable)currCache.Get("serviceConfig"); if (dttmp != null) { serviceConfig = dttmp; } else { serviceConfig = this.GetServiceConfig(APPConfig.GetAPPConfig().GetConfigValue("ServiceConfigPath", "")); } //装载数据配置 //distManagerParam = this.GetDistributeDataNodeManagerParams(); DistributeDataNodeManagerParams ddnmtmp = (DistributeDataNodeManagerParams)currCache.Get("dataNodes"); if (ddnmtmp != null) { distManagerParam = ddnmtmp; } //这里不需要再装载了,缓存已经装载了 //else //{ // distManagerParam = this.GetDistributeDataNodeManagerParams(); //} //设置语言运行环境 Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(envirObj.I18nCurrLang); Thread.CurrentThread.CurrentUICulture = new CultureInfo(envirObj.I18nCurrLang); //due to an error of freetextbox, all the cultures must use a dot as NumberDecimalSeparator Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = "."; this.successStr = this.GetI18nLangItem("successStr", this.i18nCommonCurrLang); this.errorStr = this.GetI18nLangItem("errorStr", this.i18nCommonCurrLang); } catch (Exception ex) { throw new Exception("Unknown exception! Reason:" + ex.Message); } }
/// <summary> /// 获取用户信息 /// </summary> /// <param name="model"></param> /// <returns></returns>d public string GetUserForLoginN(string req) { try { //解析参数实体 reqdata = this.AnaRequestData(req); SSY_USER_DICT model = this.json.Deserialize <SSY_USER_DICT>(reqdata.reqdata); StringBuilder toolStr = new StringBuilder(); //准备日志参数实例 List <SSY_LOGENTITY> ListBizLog = new List <SSY_LOGENTITY>(); if (model.USERID.ToString().ToUpper() == "super".ToUpper()) { base.envirObj.distManagerParam.DistributeActionIden = DistributeActionIden.Query; } else { base.envirObj.distManagerParam.DistributeActionIden = DistributeActionIden.TransAction; } //this.permitMaxLoginFailtCnt = APPConfig.GetAPPConfig().GetConfigValue("permitMaxLoginFailtCnt", "5"); //允许最大错误登录次数, 默认5次 //解密口令, 客户端已经加密,这里无需解密,直接比较密码串 //string iv128str = APPConfig.GetAPPConfig().GetConfigValue("ivpwd", "5CRc851hRywf7W3m"); //string key256str = APPConfig.GetAPPConfig().GetConfigValue("keypwd", "nW8FnftasWp7AVZrmgr9sdaGNXsjMWiw"); //byte[] key256 = Security.CreateKeyByte(key256str); //byte[] iv128 = Security.CreateKeyByte(iv128str); //model.PASSWORD = Security.DeAES(model.PASSWORD.ToString(), key256, iv128); List <SSY_USER_DICT> uds = this._comBiz.GetUserForLogin(model, base.envirObj.distManagerParam, ListBizLog); if (uds.Count > 0) { if (model.PASSWORD.ToString() == uds[0].PASSWORD.ToString()) { if (uds[0].ISUSE.ToString() == "0") { //判断是否禁用 resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_Enabled", this.i18nModuleCurrLang), string.Empty, string.Empty); } else if (uds[0].LOCKED.ToString() == "1") { //判断是否锁定 resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_Locked", this.i18nModuleCurrLang), string.Empty, string.Empty); } else { #region 允许登录后,正常验证处理 //判断是否登录 bool alreadyLonin = false; if (Utility.ObjHasData(uds[0].ISLONIN) && Utility.ObjHasData(uds[0].FROMPLAT)) { if (uds[0].ISLONIN == "Y" && uds[0].FROMPLAT.ToUpper() == base.envirObj.distManagerParam.DistributeDataNodes[0].Systemname.ToUpper()) { alreadyLonin = true; } } if (alreadyLonin) { //检查密码安全补存提示信息 //resdata = BaseWebPage.MakeResponseData("0", string.Format(BaseUI.GetNoticeCfg("com0008", "CommonNoticeCfg"), uds[0].FROMPLAT.ToUpper()), string.Empty); resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginok_exist", this.i18nModuleCurrLang), string.Empty, string.Empty); } else { //检查是否启用密码安全策略 检查首次登陆 检查超过时间间隔 if (base.envirObj.distManagerParam.DistributeDataNodes[0].Isusepwdsecuritycheck == "Y") { if (base.envirObj.distManagerParam.DistributeDataNodes[0].Pwdfirstcheck == "Y" && uds[0].ISFIRSTLOGIN == "Y") { //首次登陆提示 toolStr.AppendLine(this.GetI18nLangItem("loginok_firstlogin", this.i18nModuleCurrLang)); } //这里取服务器时间即可 //Frame.ServiceLibs.FrameManagerService tmpop = new FrameManagerService(); //string currTime = string.Empty; //currTime = tmpop.GetSystemDateTimesN(string.Empty); string currTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if ((!string.IsNullOrEmpty(currTime)) && (!string.IsNullOrEmpty(uds[0].LASTLOGINTIME.ToString()))) { TimeSpan ts = Convert.ToDateTime(currTime) - Convert.ToDateTime(uds[0].LASTLOGINTIME.ToString()); if (ts.TotalHours >= int.Parse(base.envirObj.distManagerParam.DistributeDataNodes[0].Pwdintervalhours)) { //超过时间提示 toolStr.AppendLine(string.Format(this.GetI18nLangItem("loginok_oversecuritytime", this.i18nModuleCurrLang), base.envirObj.distManagerParam.DistributeDataNodes[0].Pwdintervalhours)); } } } #region 获取令牌 //节点中心安全服务 //string FrameNodeSecurity = APPConfig.GetAPPConfig().GetConfigValue("NodeCenterMaster", "") + // APPConfig.GetAPPConfig().GetConfigValue(SSY_ServiceHost.FrameNodeSecurityService, "").TrimStart('/'); //调用普通节点中心服务获取令牌 DataRow drServ = this.GetServiceConfigOne("framenodesecu", "1.0", "normal", "frameNode", this.serviceConfig); //string FrameNodeSecurity = base.envirObj.BizNodeAddr + "/" + drServ["servcodename"].ToString().TrimStart('/'); string FrameNodeSecurity = drServ["url_addr"].ToString().TrimStart('/') + "/" + drServ["servcodename"].ToString().TrimStart('/'); SSY_DYNAMICTOKEN tokenModel = new SSY_DYNAMICTOKEN(); tokenModel.Dynamictoken = ""; tokenModel.ID = ""; tokenModel.Remarks = model.USERID.ToString(); //暂存用户账户,用于节点中心获取令牌时重新验证 tokenModel.Timestampss = model.PASSWORD.ToString(); //暂存用户口令,用于节点中心获取令牌时重新验证 this.reqdata = new ReqData(); this.reqdata.reqdata = json.Serialize(tokenModel); //动态调用服务获取令牌 string tokenstr = DynamicInvokeWCF.Create <IFrameNodeSecurity>(FrameNodeSecurity).GetToken(this.json.Serialize(this.reqdata)); //返回执行结果 if (string.IsNullOrEmpty(tokenstr)) { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginok_notoken", this.i18nModuleCurrLang), string.Empty, string.Empty); } else { //解析令牌 RespData tmpToken = json.Deserialize <RespData>(tokenstr); if (tmpToken.respflag == "1") { //赋值当前登录用户数据 base.envirObj.SysUserDict = uds[0]; RespData tmpresdata = json.Deserialize <RespData>(tokenstr); //直接返回环境参数,去除口令和数据节点 base.envirObj.TokenEncrpValue = tmpresdata.respdata; SysEnvironmentSerialize resTmp = new SysEnvironmentSerialize(); resTmp = json.Deserialize <SysEnvironmentSerialize>(json.Serialize(base.envirObj)); resTmp.SysUserDict.PASSWORD = ""; //不返回密码 resTmp.distManagerParam = null; //不返回数据节点 //赋值用户数据到框架环境变量 ManagerSysEnvironment.GetSysEnvironmentSerialize2SysEnvironment(base.envirObj); if (string.IsNullOrEmpty(toolStr.ToString())) { resdata = this.MakeResponseData("1", this.GetI18nLangItem("loginok", this.i18nModuleCurrLang), json.Serialize(resTmp), string.Empty); } else { resdata = this.MakeResponseData("2", this.GetI18nLangItem("loginok", this.i18nModuleCurrLang), json.Serialize(resTmp), string.Empty); } } else { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginok_gettokenerr", this.i18nModuleCurrLang), string.Empty, string.Empty); } } #endregion } #endregion } } else { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_userNotPassword", this.i18nModuleCurrLang), string.Empty, string.Empty); } } else { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_nocurruser", this.i18nModuleCurrLang), string.Empty, string.Empty); } } catch (Exception ex) { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_findexception", this.i18nModuleCurrLang) + ex.Message, string.Empty, string.Empty); } return(json.Serialize(resdata)); }