private AddressInfo GetShippingInfo(Sitecore.Security.UserProfile profile) { /* TODO: Change to your extended address type if you have extended the address domain model. */ AddressInfo shippingInfo = new AddressInfo(); shippingInfo.Address = profile.GetCustomProperty("Shipping Address"); shippingInfo.Address2 = profile.GetCustomProperty("Shipping Address 2"); shippingInfo.City = profile.GetCustomProperty("Shipping Address City"); var countryCode = profile.GetCustomProperty("Shipping Address Country Code"); var country = this.countryProvider.GetDefault(); if (!string.IsNullOrWhiteSpace(countryCode)) { country = this.countryProvider.Get(countryCode); } shippingInfo.Country = country; shippingInfo.Name = profile.GetCustomProperty("Shipping Address Name"); shippingInfo.Name2 = profile.GetCustomProperty("Shipping Address Name 2"); shippingInfo.Phone = profile.GetCustomProperty("Shipping Address Phone"); shippingInfo.State = profile.GetCustomProperty("Shipping Address State"); shippingInfo.Zip = profile.GetCustomProperty("Shipping Address Zip"); /* TODO: Populate any additional fields you have added to the address domain model. */ shippingInfo.IsShippingDefault = true; return(shippingInfo); }
private void SetButtonText(LinkButton button) { Sitecore.Security.Accounts.User user = Sitecore.Context.User; Sitecore.Security.UserProfile profile = user.Profile; string favorites = profile.GetCustomProperty("Favorites"); if (favorites.Contains(Sitecore.Context.Item.ID.ToString())) { button.Text = GetDictionaryText("Remove from Favorites"); } else { button.Text = GetDictionaryText("Add to Favorites"); } }
public ActionResult FavoritesNavigation() { List <GenericLink> favs = new List <GenericLink>(); Sitecore.Security.Accounts.User user = Sitecore.Context.User; Sitecore.Security.UserProfile profile = user.Profile; string ItemIds = profile.GetCustomProperty("Favorites"); foreach (string itemId in ItemIds.Split('|')) { Item item = Sitecore.Context.Database.GetItem(itemId); if (item != null) { favs.Add(new GenericLink(item["Menu Title"], LinkManager.GetItemUrl(item), false)); } } return((favs.Count > 0) ? View("TertiaryNavigationPartialFavorites", favs as IEnumerable <GenericLink>) : null); }
private void sendMail(string owner, List <Item> list) { Sitecore.Security.UserProfile profile = getProfile(owner); string email = profile.Email; if (!string.IsNullOrEmpty(email)) { System.Text.StringBuilder itempaths = new System.Text.StringBuilder(); foreach (var item in list) { itempaths.AppendFormat("{0},", item.Paths.FullPath); } itempaths.Remove(itempaths.Length - 1, 1); string text = Current.Context.ReportItem.EmailText .Replace("$sc_user", profile.FullName) .Replace("$sc_item", itempaths.ToString()) .Replace("$sc_currentuser", Sitecore.Context.User.Profile.FullName); Util.SendMail(email, text); } }
private bool AddUser(string email, string password, string firstName, string lastName, string twitterHandle, string githubUsername, string linkedInUsername) { string userName = email; var success = false; //userName = string.Format(@"{0}\{1}", domain, userName); //string newPassword = Membership.GeneratePassword(10, 3); try { if (!User.Exists(userName)) { var domain = Sitecore.Context.Domain; var accountName = domain.GetFullName(userName); Membership.CreateUser(accountName, password, email); // Edit the profile information User user = User.FromName(accountName, true); Sitecore.Security.UserProfile userProfile = user.Profile; userProfile.FullName = string.Format("{0} {1}", firstName, lastName); //userProfile.Comment = comment; // Assigning the user profile template userProfile.SetPropertyValue("ProfileItemId", "{BBCCF1F4-A638-4FE3-9B2E-8E5D7D73AE9E}"); userProfile.SetCustomProperty("Twitter Handle", twitterHandle != null ? twitterHandle : string.Empty); userProfile.SetCustomProperty("Github Username", githubUsername); userProfile.SetCustomProperty("LinkedIn Username", linkedInUsername != null ? linkedInUsername : string.Empty); userProfile.Save(); success = true; } } catch (Exception ex) { Sitecore.Diagnostics.Log.Error(string.Format("Error in Client.Project.Security.UserMaintenance (AddUser): Message: {0}; Source:{1}", ex.Message, ex.Source), this); } return(success); }
public ActionResult AddToFavorites(string itemId) { try { Sitecore.Security.Accounts.User user = Sitecore.Context.User; Sitecore.Security.UserProfile profile = user.Profile; string favorites = profile.GetCustomProperty("Favorites"); // determine if we are adding or removing. // We don't know the text of the button because it is managed in the CMS, so we will see it is already a favorite. if (favorites.Contains(Sitecore.Context.Item.ID.ToString())) { favorites = favorites.Replace(Sitecore.Context.Item.ID.ToString(), String.Empty); favorites = favorites.Replace("||", "|"); // when removing we may leave a double pipe if (favorites == "|") { favorites = String.Empty; } } else // it must be an add { if (favorites == String.Empty) { favorites = Sitecore.Context.Item.ID.ToString(); } else { favorites = favorites + "|" + Sitecore.Context.Item.ID.ToString(); } // Capture the goal AnalyticsHelper.RegisterGoalOnCurrentPage("Add a Favorite", "[Add a Favorite] : \"" + Sitecore.Context.Item.Name + "\""); } profile.SetCustomProperty("Favorites", favorites); profile.Save(); } catch { } return(View("AddToFavorites", IsAddToFavorites)); }
protected void btnAddtoFavs_Click(object sender, EventArgs e) { Sitecore.Security.Accounts.User user = Sitecore.Context.User; Sitecore.Security.UserProfile profile = user.Profile; string favorites = profile.GetCustomProperty("Favorites"); // determine if we are adding or removing. // We don't know the text of the button because it is managed in the CMS, so we will see it is already a favorite. if (favorites.Contains(Sitecore.Context.Item.ID.ToString())) { favorites = favorites.Replace(Sitecore.Context.Item.ID.ToString(), String.Empty); favorites = favorites.Replace("||", "|"); // when removeing we may leave a double pipe if (favorites == "|") { favorites = String.Empty; } } else // it must be an add { if (favorites == String.Empty) { favorites = Sitecore.Context.Item.ID.ToString(); } else { favorites = favorites + "|" + Sitecore.Context.Item.ID.ToString(); } // Capture the goal using our helper method AnalyticsHelper.RegisterGoalOnCurrentPage("Add a Favorite", "[Add a Favorite] : \"" + Sitecore.Context.Item.Name + "\""); //Tracker.CurrentVisit.CurrentPage.Register("Add a Favorite", "[Add a Favorite] : \"" + Sitecore.Context.Item.Name + "\""); } profile.SetCustomProperty("Favorites", favorites); profile.Save(); SetButtonText(sender as LinkButton); }
protected void btnPrint_Click(object sender, EventArgs e) { Item projectItem = Sitecore.Context.Database.GetItem(this.projectPath); Sitecore.Security.Accounts.User user = Sitecore.Context.User; Sitecore.Security.UserProfile profile = user.Profile; if (projectItem != null) { string fileName = string.Format("{0}_{1}", projectItem.Name, DateTime.Now.Ticks.ToString()); PrintOptions printOptions = new PrintOptions { PrintExportType = PrintExportType.Pdf, ResultFileName = fileName, UseHighRes = false }; Database masterBase = Factory.GetDatabase("master"); printOptions.Parameters.Add("articles", profile.GetCustomProperty("Favorites")); PrintManager printManager = new PrintManager(masterBase, Sitecore.Context.Language); string result = printManager.Print(projectItem.ID.ToString(), printOptions); if (!string.IsNullOrEmpty(result) && File.Exists(result)) { var file = new FileInfo(result); Response.ContentType = "application/pdf"; Response.AppendHeader("content-disposition", string.Format("attachment; filename={0}", file.Name)); Response.AppendHeader("Content-Length", file.Length.ToString()); Response.TransmitFile(file.FullName); Response.Flush(); Response.End(); } } }
private void LoadFavorites() { List <Item> items = new List <Item>(); Sitecore.Security.Accounts.User user = Sitecore.Context.User; Sitecore.Security.UserProfile profile = user.Profile; string ItemIds = profile.GetCustomProperty("Favorites"); foreach (string itemId in ItemIds.Split('|')) { Item item = Sitecore.Context.Database.GetItem(itemId); if (item != null) { items.Add(item); } } if (items.Count > 0) { favoritesli.Visible = true; rptFavorites.DataSource = items; rptFavorites.DataBind(); } }