/// <summary> /// Logs "post" activity. /// </summary> /// <param name="bci">Forum subscription</param> /// <param name="fi">Forum info</param> private void LogPostActivity(ForumPostInfo fp, ForumInfo fi) { string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (fp == null) || (fi == null) || !fi.ForumLogActivity || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.ForumPostsEnabled(siteName)) { return; } int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); Dictionary <string, object> contactData = new Dictionary <string, object>(); contactData.Add("ContactEmail", fp.PostUserMail); contactData.Add("ContactLastName", fp.PostUserName); ModuleCommands.OnlineMarketingUpdateContactFromExternalSource(contactData, false, contactId); var data = new ActivityData() { ContactID = contactId, SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.FORUM_POST, TitleData = fi.ForumName, ItemID = fi.ForumID, ItemDetailID = fp.PostId, URL = URLHelper.CurrentRelativePath, NodeID = CMSContext.CurrentDocument.NodeID, Culture = CMSContext.CurrentDocument.DocumentCulture, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Logs "subscription" activity. /// </summary> /// <param name="bci">Forum subscription</param> private void LogSubscriptionActivity(ForumSubscriptionInfo fsi, ForumInfo fi) { string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (fsi == null) || (fi == null) || !fi.ForumLogActivity || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.ForumPostSubscriptionEnabled(siteName)) { return; } var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.SUBSCRIPTION_FORUM_POST, TitleData = fi.ForumName, ItemID = fi.ForumID, ItemDetailID = fsi.SubscriptionID, URL = URLHelper.CurrentRelativePath, NodeID = CMSContext.CurrentDocument.NodeID, Culture = CMSContext.CurrentDocument.DocumentCulture, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Logs activity /// </summary> /// <param name="skuId">Product ID</param> /// <param name="skuName">Product name</param> /// <param name="Quantity">Quantity</param> private void LogProductAddedToSCActivity(int skuId, string skuName, int Quantity) { if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser)) { return; } string siteName = CMSContext.CurrentSiteName; if (!ActivitySettingsHelper.AddingProductToSCEnabled(siteName) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName)) { return; } var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.PRODUCT_ADDED_TO_SHOPPINGCART, TitleData = skuName, Value = Quantity.ToString(), ItemID = skuId, URL = URLHelper.CurrentRelativePath, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Log activity (subscribing). /// </summary> /// <param name="bsi">Board subscription info object</param> /// <param name="bi">Message board info</param> private void LogSubscribingActivity(BoardSubscriptionInfo bsi, BoardInfo bi) { string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (bsi == null) || (bi == null) || !bi.BoardLogActivity || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.MessageBoardSubscriptionEnabled(siteName)) { return; } TreeNode currentDoc = CMSContext.CurrentDocument; var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.SUBSCRIPTION_MESSAGE_BOARD, TitleData = bi.BoardDisplayName, URL = URLHelper.CurrentRelativePath, NodeID = (currentDoc != null ? currentDoc.NodeID : 0), Culture = (currentDoc != null ? currentDoc.DocumentCulture : null), Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Logs "delete" activity /// </summary> /// <param name="documentName">Document name</param> /// <param name="nodeId">Document node ID</param> /// <param name="culture">Document culture</param> private void LogDeleteActivity(string documentName, int nodeId, string culture) { if (!this.LogActivity || (CMSContext.ViewMode != ViewModeEnum.LiveSite) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser)) { return; } string siteName = CMSContext.CurrentSiteName; if (ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) && ActivitySettingsHelper.WikiContributionDeleteEnabled(siteName)) { var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.USER_CONTRIB_DELETE, TitleData = documentName, NodeID = nodeId, URL = URLHelper.CurrentRelativePath, Culture = culture, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); } }
/// <summary> /// Logs activity /// </summary> /// <param name="pollId">Poll</param> /// <param name="answers">Answers</param> private void LogActivity(PollInfo pi, string answers) { string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || !IsLiveSite || (pi == null) || !pi.PollLogActivity || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.PollVotingEnabled(siteName)) { return; } TreeNode currentDoc = CMSContext.CurrentDocument; var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.POLL_VOTING, TitleData = pi.PollQuestion, ItemID = pi.PollID, URL = URLHelper.CurrentRelativePath, NodeID = (currentDoc != null ? currentDoc.NodeID : 0), Culture = (currentDoc != null ? currentDoc.DocumentCulture : null), Value = answers, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Log activity /// </summary> /// <param name="gmi">Member info</param> /// <param name="logActivity">Determines whether activity logging is enabled for current group</param> /// <param name="groupDisplayName">Display name of the group</param> private void LogLeaveActivity(GroupMemberInfo gmi, bool logActivity, string groupDisplayName) { string siteName = CMSContext.CurrentSiteName; if (!logActivity || (CMSContext.ViewMode != ViewModeEnum.LiveSite) || (gmi == null) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.JoiningAGroupEnabled(siteName)) { return; } TreeNode currentDoc = CMSContext.CurrentDocument; var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.LEAVE_GROUP, TitleData = groupDisplayName, ItemID = gmi.MemberGroupID, URL = URLHelper.CurrentRelativePath, NodeID = (currentDoc != null ? currentDoc.NodeID : 0), Culture = (currentDoc != null ? currentDoc.DocumentCulture : null), Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Log activity (subscribing) /// </summary> /// <param name="bsi"></param> private void LogActivity(BoardSubscriptionInfo bsi, BoardInfo bi) { string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (bsi == null) || (bi == null) || !bi.BoardLogActivity || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.MessageBoardSubscriptionEnabled(siteName)) { return; } TreeNode currentDoc = CMSContext.CurrentDocument; int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); Dictionary <string, object> contactData = new Dictionary <string, object>(); contactData.Add("ContactEmail", bsi.SubscriptionEmail); ModuleCommands.OnlineMarketingUpdateContactFromExternalSource(contactData, false, contactId); var data = new ActivityData() { ContactID = contactId, SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.SUBSCRIPTION_MESSAGE_BOARD, TitleData = bi.BoardName, URL = URLHelper.CurrentRelativePath, NodeID = (currentDoc != null ? currentDoc.NodeID : 0), Culture = (currentDoc != null ? currentDoc.DocumentCulture : null), Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Log activity posting /// </summary> /// <param name="bsi">Board subscription info object</param> /// <param name="bi">Message board info</param> private void LogCommentActivity(BoardMessageInfo bmi, BoardInfo bi) { string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (bmi == null) || (bi == null) || !bi.BoardLogActivity || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.MessageBoardPostsEnabled(siteName)) { return; } int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); Dictionary <string, object> contactData = new Dictionary <string, object>(); contactData.Add("ContactEmail", bmi.MessageEmail); contactData.Add("ContactWebSite", bmi.MessageURL); contactData.Add("ContactLastName", bmi.MessageUserName); ModuleCommands.OnlineMarketingUpdateContactFromExternalSource(contactData, false, contactId); TreeNode currentDoc = CMSContext.CurrentDocument; var data = new ActivityData() { ContactID = contactId, SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.MESSAGE_BOARD_COMMENT, TitleData = bi.BoardDisplayName, ItemID = bmi.MessageBoardID, URL = URLHelper.CurrentRelativePath, ItemDetailID = bmi.MessageID, NodeID = (currentDoc != null ? currentDoc.NodeID : 0), Culture = (currentDoc != null ? currentDoc.DocumentCulture : null), Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Logs activity for subscribing/unsubscribing /// </summary> /// <param name="ui">User</param> /// <param name="newsletterId">Newsletter ID</param> /// <param name="subscribe">Subscribing/unsubscribing flag</param> /// <param name="siteId">Site ID</param> private void LogActivity(UserInfo ui, int newsletterId, bool subscribe, int siteId) { if ((sb == null) || (ui == null) || (CMSContext.ViewMode != ViewModeEnum.LiveSite) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteId) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(ui)) { return; } if (sb.SubscriberType == SiteObjectType.USER) { if (subscribe && ActivitySettingsHelper.NewsletterSubscribeEnabled(siteId) || !subscribe && ActivitySettingsHelper.NewsletterUnsubscribeEnabled(siteId)) { Newsletter news = NewsletterProvider.GetNewsletter(newsletterId); if ((news != null) && news.NewsletterLogActivity) { var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = sb.SubscriberSiteID, Type = PredefinedActivityType.NEWSLETTER_UNSUBSCRIBING, TitleData = news.NewsletterName, ItemID = newsletterId, URL = URLHelper.CurrentRelativePath, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); } } } }
/// <summary> /// OnAfterSave handler. /// </summary> protected void editProfileForm_OnAfterSave(object sender, EventArgs e) { // Update current contact info ModuleCommands.OnlineMarketingUpdateContactFromExternalData(editProfileForm.Info, DataClassInfoProvider.GetDataClass(editProfileForm.ClassName).ClassContactOverwriteEnabled, ModuleCommands.OnlineMarketingGetCurrentContactID()); ShowChangesSaved(); }
/// <summary> /// Merge contact with customer and creates relation between these two. /// </summary> /// <param name="customerInfo">Registered customer to merge with proper contact</param> private void CreateContactRelation(CustomerInfo customerInfo) { int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); ModuleCommands.OnlineMarketingCreateRelation(customerInfo.CustomerID, MembershipType.ECOMMERCE_CUSTOMER, contactId); ModuleCommands.OnlineMarketingUpdateContactFromExternalData( customerInfo, DataClassInfoProvider.GetDataClassInfo(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled, contactId); }
/// <summary> /// Logs activity. /// </summary> /// <param name="bci">Blog comment info</param> /// <param name="nodeId">Docuemnt node ID</param> /// <param name="culture">Docuemnt culture</param> private void LogCommentActivity(BlogCommentInfo bci, int nodeId, string culture) { if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (bci == null) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser)) { return; } string siteName = CMSContext.CurrentSiteName; if (!ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.BlogPostCommentsEnabled(siteName)) { return; } if (bci.CommentPostDocumentID > 0) { // Load blog post settings and check if logging is enabled for current post TreeProvider tree = new TreeProvider(); TreeNode blogPost = DocumentHelper.GetDocument(bci.CommentPostDocumentID, tree); if ((blogPost != null) && ValidationHelper.GetBoolean(blogPost.GetValue("BlogLogActivity"), false)) { TreeNode blogNode = BlogHelper.GetParentBlog(bci.CommentPostDocumentID, false); string blogName = null; if (blogNode != null) { blogName = blogNode.DocumentName; } int contactID = ModuleCommands.OnlineMarketingGetCurrentContactID(); var data = new ActivityData() { ContactID = contactID, SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.BLOG_COMMENT, TitleData = blogName, ItemID = bci.CommentID, URL = URLHelper.CurrentRelativePath, ItemDetailID = (blogNode != null ? blogNode.NodeID : 0), NodeID = nodeId, Culture = culture, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); Dictionary <string, object> contactData = new Dictionary <string, object>(); contactData.Add("ContactEmail", bci.CommentEmail); contactData.Add("ContactLastName", bci.CommentUserName); contactData.Add("ContactWebSite", bci.CommentUrl); ModuleCommands.OnlineMarketingUpdateContactFromExternalSource(contactData, false, contactID); } } }
/// <summary> /// Logs activity. /// </summary> /// <param name="bpsi">Blog subscription info</param> /// <param name="nodeId">Docuemnt node ID</param> /// <param name="culture">Document culture</param> private void LogActivity(BlogPostSubscriptionInfo bpsi, int nodeId, string culture) { if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (bpsi == null) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser)) { return; } string siteName = CMSContext.CurrentSiteName; if (!ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.BlogPostSubscriptionEnabled(siteName)) { return; } if (bpsi.SubscriptionPostDocumentID > 0) { TreeProvider tree = new TreeProvider(); TreeNode blogPost = DocumentHelper.GetDocument(bpsi.SubscriptionPostDocumentID, tree); if ((blogPost != null) && ValidationHelper.GetBoolean(blogPost.GetValue("BlogLogActivity"), false)) { string blogName = null; TreeNode blogNode = BlogHelper.GetParentBlog(bpsi.SubscriptionPostDocumentID, false); if (blogNode != null) { blogName = blogNode.DocumentName; } // Update contact info according to subscribtion int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); Dictionary <string, object> contactData = new Dictionary <string, object>(); contactData.Add("ContactEmail", bpsi.SubscriptionEmail); ModuleCommands.OnlineMarketingUpdateContactFromExternalSource(contactData, false, contactId); var data = new ActivityData() { ContactID = contactId, SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.SUBSCRIPTION_BLOG_POST, ItemDetailID = (blogNode != null ? blogNode.NodeID : 0), TitleData = bpsi.SubscriptionEmail, URL = URLHelper.CurrentRelativePath, NodeID = nodeId, Value = TextHelper.LimitLength(blogName, 250), Culture = culture, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); } } }
/// <summary> /// Logs rating activity /// </summary> /// <param name="value">Rating value</param> private void LogActivity(double value) { if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser)) { return; } string siteName = CMSContext.CurrentSiteName; if (!ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.ContentRatingEnabled(siteName)) { return; } bool logActivity = false; TreeNode currentDoc = CMSContext.CurrentDocument; if (currentDoc != null) { if (CMSContext.CurrentDocument.DocumentLogVisitActivity == null) { logActivity = ValidationHelper.GetBoolean(currentDoc.GetInheritedValue("DocumentLogVisitActivity", SiteInfoProvider.CombineWithDefaultCulture(siteName)), false); } else { logActivity = currentDoc.DocumentLogVisitActivity == true; } if (logActivity) { var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.RATING, TitleData = String.Format("{0} ({1})", value.ToString(), currentDoc.DocumentName), URL = URLHelper.CurrentRelativePath, NodeID = currentDoc.NodeID, Value = value.ToString(), Culture = currentDoc.DocumentCulture, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); } } }
/// <summary> /// Checks if page visit activity logging is enabled, if so returns contact ID. /// </summary> /// <param name="file">File to be sent</param> /// <param name="contactId">Current contact ID</param> protected bool LoggingActivityEnabled(CMSOutputFile file, out int contactId) { contactId = 0; if ((file == null) || (file.FileNode == null)) { return(false); } // Check if logging is enabled if (ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(CurrentSiteName) && ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) && ActivitySettingsHelper.PageVisitsEnabled(CurrentSiteName)) { if (file.Attachment != null) { // Get allowed extensions (if not specified log everything) bool doLog = true; string tracked = SettingsKeyProvider.GetStringValue(CurrentSiteName + ".CMSActivityTrackedExtensions"); if (!String.IsNullOrEmpty(tracked)) { string extension = file.Attachment.AttachmentExtension; if (extension != null) { string extensions = String.Format(";{0};", tracked.ToLower().Trim().Trim(';')); extension = extension.TrimStart('.').ToLower(); doLog = extensions.Contains(String.Format(";{0};", extension)); } } if (doLog) { // Check if logging is enabled for current document TreeNode fileNode = file.FileNode; if ((fileNode != null) && ((fileNode.DocumentLogVisitActivity == true) || (fileNode.DocumentLogVisitActivity == null) && ValidationHelper.GetBoolean(fileNode.GetInheritedValue("DocumentLogVisitActivity", SiteInfoProvider.CombineWithDefaultCulture(CurrentSiteName)), false))) { contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); return(contactId > 0); } } } } return(false); }
/// <summary> /// Logs activity /// </summary> /// <param name="skuId">SKU ID</param> /// <param name="skuName">Product name</param> /// <param name="siteId">Site ID</param> private void LogProductAddedToWLActivity(int skuId, string skuName, int siteId) { if ((currentUser == null) || (CMSContext.ViewMode != ViewModeEnum.LiveSite) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteId) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(currentUser) || !ActivitySettingsHelper.AddingProductToWLEnabled(siteId)) { return; } var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = siteId, Type = PredefinedActivityType.PRODUCT_ADDED_TO_WISHLIST, TitleData = skuName, ItemID = skuId, URL = URLHelper.CurrentRelativePath, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Log activity /// </summary> /// <param name="ari">Report info</param> private void LogActivity(AbuseReportInfo ari) { if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (ari == null) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(ari.ReportSiteID) || !ActivitySettingsHelper.AbuseReportEnabled(ari.ReportSiteID)) { return; } var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = ari.ReportSiteID, Type = PredefinedActivityType.ABUSE_REPORT, TitleData = ari.ReportTitle, ItemID = ari.ReportID, URL = URLHelper.CurrentRelativePath, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Save subscriber. /// </summary> /// <returns>Subscriver info object</returns> private SubscriberInfo SaveSubscriber() { // Check if a subscriber exists first SubscriberInfo sb = null; if (AllowUserSubscribers && (MembershipContext.AuthenticatedUser != null) && AuthenticationHelper.IsAuthenticated()) { sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, MembershipContext.AuthenticatedUser.UserID, SiteContext.CurrentSiteID); } else { sb = SubscriberInfoProvider.GetSubscriberInfo(txtEmail.Text, SiteContext.CurrentSiteID); } if ((sb == null) || ((chooseMode) && (sb != null))) { // Create subscriber if (sb == null) { sb = new SubscriberInfo(); } // Handle authenticated user if (AllowUserSubscribers && (MembershipContext.AuthenticatedUser != null) && AuthenticationHelper.IsAuthenticated()) { // Get user info and copy first name, last name or full name to new subscriber UserInfo ui = UserInfoProvider.GetUserInfo(MembershipContext.AuthenticatedUser.UserID); if (ui != null) { if (!DataHelper.IsEmpty(ui.FirstName) && !DataHelper.IsEmpty(ui.LastName)) { sb.SubscriberFirstName = ui.FirstName; sb.SubscriberLastName = ui.LastName; } else { sb.SubscriberFirstName = ui.FullName; } // Full name consists of "user " and user full name sb.SubscriberFullName = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName); } else { return(null); } sb.SubscriberType = UserInfo.OBJECT_TYPE; sb.SubscriberRelatedID = MembershipContext.AuthenticatedUser.UserID; } // Work with non-authenticated user else { sb.SubscriberEmail = txtEmail.Text.Trim(); // First name if (DisplayFirstName) { sb.SubscriberFirstName = txtFirstName.Text; } else { sb.SubscriberFirstName = string.Empty; } // Last name if (DisplayLastName) { sb.SubscriberLastName = txtLastName.Text; } else { sb.SubscriberLastName = string.Empty; } // Full name sb.SubscriberFullName = (sb.SubscriberFirstName + " " + sb.SubscriberLastName).Trim(); } // Set site ID sb.SubscriberSiteID = SiteContext.CurrentSiteID; // Check subscriber limits if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { lblError.Visible = true; lblError.Text = GetString("LicenseVersionCheck.Subscribers"); return(null); } // Save subscriber info SubscriberInfoProvider.SetSubscriberInfo(sb); } if (sb != null) { // Create membership between current contact and subscriber ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, ModuleCommands.OnlineMarketingGetCurrentContactID()); } // Hide all visibleLastName = false; visibleFirstName = false; visibleEmail = false; pnlButtonSubmit.Visible = false; pnlImageSubmit.Visible = false; plcNwsList.Visible = false; // Clear the form txtEmail.Text = string.Empty; txtFirstName.Text = string.Empty; txtLastName.Text = string.Empty; // Return subscriber info object return(sb); }
/// <summary> /// Sends confirmation or welcome email. /// </summary> private void SendRegistrationEmail(UserInfo ui, string password) { bool error = false; EmailTemplateInfo template = null; // Email message EmailMessage emailMessage = new EmailMessage(); emailMessage.EmailFormat = EmailFormatEnum.Default; emailMessage.Recipients = ui.Email; // Send welcome message with username and password, with confirmation link, user must confirm registration if (ConfirmationRequired) { template = EmailTemplateProvider.GetEmailTemplate("RegistrationConfirmation", CurrentSiteName); emailMessage.Subject = GetString("RegistrationForm.RegistrationConfirmationEmailSubject"); } // Send welcome message with username and password, with information that user must be approved by administrator else if (SendWelcomeEmail) { if (AdminApprovalRequired) { template = EmailTemplateProvider.GetEmailTemplate("Membership.RegistrationWaitingForApproval", CurrentSiteName); emailMessage.Subject = GetString("RegistrationForm.RegistrationWaitingForApprovalSubject"); } // Send welcome message with username and password, user can logon directly else { template = EmailTemplateProvider.GetEmailTemplate("Membership.Registration", CurrentSiteName); emailMessage.Subject = GetString("RegistrationForm.RegistrationSubject"); } } if (template != null) { // Create relation between contact and user. This ensures that contact will be correctly recognized when user approves registration (if approval is required) int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); if (contactId > 0) { ModuleCommands.OnlineMarketingCreateRelation(ui.UserID, MembershipType.CMS_USER, contactId); } // Prepare resolver for notification and welcome emails MacroResolver resolver = MembershipResolvers.GetMembershipRegistrationResolver(ui, password, AuthenticationHelper.GetRegistrationApprovalUrl(ApprovalPage, ui.UserGUID, CurrentSiteName, NotifyAdministrator)); emailMessage.From = EmailHelper.GetSender(template, SettingsKeyInfoProvider.GetValue(CurrentSiteName + ".CMSNoreplyEmailAddress")); // Enable macro encoding for body resolver.Settings.EncodeResolvedValues = true; emailMessage.Body = resolver.ResolveMacros(template.TemplateText); // Disable macro encoding for plaintext body and subject resolver.Settings.EncodeResolvedValues = false; emailMessage.PlainTextBody = resolver.ResolveMacros(template.TemplatePlainText); emailMessage.Subject = resolver.ResolveMacros(EmailHelper.GetSubject(template, emailMessage.Subject)); emailMessage.CcRecipients = template.TemplateCc; emailMessage.BccRecipients = template.TemplateBcc; try { EmailHelper.ResolveMetaFileImages(emailMessage, template.TemplateID, EmailTemplateInfo.OBJECT_TYPE, ObjectAttachmentsCategories.TEMPLATE); // Send the e-mail immediately EmailSender.SendEmail(CurrentSiteName, emailMessage, true); } catch (Exception ex) { EventLogProvider.LogException("E", "RegistrationForm - SendEmail", ex); error = true; } } // If there was some error, user must be deleted if (error) { ShowError(GetString("RegistrationForm.UserWasNotCreated")); // Email was not send, user can't be approved - delete it UserInfoProvider.DeleteUser(ui); } }
/// <summary> /// Sends confirmation or welcome email. /// </summary> private void SendRegistrationEmail(UserInfo ui) { bool error = false; EmailTemplateInfo template = null; // Email message EmailMessage emailMessage = new EmailMessage(); emailMessage.EmailFormat = EmailFormatEnum.Default; emailMessage.Recipients = ui.Email; emailMessage.From = SettingsKeyInfoProvider.GetValue(CurrentSiteName + ".CMSNoreplyEmailAddress"); // Send welcome message with username and password, with confirmation link, user must confirm registration if (ConfirmationRequired) { template = EmailTemplateProvider.GetEmailTemplate("RegistrationConfirmation", CurrentSiteName); emailMessage.Subject = GetString("RegistrationForm.RegistrationConfirmationEmailSubject"); } // Send welcome message with username and password, with information that user must be approved by administrator else if (SendWelcomeEmail) { if (AdminApprovalRequired) { template = EmailTemplateProvider.GetEmailTemplate("Membership.RegistrationWaitingForApproval", CurrentSiteName); emailMessage.Subject = GetString("RegistrationForm.RegistrationWaitingForApprovalSubject"); } // Send welcome message with username and password, user can logon directly else { template = EmailTemplateProvider.GetEmailTemplate("Membership.Registration", CurrentSiteName); emailMessage.Subject = GetString("RegistrationForm.RegistrationSubject"); } } if (template != null) { // Create relation between contact and user. This ensures that contact will be correctly recognized when user approves registration (if approval is required) int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); if (contactId > 0) { ModuleCommands.OnlineMarketingCreateRelation(ui.UserID, MembershipType.CMS_USER, contactId); } try { // Prepare resolver for notification and welcome emails MacroResolver resolver = MembershipResolvers.GetMembershipRegistrationResolver(ui, AuthenticationHelper.GetRegistrationApprovalUrl(ApprovalPage, ui.UserGUID, CurrentSiteName, NotifyAdministrator)); EmailSender.SendEmailWithTemplateText(CurrentSiteName, emailMessage, template, resolver, true); } catch (Exception ex) { EventLogProvider.LogException("E", "RegistrationForm - SendEmail", ex); error = true; } } // If there was some error, user must be deleted if (error) { ShowError(GetString("RegistrationForm.UserWasNotCreated")); // Email was not send, user can't be approved - delete it UserInfoProvider.DeleteUser(ui); } }
/// <summary> /// Process valid values of this step. /// </summary> public override bool ProcessStep() { if (plcAccount.Visible) { string siteName = SiteContext.CurrentSiteName; // Existing account if (radSignIn.Checked) { // Authenticate user UserInfo ui = AuthenticationHelper.AuthenticateUser(txtUsername.Text.Trim(), txtPsswd1.Text, SiteContext.CurrentSiteName, false); if (ui == null) { lblError.Text = GetString("ShoppingCartCheckRegistration.LoginFailed"); lblError.Visible = true; return(false); } // Sign in customer with existing account AuthenticationHelper.AuthenticateUser(ui.UserName, false); // Registered user has already started shopping as anonymous user -> Drop his stored shopping cart ShoppingCartInfoProvider.DeleteShoppingCartInfo(ui.UserID, siteName); // Assign current user to the current shopping cart ShoppingCart.User = ui; // Save changes to database if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } // Log "login" activity ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activity = new ActivityUserLogin(ContactID, ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables); activity.Log(); LoadStep(true); // Return false to get to Edit customer page return(false); } // New registration else if (radNewReg.Checked) { txtEmail2.Text = txtEmail2.Text.Trim(); pnlCompanyAccount1.Visible = chkCorporateBody.Checked; string[] siteList = { siteName }; // If AssignToSites field set if (!String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) { siteList = ShoppingCartControl.AssignToSites.Split(';'); } // Check if user exists UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail2.Text); if (ui != null) { lblError.Visible = true; lblError.Text = GetString("ShoppingCartUserRegistration.ErrorUserExists"); return(false); } // Check all sites where user will be assigned if (!UserInfoProvider.IsEmailUnique(txtEmail2.Text.Trim(), siteList, 0)) { lblError.Visible = true; lblError.Text = GetString("UserInfo.EmailAlreadyExist"); return(false); } // Create new customer and user account and sign in // User ui = new UserInfo(); ui.UserName = txtEmail2.Text.Trim(); ui.Email = txtEmail2.Text.Trim(); ui.FirstName = txtFirstName1.Text.Trim(); ui.LastName = txtLastName1.Text.Trim(); ui.FullName = ui.FirstName + " " + ui.LastName; ui.Enabled = true; ui.UserIsGlobalAdministrator = false; ui.UserURLReferrer = MembershipContext.AuthenticatedUser.URLReferrer; ui.UserCampaign = AnalyticsHelper.Campaign; ui.UserSettings.UserRegistrationInfo.IPAddress = RequestContext.UserHostAddress; ui.UserSettings.UserRegistrationInfo.Agent = HttpContext.Current.Request.UserAgent; try { UserInfoProvider.SetPassword(ui, passStrength.Text); foreach (string site in siteList) { UserInfoProvider.AddUserToSite(ui.UserName, site); // Add user to roles if (ShoppingCartControl.AssignToRoles != "") { AssignUserToRoles(ui.UserName, ShoppingCartControl.AssignToRoles, site); } } // Log registered user AnalyticsHelper.LogRegisteredUser(siteName, ui); Activity activity = new ActivityRegistration(ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables); if (activity.Data != null) { activity.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); activity.Log(); } } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; return(false); } // Customer CustomerInfo ci = new CustomerInfo(); ci.CustomerFirstName = txtFirstName1.Text.Trim(); ci.CustomerLastName = txtLastName1.Text.Trim(); ci.CustomerEmail = txtEmail2.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody.Checked) { ci.CustomerCompany = txtCompany1.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } } ci.CustomerUserID = ui.UserID; ci.CustomerSiteID = 0; ci.CustomerEnabled = true; ci.CustomerCreated = DateTime.Now; CustomerInfoProvider.SetCustomerInfo(ci); // Track successful registration conversion string name = ShoppingCartControl.RegistrationTrackConversionName; ECommerceHelper.TrackRegistrationConversion(ShoppingCart.SiteName, name); // Log "customer registration" activity and update profile var activityCustomerRegistration = new ActivityCustomerRegistration(ci, MembershipContext.AuthenticatedUser, AnalyticsContext.ActivityEnvironmentVariables); if (activityCustomerRegistration.Data != null) { if (ContactID <= 0) { activityCustomerRegistration.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); } activityCustomerRegistration.Log(); } // Sign in if (ui.UserEnabled) { AuthenticationHelper.AuthenticateUser(ui.UserName, false); ShoppingCart.User = ui; ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activity = new ActivityUserLogin(ContactID, ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables); activity.Log(); } ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; // Send new registration notification email if (ShoppingCartControl.SendNewRegistrationNotificationToAddress != "") { SendRegistrationNotification(ui); } } // Anonymous customer else if (radAnonymous.Checked) { CustomerInfo ci = null; if (ShoppingCart.ShoppingCartCustomerID > 0) { // Update existing customer account ci = CustomerInfoProvider.GetCustomerInfo(ShoppingCart.ShoppingCartCustomerID); } if (ci == null) { // Create new customer account ci = new CustomerInfo(); } ci.CustomerFirstName = txtFirstName2.Text.Trim(); ci.CustomerLastName = txtLastName2.Text.Trim(); ci.CustomerEmail = txtEmail3.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody2.Checked) { ci.CustomerCompany = txtCompany2.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID2.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID2.Text.Trim(); } } ci.CustomerEnabled = true; ci.CustomerCreated = DateTime.Now; ci.CustomerSiteID = SiteContext.CurrentSiteID; CustomerInfoProvider.SetCustomerInfo(ci); // Log "customer registration" activity var activity = new ActivityCustomerRegistration(ci, MembershipContext.AuthenticatedUser, AnalyticsContext.ActivityEnvironmentVariables); if (activity.Data != null) { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(); activity.Data.ContactID = ContactID; activity.Log(); } // Assign customer to shoppingcart ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } else { return(false); } } else { // Save the customer data bool newCustomer = false; CustomerInfo ci = CustomerInfoProvider.GetCustomerInfoByUserID(ShoppingCartControl.UserInfo.UserID); if (ci == null) { ci = new CustomerInfo(); ci.CustomerUserID = ShoppingCartControl.UserInfo.UserID; ci.CustomerSiteID = 0; ci.CustomerEnabled = true; newCustomer = true; } // Old email address string oldEmail = ci.CustomerEmail.ToLowerCSafe(); ci.CustomerFirstName = txtEditFirst.Text.Trim(); ci.CustomerLastName = txtEditLast.Text.Trim(); ci.CustomerEmail = txtEditEmail.Text.Trim(); pnlCompanyAccount2.Visible = chkEditCorpBody.Checked; ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkEditCorpBody.Checked) { ci.CustomerCompany = txtEditCompany.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtEditOrgID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtEditTaxRegID.Text.Trim(); } } // Update customer data CustomerInfoProvider.SetCustomerInfo(ci); // Update corresponding user email when required if (oldEmail != ci.CustomerEmail.ToLowerCSafe()) { UserInfo user = UserInfoProvider.GetUserInfo(ci.CustomerUserID); if (user != null) { user.Email = ci.CustomerEmail; UserInfoProvider.SetUserInfo(user); } } // Log "customer registration" activity and update contact profile if (newCustomer) { var activity = new ActivityCustomerRegistration(ci, MembershipContext.AuthenticatedUser, AnalyticsContext.ActivityEnvironmentVariables); activity.Log(); } // Set the shopping cart customer ID ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } try { if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } ShoppingCart.InvalidateCalculations(); return(true); } catch { return(false); } }
/// <summary> /// Fires at btn search click. /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Arguments</param> protected void btnSearch_Click(object sender, EventArgs e) { string url = URLHelper.CurrentURL; // Remove pager query string url = URLHelper.RemoveParameterFromUrl(url, "page"); // Update search text parameter url = URLHelper.UpdateParameterInUrl(url, "searchtext", HttpUtility.UrlEncode(txtSearchFor.Text)); // Update search mode parameter url = URLHelper.RemoveParameterFromUrl(url, "searchmode"); if (this.ShowSearchMode) { url = URLHelper.AddParameterToUrl(url, "searchmode", drpSearchMode.SelectedValue); } else { url = URLHelper.AddParameterToUrl(url, "searchmode", SearchHelper.GetSearchModeString(SearchMode)); } // Add filter params to url foreach (string urlParam in FilterUrlParameters) { string[] urlParams = urlParam.Split('='); url = URLHelper.UpdateParameterInUrl(url, urlParams[0], urlParams[1]); } // Log "internal search" activity string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) && ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) && ActivitySettingsHelper.SearchEnabled(siteName)) { ActivityLogProvider.LogInternalSearchActivity(CMSContext.CurrentDocument, ModuleCommands.OnlineMarketingGetCurrentContactID(), CMSContext.CurrentSiteID, URLHelper.CurrentRelativePath, txtSearchFor.Text, CMSContext.Campaign); } // Redirect URLHelper.Redirect(url); }
/// <summary> /// Handles btnOkNew click, creates new user and joins it with liveid token. /// </summary> protected void btnOkNew_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(facebookUserId)) { string password = passStrength.Text; string currentSiteName = CMSContext.CurrentSiteName; // Validate entered values string errorMessage = new Validator().IsRegularExp(txtUserNameNew.Text, "^([a-zA-Z0-9_\\-\\.@]+)$", GetString("mem.facebook.fillcorrectusername")) .IsEmail(txtEmail.Text, GetString("mem.facebook.fillvalidemail")).Result; // If password is enabled to set, check it if (plcPasswordNew.Visible && (String.IsNullOrEmpty(errorMessage))) { if (String.IsNullOrEmpty(password)) { errorMessage = GetString("mem.facebook.specifyyourpass"); } else if (password != txtConfirmPassword.Text.Trim()) { errorMessage = GetString("webparts_membership_registrationform.passwordonotmatch"); } // Check policy if (!passStrength.IsValid()) { errorMessage = UserInfoProvider.GetPolicyViolationMessage(CMSContext.CurrentSiteName); } } // Check whether email is unique if it is required if ((String.IsNullOrEmpty(errorMessage)) && !UserInfoProvider.IsEmailUnique(txtEmail.Text.Trim(), currentSiteName, 0)) { errorMessage = GetString("UserInfo.EmailAlreadyExist"); } // Check reserved names if ((String.IsNullOrEmpty(errorMessage)) && UserInfoProvider.NameIsReserved(currentSiteName, txtUserNameNew.Text.Trim())) { errorMessage = GetString("Webparts_Membership_RegistrationForm.UserNameReserved").Replace("%%name%%", HTMLHelper.HTMLEncode(txtUserNameNew.Text.Trim())); } if (String.IsNullOrEmpty(errorMessage)) { // Check if user with given username already exists UserInfo ui = UserInfoProvider.GetUserInfo(txtUserNameNew.Text.Trim()); // User with given username is already registered if (ui != null) { plcError.Visible = true; lblError.Text = GetString("mem.openid.usernameregistered"); } else { // Register new user string error = this.DisplayMessage; ui = UserInfoProvider.AuthenticateFacebookConnectUser(facebookUserId, currentSiteName, true, false, ref error); this.DisplayMessage = error; if (ui != null) { // Set additional information ui.UserName = ui.UserNickName = txtUserNameNew.Text.Trim(); ui.Email = txtEmail.Text; // Set password if (plcPasswordNew.Visible) { UserInfoProvider.SetPassword(ui, password); // If user can choose password then is not considered external(external user can't login in common way) ui.IsExternal = false; } UserInfoProvider.SetUserInfo(ui); // Remove live user object from session, won't be needed SessionHelper.Remove(SESSION_NAME_USERDATA); // Send registration e-mails UserInfoProvider.SendRegistrationEmails(ui, this.ApprovalPage, password, true, this.SendWelcomeEmail); // Notify administrator bool requiresConfirmation = SettingsKeyProvider.GetBoolValue(currentSiteName + ".CMSRegistrationEmailConfirmation"); if (!requiresConfirmation && this.NotifyAdministrator && (this.FromAddress != String.Empty) && (this.ToAddress != String.Empty)) { UserInfoProvider.NotifyAdministrator(ui, this.FromAddress, this.ToAddress); } // Log registration into analytics UserInfoProvider.TrackUserRegistration(this.TrackConversionName, this.ConversionValue, currentSiteName, ui); // Log activity if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(currentSiteName) && ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) && ActivitySettingsHelper.UserRegistrationEnabled(currentSiteName)) { int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); ModuleCommands.OnlineMarketingUpdateContactFromExternalData(ui, contactId); TreeNode currDoc = CMSContext.CurrentDocument; ActivityLogProvider.LogRegistrationActivity(contactId, ui, URLHelper.CurrentRelativePath, (currDoc != null ? currDoc.NodeID : 0), currentSiteName, CMSContext.Campaign, (currDoc != null ? currDoc.DocumentCulture : null)); } // Set authentication cookie and redirect to page SetAuthCookieAndRedirect(ui); // Display error message if (!String.IsNullOrEmpty(this.DisplayMessage)) { lblInfo.Visible = true; lblInfo.Text = this.DisplayMessage; plcForm.Visible = false; } else { URLHelper.Redirect(ResolveUrl("~/Default.aspx")); } } } } else { lblError.Text = errorMessage; plcError.Visible = true; } } }
/// <summary> /// Save subscriber. /// </summary> /// <returns>Subscriber info object</returns> private SubscriberInfo SaveSubscriber() { string emailValue = null; int currentSiteId = SiteContext.CurrentSiteID; // Check if a subscriber exists first SubscriberInfo sb = null; if (AllowUserSubscribers && isAuthenticated) { // Try to get user subscriber sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, CurrentUser.UserID, currentSiteId); } else { EditingFormControl txtEmail = formElem.FieldEditingControls["SubscriberEmail"] as EditingFormControl; if (txtEmail != null) { emailValue = ValidationHelper.GetString(txtEmail.Value, String.Empty); } if (!string.IsNullOrEmpty(emailValue)) { // Try to get subscriber by email address sb = SubscriberInfoProvider.GetSubscriberInfo(emailValue, currentSiteId); } } if ((sb == null) || (chooseMode)) { // Create subscriber if (sb == null) { if (formElem.Visible) { int formSiteId = formElem.Data.GetValue("SubscriberSiteID").ToInteger(0); if (formSiteId == 0) { // Specify SiteID for the new subscriber formElem.Data.SetValue("SubscriberSiteID", currentSiteId); } // Save form with new subscriber data if (!formElem.Save()) { return(null); } // Get subscriber info from form sb = (SubscriberInfo)formElem.Info; } else { sb = new SubscriberInfo(); } } // Handle authenticated user if (AllowUserSubscribers && isAuthenticated) { // Get user info and copy first name, last name or full name to new subscriber // if these properties were not set UserInfo ui = UserInfoProvider.GetUserInfo(CurrentUser.UserID); if (ui != null) { if (!DataHelper.IsEmpty(ui.FirstName) && !DataHelper.IsEmpty(ui.LastName)) { if (string.IsNullOrEmpty(sb.SubscriberFirstName)) { sb.SubscriberFirstName = ui.FirstName; } if (string.IsNullOrEmpty(sb.SubscriberLastName)) { sb.SubscriberLastName = ui.LastName; } } else { if (string.IsNullOrEmpty(sb.SubscriberFirstName)) { sb.SubscriberFirstName = ui.FullName; } } // Full name consists of "user " and user full name sb.SubscriberFullName = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName); if (!string.IsNullOrEmpty(sb.SubscriberEmail) && string.IsNullOrEmpty(ui.Email)) { // Update user email if it was not set ui.Email = sb.SubscriberEmail; UserInfoProvider.SetUserInfo(ui); // Reset email for user subscriber sb.SubscriberEmail = null; } } else { return(null); } sb.SubscriberType = UserInfo.OBJECT_TYPE; sb.SubscriberRelatedID = ui.UserID; } // Work with non-authenticated user else { if (string.IsNullOrEmpty(sb.SubscriberFullName)) { // Fill full name if it was not set via the form sb.SubscriberFullName = (sb.SubscriberFirstName + " " + sb.SubscriberLastName).Trim(); } } // Set site ID sb.SubscriberSiteID = SiteContext.CurrentSiteID; // Insert or update subscriber info SubscriberInfoProvider.SetSubscriberInfo(sb); // Check subscriber limits if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { // Remove created subscriber and display error message SubscriberInfoProvider.DeleteSubscriberInfo(sb); lblError.Visible = true; lblError.Text = GetString("LicenseVersionCheck.Subscribers"); return(null); } } if (sb != null) { // Create membership between current contact and subscriber ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, ModuleCommands.OnlineMarketingGetCurrentContactID()); } // Return subscriber info object return(sb); }
/// <summary> /// Checks status of current user. /// </summary> protected void CheckStatus() { // Get current site name string siteName = CMSContext.CurrentSiteName; string error = null; // Check return URL string returnUrl = QueryHelper.GetString("returnurl", null); returnUrl = HttpUtility.UrlDecode(returnUrl); // Get current URL string currentUrl = URLHelper.CurrentURL; currentUrl = URLHelper.RemoveParameterFromUrl(currentUrl, "oauth_token"); currentUrl = URLHelper.RemoveParameterFromUrl(currentUrl, "oauth_verifier"); // Get LinkedIn response status switch (linkedInHelper.CheckStatus(RequireFirstName, RequireLastName, RequireBirthDate, null)) { // User is authenticated case CMSOpenIDHelper.RESPONSE_AUTHENTICATED: // LinkedIn profile Id not found = save new user if (UserInfoProvider.GetUserInfoByLinkedInID(linkedInHelper.MemberId) == null) { string additionalInfoPage = SettingsKeyProvider.GetStringValue(siteName + ".CMSRequiredLinkedInPage").Trim(); // No page set, user can be created if (String.IsNullOrEmpty(additionalInfoPage)) { // Register new user UserInfo ui = UserInfoProvider.AuthenticateLinkedInUser(linkedInHelper.MemberId, linkedInHelper.FirstName, linkedInHelper.LastName, siteName, true, true, ref error); // If user was successfuly created if (ui != null) { if (linkedInHelper.BirthDate != DateTimeHelper.ZERO_TIME) { ui.UserSettings.UserDateOfBirth = linkedInHelper.BirthDate; } UserInfoProvider.SetUserInfo(ui); // If user is enabled if (ui.Enabled) { // Create autentification cookie UserInfoProvider.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new string[] { "linkedinlogin" }); // Log activity if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) && ActivitySettingsHelper.UserLoginEnabled(siteName)) { int contactId = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); ActivityLogHelper.UpdateContactLastLogon(contactId); if (ActivitySettingsHelper.ActivitiesEnabledForThisUser(ui)) { TreeNode currentDoc = CMSContext.CurrentDocument; ActivityLogProvider.LogLoginActivity(contactId, ui, URLHelper.CurrentRelativePath, (currentDoc != null ? currentDoc.NodeID : 0), siteName, CMSContext.Campaign, (currentDoc != null ? currentDoc.DocumentCulture : null)); } } } // Notify administrator if (this.NotifyAdministrator && !String.IsNullOrEmpty(this.FromAddress) && !String.IsNullOrEmpty(this.ToAddress)) { UserInfoProvider.NotifyAdministrator(ui, this.FromAddress, this.ToAddress); } // Send registration e-mails // E-mail confirmation is not required as user already provided confirmation by successful login using OpenID UserInfoProvider.SendRegistrationEmails(ui, null, null, false, false); // Log registration into analytics UserInfoProvider.TrackUserRegistration(this.TrackConversionName, this.ConversionValue, siteName, ui); // Log activity if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) && ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) && ActivitySettingsHelper.UserRegistrationEnabled(siteName)) { int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); ModuleCommands.OnlineMarketingUpdateContactFromExternalData(ui, contactId); TreeNode currentDoc = CMSContext.CurrentDocument; ActivityLogProvider.LogRegistrationActivity(contactId, ui, URLHelper.CurrentRelativePath, currentDoc.NodeID, siteName, CMSContext.Campaign, currentDoc.DocumentCulture); } } // Redirect when authentication was succesfull if (String.IsNullOrEmpty(error)) { if (!String.IsNullOrEmpty(returnUrl)) { URLHelper.Redirect(URLHelper.GetAbsoluteUrl(returnUrl)); } else { URLHelper.Redirect(currentUrl); } } // Display error otherwise else { lblError.Text = error; lblError.Visible = true; } } // Additional information page is set else { // Store user object in session for additional use SessionHelper.SetValue(SESSION_NAME_USERDATA, linkedInHelper.LinkedInResponse); // Redirect to additional info page string targetURL = URLHelper.GetAbsoluteUrl(additionalInfoPage); if (!String.IsNullOrEmpty(returnUrl)) { // Add return URL to parameter targetURL = URLHelper.AddParameterToUrl(targetURL, "returnurl", HttpUtility.UrlEncode(returnUrl)); } URLHelper.Redirect(targetURL); } } // LinkedIn profile id is in DB else { // Login existing user UserInfo ui = UserInfoProvider.AuthenticateLinkedInUser(linkedInHelper.MemberId, linkedInHelper.FirstName, linkedInHelper.LastName, siteName, false, true, ref error); if ((ui != null) && (ui.Enabled)) { // Create autentification cookie UserInfoProvider.SetAuthCookieWithUserData(ui.UserName, true, Session.Timeout, new string[] { "linkedinlogin" }); // Log activity if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) && ActivitySettingsHelper.UserLoginEnabled(siteName)) { int contactId = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); ActivityLogHelper.UpdateContactLastLogon(contactId); if (ActivitySettingsHelper.ActivitiesEnabledForThisUser(ui)) { TreeNode currentDoc = CMSContext.CurrentDocument; ActivityLogProvider.LogLoginActivity(contactId, ui, URLHelper.CurrentRelativePath, currentDoc.NodeID, siteName, CMSContext.Campaign, currentDoc.DocumentCulture); } } // Redirect user if (!String.IsNullOrEmpty(returnUrl)) { URLHelper.Redirect(URLHelper.GetAbsoluteUrl(returnUrl)); } else { URLHelper.Redirect(currentUrl); } } // Display error which occured during authentication process else if (!String.IsNullOrEmpty(error)) { lblError.Text = error; lblError.Visible = true; } // Otherwise is user disabled else { lblError.Text = GetString("membership.userdisabled"); lblError.Visible = true; } } break; // No authentication, do nothing case LinkedInHelper.RESPONSE_NOTAUTHENTICATED: break; } }
private void usNewsletters_OnSelectionChanged(object sender, EventArgs e) { if (RaiseOnCheckPermissions("ManageSubscribers", this)) { if (StopProcessing) { return; } } // Get specified user if used instead of current user UserInfo ui = null; if (UserID > 0) { ui = UserInfoProvider.GetUserInfo(UserID); } else { ui = CMSContext.CurrentUser; } // Get specified site ID instead of current site ID int siteId = 0; if (SiteID > 0) { siteId = SiteID; } else { siteId = CMSContext.CurrentSiteID; } if ((sb == null) && (ui != null)) { // Create new subsciber (bind to existing user account) if ((!ui.IsPublic()) && (ValidationHelper.IsEmail(ui.Email) || ValidationHelper.IsEmail(ui.UserName))) { sb = new SubscriberInfo(); if (ui != null) { if (!string.IsNullOrEmpty(ui.FirstName) && !string.IsNullOrEmpty(ui.LastName)) { sb.SubscriberFirstName = ui.FirstName; sb.SubscriberLastName = ui.LastName; } else { sb.SubscriberFirstName = ui.FullName; } // Full name consists of "user " and user full name sb.SubscriberFullName = "User '" + ui.FullName + "'"; } sb.SubscriberSiteID = siteId; sb.SubscriberType = SiteObjectType.USER; sb.SubscriberRelatedID = ui.UserID; // Save subscriber to DB SubscriberInfoProvider.SetSubscriberInfo(sb); } } if (sb == null) { return; } // Create membership between current contact and subscriber ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, ModuleCommands.OnlineMarketingGetCurrentContactID()); // Remove old items int newsletterId = 0; string newValues = ValidationHelper.GetString(usNewsletters.Value, null); string items = DataHelper.GetNewItemsInList(newValues, currentValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { foreach (string item in newItems) { newsletterId = ValidationHelper.GetInteger(item, 0); // If subscriber is subscribed, unsubscribe him if (SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)) { SubscriberInfoProvider.Unsubscribe(sb.SubscriberID, newsletterId, SendConfirmationEmail); // Log activity LogActivity(ui, newsletterId, false); } } } } // Add new items items = DataHelper.GetNewItemsInList(currentValues, newValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { foreach (string item in newItems) { newsletterId = ValidationHelper.GetInteger(item, 0); // If subscriber is not subscribed, subscribe him if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)) { try { SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, SendConfirmationEmail); // Log activity LogActivity(ui, newsletterId, true); } catch { } } } } } // Display information about successful (un)subscription ShowChangesSaved(); }
/// <summary> /// OnAfterSave handler. /// </summary> private void editProfileForm_OnAfterSave(object sender, EventArgs e) { // Update current contact info var classInfo = DataClassInfoProvider.GetDataClassInfo(editProfileForm.ClassName); ContactInfoProvider.UpdateContactFromExternalData(editProfileForm.Info, classInfo.ClassContactOverwriteEnabled, ModuleCommands.OnlineMarketingGetCurrentContactID()); }
/// <summary> /// OK click handler (Proceed registration). /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (PortalContext.IsDesignMode(PortalContext.ViewMode) || (HideOnCurrentPage) || (!IsVisible)) { // Do not process } else { String siteName = SiteContext.CurrentSiteName; #region "Banned IPs" // Ban IP addresses which are blocked for registration if (!BannedIPInfoProvider.IsAllowed(siteName, BanControlEnum.Registration)) { ShowError(GetString("banip.ipisbannedregistration")); return; } #endregion #region "Check Email & password" string[] siteList = { siteName }; // If AssignToSites field set if (!String.IsNullOrEmpty(AssignToSites)) { siteList = AssignToSites.Split(';'); } // Check whether another user with this user name (which is effectively email) does not exist UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail.Text); SiteInfo si = SiteContext.CurrentSite; UserInfo siteui = UserInfoProvider.GetUserInfo(UserInfoProvider.EnsureSitePrefixUserName(txtEmail.Text, si)); if ((ui != null) || (siteui != null)) { ShowError(GetString("Webparts_Membership_RegistrationForm.UserAlreadyExists").Replace("%%name%%", HTMLHelper.HTMLEncode(txtEmail.Text))); return; } // Check whether password is same if (passStrength.Text != txtConfirmPassword.Text) { ShowError(GetString("Webparts_Membership_RegistrationForm.PassworDoNotMatch")); return; } if ((PasswordMinLength > 0) && (passStrength.Text.Length < PasswordMinLength)) { ShowError(String.Format(GetString("Webparts_Membership_RegistrationForm.PasswordMinLength"), PasswordMinLength)); return; } if (!passStrength.IsValid()) { ShowError(AuthenticationHelper.GetPolicyViolationMessage(SiteContext.CurrentSiteName)); return; } if ((!txtEmail.IsValid()) || (txtEmail.Text.Length > EMAIL_MAX_LENGTH)) { ShowError(String.Format(GetString("Webparts_Membership_RegistrationForm.EmailIsNotValid"), EMAIL_MAX_LENGTH)); return; } #endregion #region "Captcha" // Check if captcha is required and verify captcha text if (DisplayCaptcha && !scCaptcha.IsValid()) { // Display error message if catcha text is not valid ShowError(GetString("Webparts_Membership_RegistrationForm.captchaError")); return; } #endregion #region "User properties" var userEmail = txtEmail.Text.Trim(); ui = new UserInfo(); ui.PreferredCultureCode = ""; ui.Email = userEmail; ui.FirstName = txtFirstName.Text.Trim(); ui.LastName = txtLastName.Text.Trim(); ui.FullName = UserInfoProvider.GetFullName(ui.FirstName, String.Empty, ui.LastName); ui.MiddleName = ""; ui.UserMFRequired = chkUseMultiFactorAutentization.Checked; // User name as put by user (no site prefix included) var plainUserName = userEmail; ui.UserName = plainUserName; // Check if the given email can be used as user name if (!ValidationHelper.IsUserName(plainUserName)) { ShowError(String.Format(GetString("Webparts_Membership_RegistrationForm.UserNameNotValid"), HTMLHelper.HTMLEncode(plainUserName))); return; } // Ensure site prefixes if (UserInfoProvider.UserNameSitePrefixEnabled(siteName)) { ui.UserName = UserInfoProvider.EnsureSitePrefixUserName(plainUserName, si); } ui.Enabled = EnableUserAfterRegistration; ui.UserURLReferrer = CookieHelper.GetValue(CookieName.UrlReferrer); ui.UserCampaign = Service <ICampaignService> .Entry().CampaignCode; ui.SiteIndependentPrivilegeLevel = UserPrivilegeLevelEnum.None; ui.UserSettings.UserRegistrationInfo.IPAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; ui.UserSettings.UserRegistrationInfo.Agent = HttpContext.Current.Request.UserAgent; // Check whether confirmation is required bool requiresConfirmation = SettingsKeyInfoProvider.GetBoolValue(siteName + ".CMSRegistrationEmailConfirmation"); bool requiresAdminApprove = false; if (!requiresConfirmation) { // If confirmation is not required check whether administration approval is required requiresAdminApprove = SettingsKeyInfoProvider.GetBoolValue(siteName + ".CMSRegistrationAdministratorApproval"); if (requiresAdminApprove) { ui.Enabled = false; ui.UserSettings.UserWaitingForApproval = true; } } else { // EnableUserAfterRegistration is overridden by requiresConfirmation - user needs to be confirmed before enable ui.Enabled = false; } // Set user's starting alias path if (!String.IsNullOrEmpty(StartingAliasPath)) { ui.UserStartingAliasPath = MacroResolver.ResolveCurrentPath(StartingAliasPath); } #endregion #region "Reserved names" // Check for reserved user names like administrator, sysadmin, ... if (UserInfoProvider.NameIsReserved(siteName, plainUserName)) { ShowError(GetString("Webparts_Membership_RegistrationForm.UserNameReserved").Replace("%%name%%", HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(ui.UserName, true)))); return; } if (UserInfoProvider.NameIsReserved(siteName, ui.UserNickName)) { ShowError(GetString("Webparts_Membership_RegistrationForm.UserNameReserved").Replace("%%name%%", HTMLHelper.HTMLEncode(ui.UserNickName))); return; } #endregion #region "License limitations" string errorMessage = String.Empty; UserInfoProvider.CheckLicenseLimitation(ui, ref errorMessage); if (!String.IsNullOrEmpty(errorMessage)) { ShowError(errorMessage); return; } #endregion // Check whether email is unique if it is required if (!UserInfoProvider.IsEmailUnique(userEmail, siteList, 0)) { ShowError(GetString("UserInfo.EmailAlreadyExist")); return; } // Set password UserInfoProvider.SetPassword(ui, passStrength.Text); #region "Welcome Emails (confirmation, waiting for approval)" bool error = false; EmailTemplateInfo template = null; string emailSubject = null; // Send welcome message with username and password, with confirmation link, user must confirm registration if (requiresConfirmation) { template = EmailTemplateProvider.GetEmailTemplate("RegistrationConfirmation", siteName); emailSubject = EmailHelper.GetSubject(template, GetString("RegistrationForm.RegistrationConfirmationEmailSubject")); } // Send welcome message with username and password, with information that user must be approved by administrator else if (SendWelcomeEmail) { if (requiresAdminApprove) { template = EmailTemplateProvider.GetEmailTemplate("Membership.RegistrationWaitingForApproval", siteName); emailSubject = EmailHelper.GetSubject(template, GetString("RegistrationForm.RegistrationWaitingForApprovalSubject")); } // Send welcome message with username and password, user can logon directly else { template = EmailTemplateProvider.GetEmailTemplate("Membership.Registration", siteName); emailSubject = EmailHelper.GetSubject(template, GetString("RegistrationForm.RegistrationSubject")); } } if (template != null) { // Create relation between contact and user. This ensures that contact will be correctly recognized when user approves registration (if approval is required) int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); if (contactId > 0) { ModuleCommands.OnlineMarketingCreateRelation(ui.UserID, MembershipType.CMS_USER, contactId); } // Email message EmailMessage email = new EmailMessage(); email.EmailFormat = EmailFormatEnum.Default; email.Recipients = ui.Email; email.From = SettingsKeyInfoProvider.GetValue(siteName + ".CMSNoreplyEmailAddress"); email.Subject = emailSubject; try { var resolver = MembershipResolvers.GetMembershipRegistrationResolver(ui, AuthenticationHelper.GetRegistrationApprovalUrl(ApprovalPage, ui.UserGUID, siteName, NotifyAdministrator)); EmailSender.SendEmailWithTemplateText(siteName, email, template, resolver, true); } catch (Exception ex) { EventLogProvider.LogException("E", "RegistrationForm - SendEmail", ex); error = true; } } // If there was some error, user must be deleted if (error) { ShowError(GetString("RegistrationForm.UserWasNotCreated")); // Email was not send, user can't be approved - delete it UserInfoProvider.DeleteUser(ui); return; } #endregion #region "Administrator notification email" // Notify administrator if enabled and e-mail confirmation is not required if (!requiresConfirmation && NotifyAdministrator && (FromAddress != String.Empty) && (ToAddress != String.Empty)) { EmailTemplateInfo mEmailTemplate; if (SettingsKeyInfoProvider.GetBoolValue(siteName + ".CMSRegistrationAdministratorApproval")) { mEmailTemplate = EmailTemplateProvider.GetEmailTemplate("Registration.Approve", siteName); } else { mEmailTemplate = EmailTemplateProvider.GetEmailTemplate("Registration.New", siteName); } if (mEmailTemplate == null) { // Log missing e-mail template EventLogProvider.LogEvent(EventType.ERROR, "RegistrationForm", "GetEmailTemplate", eventUrl: RequestContext.RawURL); } else { EmailMessage message = new EmailMessage(); message.EmailFormat = EmailFormatEnum.Default; message.From = EmailHelper.GetSender(mEmailTemplate, FromAddress); message.Recipients = ToAddress; message.Subject = GetString("RegistrationForm.EmailSubject"); try { MacroResolver resolver = MembershipResolvers.GetRegistrationResolver(ui); EmailSender.SendEmailWithTemplateText(siteName, message, mEmailTemplate, resolver, false); } catch { EventLogProvider.LogEvent(EventType.ERROR, "Membership", "RegistrationEmail"); } } } #endregion #region "Web analytics" // Track successful registration conversion if (TrackConversionName != String.Empty) { if (AnalyticsHelper.AnalyticsEnabled(siteName) && !AnalyticsHelper.IsIPExcluded(siteName, RequestContext.UserHostAddress)) { // Log conversion HitLogProvider.LogConversions(siteName, LocalizationContext.PreferredCultureCode, TrackConversionName, 0, ConversionValue); } } // Log registered user if confirmation is not required if (!requiresConfirmation) { AnalyticsHelper.LogRegisteredUser(siteName, ui); } #endregion #region "On-line marketing - activity" // Log registered user if confirmation is not required if (!requiresConfirmation) { MembershipActivityLogger.LogRegistration(ui.UserName, DocumentContext.CurrentDocument); // Log login activity if (ui.Enabled) { MembershipActivityLogger.LogLogin(ui.UserName, DocumentContext.CurrentDocument); } } #endregion #region "Roles & authentication" string[] roleList = AssignRoles.Split(';'); foreach (string sn in siteList) { // Add new user to the current site UserInfoProvider.AddUserToSite(ui.UserName, sn); foreach (string roleName in roleList) { if (!String.IsNullOrEmpty(roleName)) { String s = roleName.StartsWith(".", StringComparison.Ordinal) ? "" : sn; // Add user to desired roles if (RoleInfoProvider.RoleExists(roleName, s)) { UserInfoProvider.AddUserToRole(ui.UserName, roleName, s); } } } } if (DisplayMessage.Trim() != String.Empty) { pnlForm.Visible = false; lblText.Visible = true; lblText.Text = DisplayMessage; } else { if (ui.Enabled) { AuthenticationHelper.AuthenticateUser(ui.UserName, true); } if (RedirectToURL != String.Empty) { URLHelper.Redirect(UrlResolver.ResolveUrl(RedirectToURL)); } else if (QueryHelper.GetString("ReturnURL", "") != String.Empty) { string url = QueryHelper.GetString("ReturnURL", ""); // Do url decode url = Server.UrlDecode(url); // Check that url is relative path or hash is ok if (url.StartsWith("~", StringComparison.Ordinal) || url.StartsWith("/", StringComparison.Ordinal) || QueryHelper.ValidateHash("hash", "aliaspath")) { URLHelper.Redirect(UrlResolver.ResolveUrl(url)); } // Absolute path with wrong hash else { URLHelper.Redirect(AdministrationUrlHelper.GetErrorPageUrl("dialogs.badhashtitle", "dialogs.badhashtext")); } } } #endregion lblError.Visible = false; } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string errorMessage = ""; string siteName = SiteContext.CurrentSiteName; if ((txtCustomerCompany.Text.Trim() == "" || !IsBusiness) && ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == ""))) { errorMessage = GetString("Customers_Edit.errorInsert"); } // At least company name has to be filled when company account is selected if (errorMessage == "" && IsBusiness) { errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text, GetString("customers_edit.errorCompany")).Result; } // Check the following items if complete company info is required for company account if (errorMessage == "" && ECommerceSettings.RequireCompanyInfo(siteName) && IsBusiness) { errorMessage = new Validator().NotEmpty(txtOraganizationID.Text, GetString("customers_edit.errorOrganizationID")) .NotEmpty(txtTaxRegistrationID.Text, GetString("customers_edit.errorTaxRegID")).Result; } if (errorMessage == "") { errorMessage = new Validator().IsEmail(txtCustomerEmail.Text.Trim(), GetString("customers_edit.erroremailformat"), true) .MatchesCondition(txtCustomerPhone.Text.Trim(), k => k.Length < 50, GetString("customers_edit.errorphoneformat")).Result; } plcCompanyInfo.Visible = IsBusiness; if (errorMessage == "") { // If customer doesn't already exist, create new one if (mCustomer == null) { mCustomer = new CustomerInfo(); mCustomer.CustomerUserID = MembershipContext.AuthenticatedUser.UserID; } mCustomer.CustomerEmail = txtCustomerEmail.Text.Trim(); mCustomer.CustomerLastName = txtCustomerLastName.Text.Trim(); mCustomer.CustomerPhone = txtCustomerPhone.Text.Trim(); mCustomer.CustomerFirstName = txtCustomerFirstName.Text.Trim(); mCustomer.CustomerCreated = DateTime.Now; if (IsBusiness) { mCustomer.CustomerCompany = txtCustomerCompany.Text.Trim(); mCustomer.CustomerOrganizationID = txtOraganizationID.Text.Trim(); mCustomer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } else { mCustomer.CustomerCompany = ""; mCustomer.CustomerOrganizationID = ""; mCustomer.CustomerTaxRegistrationID = ""; } // Update customer data CustomerInfoProvider.SetCustomerInfo(mCustomer); // Update corresponding contact data int currentContactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); ModuleCommands.OnlineMarketingCreateRelation(mCustomer.CustomerID, MembershipType.ECOMMERCE_CUSTOMER, currentContactId); ContactInfoProvider.UpdateContactFromExternalData( mCustomer, DataClassInfoProvider.GetDataClassInfo(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled, currentContactId); // Let others now that customer was created if (OnCustomerCrated != null) { OnCustomerCrated(); ShowChangesSaved(); } else { URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "saved", "1")); } } else { //Show error ShowError(errorMessage); } }