public BusinessViewModelContainer <bool> Logout() { BusinessViewModelContainer <bool> viewModel = new BusinessViewModelContainer <bool>(); try { //系统管理员退出的清理 bool isCookieOfAdmin = Request.Cookies.ContainsKey(Contanst.Login_Cookie_SystemAdminUserInfo); if (isCookieOfAdmin) { //清除cookie HttpContext.RemoveCookie(Contanst.Login_Cookie_SystemAdminUserInfo, Contanst.Global_Site_Domain_Cookie); HttpContext.RemoveCookie(Contanst.Login_Cookie_Client_Key, Contanst.Global_Site_Domain_Cookie); //写入用户基本信息Cookie HttpContext.RemoveCookie(Contanst.Login_Cookie_UserInfo, Contanst.Global_Site_Domain_Cookie); } //普通商户退出登录 //清除cookie HttpContext.RemoveCookie(Contanst.Login_Cookie_Client_Key, Contanst.Global_Site_Domain_Cookie); //写入用户基本信息Cookie HttpContext.RemoveCookie(Contanst.Login_Cookie_UserInfo, Contanst.Global_Site_Domain_Cookie); } catch (Exception ex) { Logger.Error(ex); } return(viewModel); }
public BusinessViewModelContainer <LoginSystemAdminResultViewModel> LoginCheckUser(PasswordLoginViewModel model) { BusinessViewModelContainer <LoginSystemAdminResultViewModel> viewModel = new BusinessViewModelContainer <LoginSystemAdminResultViewModel>(); try { //先去检查用户名密码 string uName = model.UserName; string pwd = DESEncrypt.Encrypt(model.Pwd); if (string.IsNullOrEmpty(uName) || string.IsNullOrEmpty(pwd)) { viewModel.Data = new LoginSystemAdminResultViewModel { Message = "用户名密码不能为空!" }; return(viewModel); } var sysUser = Singleton <SysAdminService> .Instance .GetSysAdminFirstOrDefaultByCondition(x => x.Uname == uName && x.Upassword == pwd && x.State == true); if (null != sysUser) { string next_step = "2";//验证通过后,加密的签名进行第二步操作--动态口令验证 var lstSignParas = new string[] { DateTime.Now.ToTimeStampMilliseconds().ToString(), next_step, uName, pwd }; string sign = DESEncrypt.Encrypt(string.Join('|', lstSignParas)); viewModel.Data = new LoginSystemAdminResultViewModel { Message = "登录成功!请进行二阶验证!", IsSuccess = true, Step = 1, //标识第一步验证通过 Sign = sign //自定义签名 }; } else { viewModel.Data = new LoginSystemAdminResultViewModel { Message = "用户名密码输入错误!" }; } } catch (Exception ex) { viewModel.SetFalied("调用失败了!"); Logger.Error(ex); } return(viewModel); }
public override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (false == IsCheck) { return(base.OnActionExecutionAsync(context, next)); } //优先检测是否为超管用户 bool isSysAdmin = this.AuthenticationService.CheckUserIsSystemAdminFromHttpContext(); //当前登录过的用户id ILoginAuthedUserDTO currentUser = null; currentUser = this.AuthenticationService.GetAuthenticatedUserFromHttpContext(); //验证通过 那么直接执行 action 否则返回错误 if (null != currentUser || isSysAdmin) { //设定当前登录用户到安全上下文中 ApplicationContext.Current.User = currentUser; return(base.OnActionExecutionAsync(context, next));//有权限的话 直接继续执行要访问的action } //非超管并且不是普通商户 if (!isSysAdmin && null == currentUser) { //记录错误日志 string toAccessUrl = context.HttpContext.Request.Path.Value; string msg = string.Concat("非法访问;IP地址:", context.HttpContext.Request.GetIP(), "。访问地址:", toAccessUrl); Logger.Error(msg); //输出错误信息 var result = new BusinessViewModelContainer <string> { Status = (int)CodeStatusTable.NotHaveAuth, Msg = CodeStatusTable.NotHaveAuth.GetEnumDescription() }; //////context.HttpContext.Response = context.HttpContext.Request.CreateResponse(HttpStatusCode.OK, result); //////context.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; //////context.HttpContext.Response.ContentType = "application/json;charset=utf-8"; ////// return context.HttpContext.Response.WriteAsync(result); context.Result = new JsonResult(result); } return(Task.FromResult <object>(null)); }
public IActionResult Index() { //var r = this.HttpContext.Request; //var id = Request.GetQuery<string>("id"); //var ip = Request.GetIP(); var dataContainer = new BusinessViewModelContainer <HomePageViewModel>(); var viewModel = new HomePageViewModel(); //热搜词汇- 从检索的5分钟的词列表中获取 viewModel.HotWords = HotWordService.GetHotWords(); dataContainer.Data = viewModel; return(View(dataContainer)); }
/// <summary> /// 分页查询搜索学生信息 /// </summary> /// <param name="dataContainer"></param> /// <param name="condition"></param> /// <returns></returns> public BusinessViewModelContainer <List <StudentDto> > SearchUserStudentsHandler(StudentQueryCondition condition) { BusinessViewModelContainer <List <StudentDto> > dataContainer = new BusinessViewModelContainer <List <StudentDto> >(); try { if (null == condition) { throw new Exception("查询条件不能为空!"); } if (condition.PageNumber <= 0) { condition.PageNumber = 1; } if (condition.PageSize > 100) { condition.PageSize = 100; } //查询分页 var dataListPager = this.dal_UserStudents.GetStudentssByPagerAndCondition(condition.KeyWord, condition.PageNumber, condition.PageSize); if (dataListPager != null && dataListPager.TotalRows > 0) { //数据转换DTO dataContainer.Data = dataListPager.DataList; //初始化客户端分页信息 if (dataContainer.PagerInfomation == null) { dataContainer.PagerInfomation = new PageInfo(); } dataContainer.PagerInfomation.PageNumber = condition.PageNumber; dataContainer.PagerInfomation.Size = condition.PageSize; dataContainer.PagerInfomation.TotalElements = dataListPager.TotalRows; } } catch (Exception ex) { throw ex; } return(dataContainer); }
public BusinessViewModelContainer <List <EnumKeyValueViewModel> > LoadSupportPlatformsListHandler() { BusinessViewModelContainer <List <EnumKeyValueViewModel> > res = new BusinessViewModelContainer <List <EnumKeyValueViewModel> >(); try { var lstPlatforms = EnumExtension.ConvertEnumToList <PlatformEnum>(); res.Data = lstPlatforms.Where(x => x.EnumValue > 0).Select(item => { return(new EnumKeyValueViewModel { Label = item.Description, Value = item.EnumValue }); }).ToList(); } catch (Exception ex) { res.SetFalied(ex.Message); } return(res); }
public BusinessViewModelContainer <SearchProductViewModel> SearchTmallProducts([FromBody] TmallFetchWebPageArgument webArgs) { BusinessViewModelContainer <SearchProductViewModel> container = new BusinessViewModelContainer <SearchProductViewModel>(); if (null == webArgs || !webArgs.IsValid()) { container.SetFalied("查询参数不是有效的查询参数!"); return(container); } try { //使用指定平台的页面检索服务 进行搜索商品 var pageService = WebPageService.CreateNew(); container.Data = pageService.QueryProductsByKeyWords(webArgs); } catch (Exception ex) { Logger.Error(ex); } return(container); }
public BusinessViewModelContainer <bool> AddMulitiUserStudentsModelsTest() { var viewModel = new BusinessViewModelContainer <bool>(); var lstData = new List <UserStudentsModel>(); var rand = new Random(DateTime.Now.Millisecond); for (int i = 0; i < 100; i++) { var model = new UserStudentsModel { Name = "你猜猜-" + Guid.NewGuid().ToString(), Age = rand.Next(1, 100), Sex = false, Score = 33355.98m, Longitude = 59595959, AddTime = DateTime.Now, HasPay = 888, HomeNumber = 666 }; lstData.Add(model); } using (var tran = new TransactionScope()) { var lstStudents = Singleton <UserStudentsService> .Instance.GetUserStudentsElementById(1); var result = Singleton <UserStudentsService> .Instance.AddMulitiUserStudentsModels(lstData); viewModel.Data = result; tran.Complete(); } return(viewModel); }
public BusinessViewModelContainer <object> SearchGuomeiPrice([FromBody] GuomeiFetchWebPageArgument webArgs) { BusinessViewModelContainer <object> container = new BusinessViewModelContainer <object>(); if (null == webArgs || !webArgs.AttachParas.ContainsKey("pid") || !webArgs.AttachParas.ContainsKey("skuid") ) { container.SetFalied("查询参数不是有效的查询参数!缺少AttachParas 中的pid /skuid."); return(container); } try { //使用国美的插件实例 ,进行价格请求 IPlugin guomeiPlugin = null; var guomeiPlugin_QuerySingleProductPrice = new GuomeiSearchProductResolver() .GetPluginMethodInfo("QuerySingleProductPrice", out guomeiPlugin); if (null != guomeiPlugin_QuerySingleProductPrice) { //设定连接 var connStrConfig = ConfigHelper.WebCrawlerSection.ConnectionStringCollection.First(); webArgs.SystemAttachParas["SoapTcpConnectionString"] = connStrConfig;//register to attach paras container.Data = guomeiPlugin_QuerySingleProductPrice.Invoke(guomeiPlugin, new object[] { webArgs }); } } catch (Exception ex) { Logger.Error(ex); } return(container); }
public BusinessViewModelContainer <List <UserStudentsModel> > GetStudents() { var viewModel = new BusinessViewModelContainer <List <UserStudentsModel> >(); try { //下面是一个查询数据库的示范---在实际场景中请一定要把数据放到Data 属性中。 var demoData = Singleton <UserStudentsService> .Instance .GetUserStudentsElementsByCondition(x => x.Id >= 10); if (demoData.IsNotEmpty()) { viewModel.Data = demoData; } } catch (Exception ex) { viewModel.SetFalied("调用失败了!"); Logger.Error(ex); } return(viewModel); }
public async Task <IActionResult> AuthCallBack(string accessCode, string appkey, string ext) { #region 参考文档 /* * 参考文档: ///https://open.taobao.com/doc.htm?docId=107149&docType=1 * /// http://lcp.cloud.cainiao.com/permission/isv/grantpage.do?isvAppKey=<YourAppKey>&ext=<YourExtentionInfo>&redirectUrl=http://www.<YourRedirectUrl>.com/auth/callback.do * /// http://lcp.cloud.cainiao.com/permission/isv/grantpage.do?isvAppKey=472333&ext=66666666666&redirectUrl=http://api.flybirdyoyo.com/cainiao/call_back_handler * /// </summary> */ #endregion BusinessViewModelContainer <string> msgResult = new BusinessViewModelContainer <string>(); if (string.IsNullOrEmpty(accessCode) || string.IsNullOrEmpty(appkey) || string.IsNullOrEmpty(ext)) { msgResult.SetFalied("参数丢失!"); return(new JsonResult(msgResult)); } var configSection = ConfigHelper.GetConfigSection <AppSecretConfigSection>(AppSecretConfigSection.SectionName); //回调的跟发起授权的key不一样,返回错误 if (appkey != configSection.CaiNiao.AppKey) { msgResult.SetFalied("非法请求!"); return(new JsonResult(msgResult)); } if (null == ApplicationContext.Current.User) { msgResult.SetFalied("当前用户未登录,请登录!!"); return(new JsonResult(msgResult)); } //1 验证state的数据 //时间戳+签名 var array_State = ext.Split(this.SplitChar); long timeStamp = array_State[0].ToLong(); string signInner = array_State[1];// if (timeStamp <= 0 || signInner.IsNullOrEmpty()) { msgResult.SetFalied("拼多多回调缺少参数!!"); return(new JsonResult(msgResult)); } var serverSign = StringExtension.DEFAULT_ENCRYPT_KEY.GetCrossSiteSign(timeStamp); if (!string.Equals(signInner, serverSign)) { msgResult.SetFalied("拼多多回调签名验证失败!"); return(new JsonResult(msgResult)); } //--------验证通过-------- // 发起请求去交换当前用户的Token try { string baseExtenPath = configSection.CaiNiao.ShopExtenTokenAddress; var keyPair = new NameValueCollection(); keyPair.Add("accessCode", accessCode); keyPair.Add("isvAppKey", configSection.CaiNiao.AppKey); //菜鸟的签名 //sign:签名,证明ISV合法,签名规则:md5(accessCode + "," + appKey + "," + appSecret); Note: 别忘了逗号是英文状态下的逗号,签名方法: var lstSignParas = new List <string> { accessCode, configSection.CaiNiao.AppKey, configSection.CaiNiao.AppSecret }; string signCaiNiaoData = string.Join(',', lstSignParas).GetMD5().ToLower(); keyPair.Add("sign", signCaiNiaoData); //---字典转为字符串--- string paramString = keyPair.ToQueryString(); string extentTokenAddress = string.Concat(baseExtenPath, paramString); var resp = await Singleton <HttpServerProxy> .Instance.GetAsync(extentTokenAddress); if (null != resp && resp.IsSuccessStatusCode) { string jsonContent = await resp.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(jsonContent)) { msgResult.IsSuccess = false; msgResult.Msg = "菜鸟授权未成功,请重试!"; return(new JsonResult(msgResult)); } } } catch (Exception ex) { Logger.Error(ex); } return(new JsonResult(msgResult)); }
public async Task <IActionResult> AuthCallBack(string accessCode, string appkey, string ext) { BusinessViewModelContainer <string> msgResult = new BusinessViewModelContainer <string>(); if (string.IsNullOrEmpty(accessCode) || string.IsNullOrEmpty(appkey) || string.IsNullOrEmpty(ext)) { msgResult.SetFalied("参数丢失!"); return(new JsonResult(msgResult)); } var configSection = ConfigHelper.GetConfigSection <AppSecretConfigSection>(AppSecretConfigSection.SectionName); //回调的跟发起授权的key不一样,返回错误 if (appkey != configSection.CaiNiao.AppKey) { msgResult.SetFalied("非法请求!"); return(new JsonResult(msgResult)); } if (null == ApplicationContext.Current.User) { msgResult.SetFalied("当前用户未登录,请登录!!"); return(new JsonResult(msgResult)); } //1 验证state的数据 //时间戳+签名 var array_State = ext.Split(this.SplitChar); long timeStamp = array_State[0].ToLong(); string signInner = array_State[1];// if (timeStamp <= 0 || signInner.IsNullOrEmpty()) { msgResult.SetFalied("拼多多回调缺少参数!!"); return(new JsonResult(msgResult)); } var serverSign = StringExtension.DEFAULT_ENCRYPT_KEY.GetCrossSiteSign(timeStamp); if (!string.Equals(signInner, serverSign)) { msgResult.SetFalied("拼多多回调签名验证失败!"); return(new JsonResult(msgResult)); } //--------验证通过-------- // 发起请求去交换当前用户的Token try { string baseExtenPath = configSection.CaiNiao.ShopExtenTokenAddress; var keyPair = new NameValueCollection(); keyPair.Add("accessCode", accessCode); keyPair.Add("isvAppKey", configSection.CaiNiao.AppKey); //菜鸟的签名 //sign:签名,证明ISV合法,签名规则:md5(accessCode + "," + appKey + "," + appSecret); Note: 别忘了逗号是英文状态下的逗号,签名方法: var lstSignParas = new List <string> { accessCode, configSection.CaiNiao.AppKey, configSection.CaiNiao.AppSecret }; string signCaiNiaoData = string.Join(',', lstSignParas).GetMD5().ToLower(); keyPair.Add("sign", signCaiNiaoData); //---字典转为字符串--- string paramString = keyPair.ToQueryString(); string extentTokenAddress = string.Concat(baseExtenPath, paramString); var resp = await Singleton <HttpServerProxy> .Instance.GetAsync(extentTokenAddress); if (null != resp && resp.IsSuccessStatusCode) { string jsonContent = await resp.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(jsonContent)) { msgResult.IsSuccess = false; msgResult.Msg = "菜鸟授权未成功,请重试!"; return(new JsonResult(msgResult)); } } } catch (Exception ex) { Logger.Error(ex); } return(new JsonResult(msgResult)); }
public BusinessViewModelContainer <bool> LoginCheckDyCode(PasswordLoginViewModel model) { BusinessViewModelContainer <bool> viewModel = new BusinessViewModelContainer <bool>(); try { if (model.CheckCode.IsNullOrEmpty()) { return(viewModel); } if (model.Sign.IsNullOrEmpty()) { viewModel.SetFalied("签名不能为空!"); return(viewModel); } string deSign = string.Empty; try { deSign = DESEncrypt.Decrypt(model.Sign); } catch { } if (deSign.IsNullOrEmpty()) { viewModel.SetFalied("签名错误!"); return(viewModel); } string[] arrSign = deSign.Split('|'); long timeSnamp = arrSign[0].ToLong(); int step = arrSign[1].ToInt(); //时间戳之间的间隔不能过长-不可超过5分钟 if ((DateTime.Now.ToTimeStampMilliseconds() - timeSnamp) / 1000 > 5 * 60) { viewModel.SetFalied("登录超时!请重新输入用户名密码!"); return(viewModel); } if (step != 2 || arrSign.Length < 4) { viewModel.SetFalied("登录必须输入密码!请重新输入用户名密码!"); return(viewModel); } string uName = arrSign[2]; string pwd = arrSign[3]; if (string.IsNullOrEmpty(uName) || string.IsNullOrEmpty(pwd)) { viewModel.SetFalied("登录必须输入密码!请重新输入用户名密码!"); return(viewModel); } var sysUser = Singleton <SysAdminService> .Instance .GetSysAdminFirstOrDefaultByCondition(x => x.Uname == uName && x.Upassword == pwd && x.State == true); if (null == sysUser) { viewModel.SetFalied("未知用户!"); return(viewModel); } if (string.IsNullOrEmpty(sysUser.PublicKey)) { viewModel.SetFalied("用户密钥已经失效!请联系管理员!"); return(viewModel); } //进行谷歌身份验证,如果验证通过,那么写入系统用户Cookie //写入凭证 //todo:进行谷歌二阶验证 var tfaProvider = new TwoFactorAuth(); bool validateResult = false; try { validateResult = tfaProvider.VerifyCode(sysUser.PublicKey, model.CheckCode); } catch { } if (true == validateResult) { //验证通过 //1 记录登录日志: var logModel = new SysLogModel { Level = 1, SysUserId = sysUser.Id, //LogType = (int)SysLogTypeEnum.Login, LogContent = $"超管账号:{sysUser.Uname} , 登录系统!", CreateTime = DateTime.Now, IpAddress = base.IpAddress }; Singleton <SysLogService> .Instance.AddOneSysLogModel(logModel); //2 客户端授权并进入后台页面 viewModel.Msg = "成功登录!"; viewModel.Data = true; var sysUserLoginModel = new LoginSystemAdminResultViewModel { AdminUserId = sysUser.Id, IsSuccess = true, Step = 3, Sign = model.Sign//自定义签名 }; string authJson = sysUserLoginModel.ToJson(); //写入用户基本信息Cookie HttpContext.SetCookie(Contanst.Global_Site_Domain_Cookie, Contanst.Login_Cookie_SystemAdminUserInfo, authJson); } else { viewModel.SetFalied("口令已经过期,请重新输入!"); } } catch (Exception ex) { viewModel.SetFalied("验证失败!"); Logger.Error(ex); } return(viewModel); }