public async Task <IActionResult> Login([FromBody] UserLoginDto user) { try { var tokens = await _service.LoginAsync(user); var userRoles = await _service.GetUserRoles(user.Email); CookieHelper.CreateCookie(_configuration, HttpContext.Response, user.RememberMe, tokens); return(Ok(userRoles)); } catch (LoginException ex) { return(BadRequest(ex.ToString())); } catch (ObjectNotFoundException ex) { return(BadRequest(ex.ToString())); } catch (IOException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public MvcHtmlString UpdateIngredientQuantity(Guid productId, int quantity) { ICollection <IngredientCreateViewModel> ingredients; var product = ProductManager.FindById(productId); if (!TryUpdateCreatedQuantity(productId, quantity, out ingredients)) { // Tworzymy nowe ciasteczko, jeśli jeszcze nie ma, albo wystąpiły problemy z jedno odczytem. if (product != null) { ingredients = new List <IngredientCreateViewModel> { new IngredientCreateViewModel { ProductId = productId, ProductName = product.Name, Quantity = quantity } }; CookieHelper.CreateCookie <ICollection <IngredientCreateViewModel> >( currentRecipeCookie, createdRecipeIngredients, ingredients, new TimeSpan(0, 30, 0)); } else { ingredients = CookieHelper.ReadCookie <ICollection <IngredientCreateViewModel> >( currentRecipeCookie, createdRecipeIngredients) ?? new List <IngredientCreateViewModel>(); } } return(new MvcHtmlString("[\"" + RecipeHelper.GetNutritionString( quantity * product.Protein / 100, quantity * product.Carbohydrate / 100, quantity * product.Fat / 100) + "\",\"" + RecipeHelper.GetTotalNutritionString(ingredients) + "\"]")); //return PartialView("_CreatedRecipeIngredients", ingredients); }
public ActionResult AddCookie() { CookieHelper.CreateCookie(".NET Version", "4.7"); CookieHelper.CreateCookie("Year", "2020"); CookieHelper.CreateCookie("Github Profile", "theilgazcode"); return(View("Index")); }
/// <summary> /// 保存登录信息 /// </summary> /// <param name="m"></param> protected void SetLogin(UserBase m) { _userinfo = m; string keyMsg = DESEncryptHelper.Encrypt("{0}".FormatWith(JsonConvert.SerializeObject(m)), ConfigHelper.AppSettings("LoginDesKey")); //ErrorBLL.Instance.Log("保存登录信息:{0}".FormatWith(keyMsg)); CookieHelper.CreateCookie("uinfo", keyMsg); }
public PartialViewResult AddIngredient(Guid id) { HttpCookie cookie; var product = ProductManager.FindById(id); IngredientCreateViewModel ingredient = new IngredientCreateViewModel { ProductId = id, Quantity = 0, ProductName = product.Name, BaseProtein = product.Protein, BaseCarbohydrate = product.Carbohydrate, BaseFat = product.Fat }; ICollection <IngredientCreateViewModel> ingredients; if (CookieHelper.CookieExists(currentRecipeCookie, out cookie)) { ingredients = CookieHelper.ReadCookie <ICollection <IngredientCreateViewModel> >(cookie, createdRecipeIngredients); if (ingredients == null) { CookieHelper.DeleteCookie(currentRecipeCookie); ingredients = new List <IngredientCreateViewModel> { ingredient }; CookieHelper.CreateCookie <ICollection <IngredientCreateViewModel> >( currentRecipeCookie, createdRecipeIngredients, ingredients, new TimeSpan(0, 30, 0)); } else { if (!ingredients.Any(i => i.ProductId == id)) { ingredients.Add(ingredient); CookieHelper.UpdateCookie <ICollection <IngredientCreateViewModel> >(cookie, createdRecipeIngredients, ingredients); } } } else { ingredients = new List <IngredientCreateViewModel> { ingredient }; CookieHelper.CreateCookie <ICollection <IngredientCreateViewModel> >( currentRecipeCookie, createdRecipeIngredients, ingredients, new TimeSpan(0, 30, 0)); } return(PartialView("_CreatedRecipeIngredients", ingredients)); }
public IActionResult TestCommon() { ViewData["ContentRootPath"] = FileHelper.ContentRootPath; ViewData["WebRootPath"] = FileHelper.WebRootPath; ViewData["WebRootName"] = FileHelper.WebRootName; string strRequestMsg = string.Empty; strRequestMsg += " HasFormContentType:" + MyHttpContext.Current.Request.HasFormContentType + Environment.NewLine; strRequestMsg += " Host:" + MyHttpContext.Current.Request.Host + Environment.NewLine; strRequestMsg += " IsHttps:" + MyHttpContext.Current.Request.IsHttps + Environment.NewLine; strRequestMsg += " Method:" + MyHttpContext.Current.Request.Method + Environment.NewLine; strRequestMsg += " Path:" + MyHttpContext.Current.Request.Path + Environment.NewLine; strRequestMsg += " PathBase:" + MyHttpContext.Current.Request.PathBase + Environment.NewLine; strRequestMsg += " Protocol:" + MyHttpContext.Current.Request.Protocol + Environment.NewLine; strRequestMsg += " Scheme:" + MyHttpContext.Current.Request.Scheme + Environment.NewLine; ViewData["RequestMsg"] = strRequestMsg; ViewData["RequestReferer"] = MyHttpContext.Current.Request.UrlReferrer(); string strHeaders = string.Empty; foreach (String strFormKey in MyHttpContext.Current.Request.Headers.Keys) { strHeaders += strFormKey + ":" + MyHttpContext.Current.Request.Headers[strFormKey] + "#####"; } ViewData["RequestHeaders"] = strHeaders; ViewData["RequestHeadersJSON"] = ""; //MyHttpContext.Current.Request.Headers.ToJson(); string strForm = string.Empty; if (MyHttpContext.Current.Request.Method == "POST") { foreach (String strFormKey in MyHttpContext.Current.Request.Form.Keys) { strForm += strFormKey + ":" + DataConverter.ToString(MyHttpContext.Current.Request.Form[strFormKey]) + "#####"; } } ViewData["RequestFormJSON"] = strForm; //ViewData["RequestFormJSON"] = MyHttpContext.Current.Request.Form.ToJson(); string strCurrentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"); var resultAdd = CacheHelper.CacheServiceProvider.AddOrUpdate("CurrentTime", strCurrentTime); if (CacheHelper.CacheServiceProvider.Exists("CurrentTime")) { string resultGet = CacheHelper.CacheServiceProvider.Get <string>("CurrentTime"); ViewData["CurrentTime"] = resultGet; } string strMsg = "我是加密文件,请保管好"; string strKey = Guid.NewGuid().ToString().Replace("-", string.Empty); string strEncryptAes = AesRijndael.Encrypt(strMsg, strKey); string strDecryptAes = AesRijndael.Decrypt(strEncryptAes, strKey); ViewData["EncryptAes"] = strEncryptAes; ViewData["DecryptAes"] = strDecryptAes; string strEncryptHmacSha1 = HmacSha1.EncryptUtf8(strMsg, strKey); string strEncryptHmacSha1Base64 = HmacSha1.EncryptBase64(strMsg, strKey); ViewData["EncryptHmacSha1"] = strEncryptHmacSha1; ViewData["EncryptHmacSha1Base64"] = strEncryptHmacSha1Base64; string strEncryptMd5 = Md5.EncryptHexString(strMsg); ViewData["EncryptMd5"] = strEncryptMd5; string strEncryptSha1 = Sha1.Encrypt(strMsg); ViewData["EncryptSha1"] = strEncryptSha1; ViewData["ClientIP"] = IPHelper.GetClientIP(); ViewData["HostIP"] = IPHelper.GetHostIP(); ViewData["RandomFormatedNumeric"] = RandomHelper.GetFormatedNumeric(4, 10); ViewData["RandomString"] = RandomHelper.GetRandString(4); ViewData["RandomStringByPattern"] = RandomHelper.GetRandStringByPattern("JX###???***"); ViewData["StringHelper-GetHashKey"] = StringHelper.GetHashKey(strMsg, StringFilterOptions.HoldChinese); ViewData["StringHelper-GetStringHashKey"] = StringHelper.GetStringHashKey(strMsg); ViewData["StringHelper-MD5"] = StringHelper.MD5(strMsg); ViewData["StringHelper-MD5D"] = StringHelper.MD5D(strMsg); ViewData["StringHelper-MD5GB2312"] = StringHelper.MD5GB2312(strMsg); ViewData["StringHelper-SHA1"] = StringHelper.SHA1(strMsg); ViewData["StringHelper-ValidateMD5"] = StringHelper.ValidateMD5(strEncryptMd5, StringHelper.MD5(strMsg)); ViewData["StringHelper-SubString"] = StringHelper.SubString(strMsg, 12, "..."); ViewData["StringHelper-GetInitial"] = StringHelper.GetInitial(strMsg); ViewData["StringHelper-MakeSpellCode"] = ChineseSpell.MakeSpellCode(strMsg, SpellOptions.EnableUnicodeLetter); ViewData["StringHelper-FirstLetterOnly"] = ChineseSpell.MakeSpellCode(strMsg, SpellOptions.FirstLetterOnly); ViewData["XmlSerializer"] = ConfigHelper.Get <IPLockConfig>().ToXml(); var strXML = "<IPLockConfig> <AdminLockIPBlack>10.123.123.1</AdminLockIPBlack> <AdminLockIPType>30.123.123.3</AdminLockIPType> <AdminLockIPWhite>20.123.123.2</AdminLockIPWhite> <LockIPType>60.123.123.6</LockIPType> <LockIPBlack>40.123.123.4</LockIPBlack> <LockIPWhite>50.123.123.5</LockIPWhite> </IPLockConfig>"; var ipLockConfig = strXML.ToXmlObject <IPLockConfig>(); ViewData["XmlDeserialize"] = "IPLockConfig:" + ipLockConfig.AdminLockIPBlack + " " + ipLockConfig.AdminLockIPType + " " + ipLockConfig.AdminLockIPWhite; ViewData["JsonSerializer"] = ConfigHelper.Get <WebHostConfig>().ToJson(); ConfigHelper.Save(ConfigHelper.Get <ShopConfig>()); ConfigHelper.Save(ConfigHelper.Get <SiteConfig>()); ConfigHelper.Save(ConfigHelper.Get <SiteOptionConfig>()); ConfigHelper.Save(ConfigHelper.Get <SmsConfig>()); ConfigHelper.Save(ConfigHelper.Get <UserConfig>()); ConfigHelper.Save(ConfigHelper.Get <WebHostConfig>()); var strJSON = "{\"AuthenticationType\": 0,\"EnabledSsl\": false,\"MailFrom\": \"[email protected]\",\"MailServer\": \"smtp.qq.com\",\"MailServerPassWord\": \"lx123456\",\"MailServerUserName\": \"2094838895\",\"Port\": \"25\"}"; var mailConfig = strJSON.ToJsonObject <MailConfig>(); ViewData["JsonDeserialize"] = mailConfig.AuthenticationType + " " + mailConfig.EnabledSsl + " " + mailConfig.MailFrom + " " + mailConfig.MailServer; CookieHelper.CreateCookie("cName", "aspnetcore" + strCurrentTime, 10); ViewData["CookieHelper"] = CookieHelper.GetCookie("cName"); //CookieHelper.DeleteCookie("cName"); DateTime beginDate = new DateTime(2015, 12, 5); DateTime endDate = DateTime.Now; ViewData["DateDiff-yyyy"] = Utility.DateDiff(beginDate, endDate, "yyyy"); ViewData["DateDiff-q"] = Utility.DateDiff(beginDate, endDate, "q"); ViewData["DateDiff-m"] = Utility.DateDiff(beginDate, endDate, "m"); ViewData["DateDiff-d"] = Utility.DateDiff(beginDate, endDate, "d"); ViewData["DateDiff-w"] = Utility.DateDiff(beginDate, endDate, "w"); ViewData["DateDiff-h"] = Utility.DateDiff(beginDate, endDate, "h"); ViewData["DateDiff-n"] = Utility.DateDiff(beginDate, endDate, "n"); ViewData["DateDiff-s"] = Utility.DateDiff(beginDate, endDate, "s"); ViewData["Query-name"] = Utility.Query("name"); ViewData["Query-date"] = Utility.Query("date", DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss:fff"); ViewData["Query-age"] = Utility.Query("age", 0); ViewData["Query-mobile"] = Utility.AddQuery("mobile", "15871375589"); var mailConfigSession = ConfigHelper.Get <MailConfig>(); Utility.SetSession("sessionName", mailConfigSession); ViewData["GroupTypeEnum"] = EnumHelper.GetDescription((GroupTypeEnum)(0)); ViewData["GroupTypeEnum1"] = EnumHelper.GetDescription <GroupTypeEnum>(GroupTypeEnum.Agent.ToString()); LogFactory.SaveFileLog("日志标题get", "日志内容"); return(View()); }