public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args) { try { //Spontaneous.DataModel.SpontaneousProfileProvider //Get logged in user profile var logedInUserProfile = System.Web.Profile.ProfileBase.Create(args.Context.User.Identity.Name); //Get profile for anonymous user var anonymousUserProfile = System.Web.Profile.ProfileBase.Create(args.AnonymousID); log.InfoFormat("[Profile_OnMigrateAnonymous] From anonymous={0} to registered={1}", args.AnonymousID, args.Context.User.Identity.Name); //////// // Delete the anonymous profile. If the anonymous ID is not // needed in the rest of the site, remove the anonymous cookie. ProfileManager.DeleteProfile(args.AnonymousID); AnonymousIdentificationModule.ClearAnonymousIdentifier(); // Delete the user row that was created for the anonymous user. Membership.DeleteUser(args.AnonymousID, true); } catch (Exception ex) { log.Error("[Profile_OnMigrateAnonymous] error on migration from anonymous to registered.", ex); } }
// Carry over profile property values from an anonymous to an authenticated state protected void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e) { Profile anonymousProfile = PB.ProfileManager.Instance.GetAnonymousUser(); Profile profile = PB.ProfileManager.Instance.GetCurrentUser(e.Context.User.Identity.Name); //Merge anonymous shopping cart items to the authenticated shopping cart items foreach (Cart item in anonymousProfile.CartCollection) profile.CartCollection.Add(new Cart() { ItemId = item.ItemId, UniqueId = profile.UniqueId, IsShoppingCart = true, Quantity = item.Quantity}); //Merge anonymous wishlist items to the authenticated wishlist items foreach (Cart item in anonymousProfile.WishList) profile.WishList.Add(new Cart() { ItemId = item.ItemId, UniqueId = profile.UniqueId, IsShoppingCart = false, Quantity = item.Quantity }); var profileService = new ProfileService(); profileService.DeepSave(profile); // Clean up anonymous profile ProfileManager.DeleteProfile(e.AnonymousID); AnonymousIdentificationModule.ClearAnonymousIdentifier(); //Clear the cart. anonymousProfile.CartCollection.Clear(); anonymousProfile.WishList.Clear(); profileService.DeepSave(anonymousProfile); }
void OnEnter(object o, EventArgs eventArgs) { if (!ProfileManager.Enabled) { return; } if (HttpContext.Current.Request.IsAuthenticated) { HttpCookie cookie = app.Request.Cookies [anonymousCookieName]; if (cookie != null && (cookie.Expires != DateTime.MinValue && cookie.Expires > DateTime.Now)) { ProfileMigrateEventHandler eh = events [migrateAnonymousEvent] as ProfileMigrateEventHandler; if (eh != null) { ProfileMigrateEventArgs e = new ProfileMigrateEventArgs(HttpContext.Current, Encoding.Unicode.GetString(Convert.FromBase64String(cookie.Value))); eh(this, e); } HttpCookie newCookie = new HttpCookie(anonymousCookieName); newCookie.Path = app.Request.ApplicationPath; newCookie.Expires = new DateTime(1970, 1, 1); newCookie.Value = ""; app.Response.AppendCookie(newCookie); } } }
/// <summary> /// Profile migrate from anonymous. /// </summary> /// <param name="sender">The sender.</param> /// <param name="pe">The <see cref="ProfileMigrateEventArgs"/> instance containing the event data.</param> private void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs pe) { var client = ServiceLocator.Current.GetInstance<OrderClient>(); var orders = client.GetAllCustomerOrders(pe.AnonymousID, UserHelper.CustomerSession.StoreId); if (orders != null) { foreach (var order in orders) { order.CustomerId = UserHelper.CustomerSession.CustomerId; order.CustomerName = UserHelper.CustomerSession.CustomerName; } client.SaveChanges(); } // Migrate shopping cart var cart = new CartHelper(CartHelper.CartName); var anonymousCart = new CartHelper(CartHelper.CartName, pe.AnonymousID); // Only perform merge if cart is not empty if (!anonymousCart.IsEmpty) { // Merge cart cart.Add(anonymousCart.Cart, true); cart.SaveChanges(); // Delete anonymous cart anonymousCart.Delete(); anonymousCart.SaveChanges(); } var wishList = new CartHelper(CartHelper.WishListName); var anonymousWishList = new CartHelper(CartHelper.WishListName, pe.AnonymousID); // Only perform merge if cart is not empty if (!anonymousWishList.IsEmpty) { // Merge wish list wishList.Add(anonymousWishList.Cart, true); if (String.IsNullOrEmpty(wishList.Cart.BillingCurrency)) { wishList.Cart.BillingCurrency = UserHelper.CustomerSession.Currency; } wishList.SaveChanges(); // Delete anonymous wish list anonymousWishList.Delete(); anonymousWishList.SaveChanges(); } //Delete the anonymous data from the database //ProfileManager.DeleteProfile(pe.AnonymousID); //Remove the anonymous identifier from the request so //this event will no longer fire for a logged-in user AnonymousIdentificationModule.ClearAnonymousIdentifier(); }
private void OnEnter(object source, EventArgs eventArgs) { HttpContext context = ((HttpApplication)source).Context; this.OnPersonalize(new ProfileEventArgs(context)); if ((context.Request.IsAuthenticated && !string.IsNullOrEmpty(context.Request.AnonymousID)) && (this._MigrateEventHandler != null)) { ProfileMigrateEventArgs e = new ProfileMigrateEventArgs(context, context.Request.AnonymousID); this._MigrateEventHandler(this, e); } }
void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs e) { //// get a reference to the previously anonymous user's profile //ProfileCommon anonProfile = this.Profile.GetProfile(e.AnonymousID); //// if set, copy its Theme and ShoppingCart to the current user's profile //if (anonProfile.ShoppingCart.Items.Count > 0) // this.Profile.ShoppingCart = anonProfile.ShoppingCart; //if (!string.IsNullOrEmpty(anonProfile.Preferences.Theme)) // this.Profile.Preferences.Theme = anonProfile.Preferences.Theme; //// delete the anonymous profile //ProfileManager.DeleteProfile(e.AnonymousID); //AnonymousIdentificationModule.ClearAnonymousIdentifier(); }
void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e) { ProfileCommon Profile = new ProfileCommon(); ProfileCommon anonProfile = Profile.GetProfile(e.AnonymousID); foreach (CartItemInfo cartItem in anonProfile.ShoppingCart.CartItems) Profile.ShoppingCart.Add(cartItem); foreach (CartItemInfo cartItem in anonProfile.WishList.CartItems) Profile.WishList.Add(cartItem); ProfileManager.DeleteProfile(e.AnonymousID); AnonymousIdentificationModule.ClearAnonymousIdentifier(); Profile.Save(); }
// Carry over profile property values from an anonymous to an authenticated state void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e) { var anonProfile = ProfileBase.Create(e.AnonymousID); //CustomProfile anonProfile = Profile.GetProfile(e.AnonymousID); // Merge anonymous shopping cart items to the authenticated shopping cart items foreach (CartItemInfo cartItem in ((PetShop.BLL.Cart)anonProfile.GetPropertyValue("ShoppingCart")).CartItems) Profile.ShoppingCart.Add(cartItem); // Merge anonymous wishlist items to the authenticated wishlist items foreach (CartItemInfo cartItem in((PetShop.BLL.Cart)(anonProfile.GetPropertyValue("WishList"))).CartItems) Profile.WishList.Add(cartItem); // Clean up anonymous profile ProfileManager.DeleteProfile(e.AnonymousID); AnonymousIdentificationModule.ClearAnonymousIdentifier(); // Save profile Profile.Save(); }
// Carry over profile property values from an anonymous to an authenticated state protected void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e) { Profile anonymousProfile = PB.ProfileManager.Instance.GetAnonymousUser(); Profile profile = PB.ProfileManager.Instance.GetCurrentUser(e.Context.User.Identity.Name); //Merge anonymous shopping cart items to the authenticated shopping cart items foreach (Cart item in anonymousProfile.ShoppingCart) profile.ShoppingCart.Add(item.ItemId, profile.UniqueID, true, item.Quantity); //Merge anonymous wishlist items to the authenticated wishlist items foreach (Cart item in anonymousProfile.WishList) profile.WishList.Add(item.ItemId, profile.UniqueID, false, item.Quantity); profile = profile.Save(); //Clear the cart. anonymousProfile.ShoppingCart.Clear(); anonymousProfile.WishList.Clear(); anonymousProfile = anonymousProfile.Save(); // Clean up anonymous profile //ProfileManager.DeleteProfile(e.AnonymousID); //AnonymousIdentificationModule.ClearAnonymousIdentifier(); }
/// <summary> /// Handles the OnMigrateAnonymous event of the Profile control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="T:System.Web.Profile.ProfileMigrateEventArgs"/> instance containing the event data.</param> public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args) { OrderController.MigrateCart(args.AnonymousID, WebProfile.Current.UserName); ProfileManager.DeleteProfile(args.AnonymousID); AnonymousIdentificationModule.ClearAnonymousIdentifier(); }
protected void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs args) { //TODO: maybe support capturing profile properties for anonymous users // then if they register transfer them to the new user //WebProfile anonymousProfile = new WebProfile(args.Context.Profile); //Profile.ZipCode = anonymousProfile; //Profile.CityAndState = anonymousProfile.CityAndState; //Profile.StockSymbols = anonymousProfile.StockSymbols; //////// // Delete the anonymous profile. If the anonymous ID is not // needed in the rest of the site, remove the anonymous cookie. //ProfileManager.DeleteProfile(args.AnonymousID); //AnonymousIdentificationModule.ClearAnonymousIdentifier(); // Delete the user row that was created for the anonymous user. //Membership.DeleteUser(args.AnonymousID, true); }
//////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> private void OnEnter(Object source, EventArgs eventArgs) { HttpContext context = ((HttpApplication)source).Context; OnPersonalize(new ProfileEventArgs(context)); if (context.Request.IsAuthenticated && !string.IsNullOrEmpty(context.Request.AnonymousID) && _MigrateEventHandler != null) { ProfileMigrateEventArgs e = new ProfileMigrateEventArgs(context, context.Request.AnonymousID); _MigrateEventHandler(this, e); } }
/// <summary> /// The profile_ on migrate anonymous. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="args"> /// The args. /// </param> public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args) { ProfileManager.DeleteProfile(args.AnonymousID); AnonymousIdentificationModule.ClearAnonymousIdentifier(); }
private void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs args) { SessionWrapper wrapper = SessionManager.GetSessionWrapper(); try { IUserProfileDao profileDao = OrnamentContext.DaoFactory.MemberShipFactory.CreateProfileDao(); ProfileValue anonymous = profileDao.FindByLoginId(args.AnonymousID); if (anonymous != null) { //合并anonymous profile ProfileBase currenProfile = HttpContext.Current.Profile; foreach (string key in anonymous.Properities.Keys) { currenProfile.SetPropertyValue(key, anonymous.Properities[key]); } profileDao.Delete(anonymous); currenProfile.Save(); AnonymousIdentificationModule.ClearAnonymousIdentifier(); } //最后,一更新Multi-lang的cookie,因此使用Profile的语言。 OrnamentContext.MemberShip.SwitchLanguage(OrnamentContext.MemberShip.CurrentUser().GetLanguage()); wrapper.Commit(); } catch (Exception ex) { ILog log = LogManager.GetLogger(typeof(GlobalContext)); log.Error(ex.Message, ex); } finally { wrapper.Close(); } }
/// <summary> /// 匿名ユーザから特定のユーザにログインされた場合に、 /// 匿名ユーザの状態で設定されたプロファイルの内容をマージし、 /// 且つ、特定ユーザーのプロファイルとユーザ識別情報を削除する. /// (現在はweb.configで匿名ユーザは無効にしているため、この処理は実行されない) /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args) { foreach (ProfileInfo profile in ProfileManager.FindProfilesByUserName( ProfileAuthenticationOption.Anonymous, args.AnonymousID)) { if (string.Equals(profile.UserName, args.AnonymousID)) { // 匿名としてのプロファイルの登録内容をログインしたプロファイルに転記する ProfileBase newProfile = HttpContext.Current.Profile; ProfileBase oldProfile = ProfileBase.Create(args.AnonymousID, false); foreach (SettingsProperty prop in ProfileBase.Properties) { // プロパティ定義一覧とデフォルト値の取得 string propertyName = prop.Name; object defValue = prop.DefaultValue; Type defValueType = prop.PropertyType; if (defValue != null && defValueType != null) { // デフォルト値は型変換しておく defValue = Convert.ChangeType(defValue, defValueType); } // 匿名プロファイルでの設定値 object value = oldProfile.GetPropertyValue(propertyName); if (!object.Equals(defValue, value)) { // 匿名プロファイルでデフォルト値から設定値を変えていた場合は // 名前つきプロファイル側に更新内容を反映する. // (デフォルト値のままであれば以前のものを優先する.) newProfile.SetPropertyValue(propertyName, value); } } // 匿名ユーザのプロファイルとユーザ登録を // DBおよび セッションから削除します ProfileManager.DeleteProfile(args.AnonymousID); AnonymousIdentificationModule.ClearAnonymousIdentifier(); Membership.DeleteUser(args.AnonymousID, true); } } }
void OnEnter (object o, EventArgs eventArgs) { if (!ProfileManager.Enabled) return; if (HttpContext.Current.Request.IsAuthenticated) { HttpCookie cookie = app.Request.Cookies [anonymousCookieName]; if (cookie != null && (cookie.Expires != DateTime.MinValue && cookie.Expires > DateTime.Now)) { ProfileMigrateEventHandler eh = events [migrateAnonymousEvent] as ProfileMigrateEventHandler; if (eh != null) { ProfileMigrateEventArgs e = new ProfileMigrateEventArgs (HttpContext.Current, Encoding.Unicode.GetString (Convert.FromBase64String (cookie.Value))); eh (this, e); } HttpCookie newCookie = new HttpCookie (anonymousCookieName); newCookie.Path = app.Request.ApplicationPath; newCookie.Expires = new DateTime (1970, 1, 1); newCookie.Value = ""; app.Response.AppendCookie (newCookie); } } }