public async Task <JsonResult> LoginGetToken([FromBody] JWTUserModel _user) { var _return = await new DB_User().DBLoginAsync(_user); var ipaddress = HttpContext.Connection.RemoteIpAddress.ToIPv4String(); var userAgent = HttpContext.Request.Headers["User-Agent"]; var agent = new UserAgent(userAgent); var Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}"; var OS = $"{agent.OS?.Name} {agent.OS?.Version}"; await new DB_Log().SetOperatingLogAsync(new Operatinginfo { UserID = _user.id, Operating = "登录", Date = DateTime.Now.ToString(), UserName = _user.Name, ip = ipaddress, Browser = Browser, OS = OS, state = _return != null ? 200 : 500, Details = _return != null ? "通过登录授权" : "未通过登录授权" }); var _token = ""; if (_return != null && !string.IsNullOrEmpty(_return.id.ToString())) { _token = _tokenServic.GetToken(_user).AESEncrypt(); HttpContext.AddCookie(CoreConfiguration.JwtCookiesTokenKey, _token); return(new JsonResult(new { Success = true, Message = "登录成功", access_token = _token })); } return(new JsonResult(new { Success = false, Message = "用户名或密码不正确!" })); }
public virtual async Task <ActionResult> AddToCart(long?productId, decimal?value) { if (productId == null) { return(Content(null)); } var product = _productService.GetById(productId.Value); if (product == null) { return(Content(null)); } var count = value ?? product.Ratio; var result = decimal.Remainder(count, product.Ratio); if (result != decimal.Zero) { return(Content(null)); } if (!_productService.CanAddToShoppingCart(productId.Value, count)) { return(Content("nok")); } var cartItem = _shoppingCartService.GetCartItem(productId.Value, User.Identity.Name); product.Reserve += count; if (cartItem == null) { _shoppingCartService.Add(new ShoppingCart { CartNumber = User.Identity.Name, Quantity = count, ProductId = productId.Value, CreateDate = DateTime.Now }); } else { cartItem.Quantity += count; } await _unitOfWork.SaveAllChangesAsync(false); var totalValueInCart = _shoppingCartService.TotalValueInCart(User.Identity.Name); if (string.IsNullOrEmpty(HttpContext.GetCookieValue(TotalInCartCookieName))) { HttpContext.AddCookie(TotalInCartCookieName, totalValueInCart.ToString(CultureInfo.InvariantCulture), DateTime.Now.AddDays(1)); } else { HttpContext.UpdateCookie(TotalInCartCookieName, totalValueInCart.ToString(CultureInfo.InvariantCulture)); } return(Content("ok")); }
/// <summary> /// 混合验证码 /// </summary> /// <returns></returns> public FileContentResult MixVerifyCode() { string code = VerifyCodeHelper.GetSingleObj().CreateVerifyCode(VerifyCodeHelper.VerifyCodeType.MixVerifyCode); HttpContext.AddCookie("captcha", code, 5); var bitmap = VerifyCodeHelper.GetSingleObj().CreateBitmapByImgVerifyCode(code, 120, 38); MemoryStream stream = new MemoryStream(); bitmap.Save(stream, ImageFormat.Gif); return(File(stream.ToArray(), "image/gif")); }
public Basemessage Get([FromQuery] string themeName) { if (!string.IsNullOrWhiteSpace(themeName)) { HttpContext.AddCookie("WebTheme", themeName); return(succeed()); } else { return(Error()); } }
public virtual ActionResult AddToCompareList(long?productId) { if (productId == null) { return(Content(null)); } var itemsInCookie = new List <ProductCompareViewModel>(); var cookieValue = HttpContext.GetCookieValue(TotalInCompareCookieName); var count = string.IsNullOrEmpty(cookieValue) ? 0 : int.Parse(cookieValue); if (count > 5) { return(Content("limit")); } var product = _productService.GetForAddToCompare(productId.Value); if (count == 0) { HttpContext.AddCookie(TotalInCompareCookieName, (++count).ToString(), DateTime.Now.AddDays(1)); } else { itemsInCookie = new JavaScriptSerializer().Deserialize <List <ProductCompareViewModel> >( HttpContext.GetCookieValue(CompareListCookieName)); if (itemsInCookie.Any(a => a.ProductId == productId.Value)) { return(Content("nok")); } if (itemsInCookie.Count > 4) { return(Content("limit")); } HttpContext.UpdateCookie(TotalInCompareCookieName, (++count).ToString()); } itemsInCookie.Add(product); HttpContext.UpdateCookie(CompareListCookieName, itemsInCookie.ToJson()); return(Content("ok")); }
public static void RemoveCookie(this HttpContext context, string name) => context.AddCookie(context.GetCookie(name).ExpireCookie());