public override OrderProduct AddToCart(OrderType opType, int productId, int quantity, NameValueCollection paras) { int typecode; if (!int.TryParse(paras["typecode"], out typecode)) { typecode = 0; } ShopIdentity user = HttpContext.Current.User.Identity as ShopIdentity; MemberInfo member = MemberInfo.GetBaseInfo(user.UserId); OrderProduct op = OrderProducts.Find(c => c.ProductID == productId && c.TypeCode == typecode); if (op == null) { op = OrderProductFactory.Instance().CreateOrderProduct(productId, quantity, opType, paras); op.Key = this.Key + "_op" + this.GetSerial(); op.Container = this; this.ContinueShopUrl = op.ProductUrl; if (op != null) { if (this.TotalScore + op.TotalScore <= member.CurScore) { OrderProducts.Add(op); } else { op = null; } } } else { int oldQuantity = op.Quantity; op.SetQuantiy(op.Quantity + quantity); if (this.TotalScore > member.CurScore) { op.SetQuantiy(oldQuantity); } } return(op); }
/// <summary> /// 获取用户身份 /// </summary> /// <param name="context"></param> /// <returns></returns> private string GetIdentity(HttpContext context) { NameValueCollection nv = GetParas(context); string result = String.Empty; StringBuilder sb = new StringBuilder(200); JsonWriter jw = new JsonWriter(new StringWriter(sb)); jw.WriteStartObject(); if (context.User.Identity.IsAuthenticated) { ShopIdentity iden = context.User.Identity as ShopIdentity; if (iden != null) { //JavaScriptSerializer jss = new JavaScriptSerializer(); //result = jss.Serialize(iden); jw.WritePropertyName("result"); jw.WriteValue("true"); jw.WritePropertyName("userId"); jw.WriteValue(iden.UserId); jw.WritePropertyName("userName"); jw.WriteValue(iden.UserName); jw.WritePropertyName("userEmail"); jw.WriteValue(iden.UserEmail); jw.WritePropertyName("userType"); jw.WriteValue(iden.UserType.ToString()); jw.WritePropertyName("userLevel"); jw.WriteValue(iden.UserLevel.ToString()); } else { jw.WritePropertyName("result"); jw.WriteValue("false"); } } else { jw.WritePropertyName("result"); jw.WriteValue("false"); } jw.WriteEndObject(); return(sb.ToString()); }
protected void Application_OnPostAuthenticateRequest(object sender, EventArgs e) { IPrincipal user = HttpContext.Current.User; if (user.Identity.IsAuthenticated && user.Identity.AuthenticationType == "Forms") { try { FormsIdentity formIdentity = user.Identity as FormsIdentity; ShopIdentity identity = new ShopIdentity(formIdentity.Ticket); ShopPrincipal principal = new ShopPrincipal(identity); HttpContext.Current.User = principal; Thread.CurrentPrincipal = principal; } catch { } } }