Member was not found.
+ } + else + { + if (Roles.IsUserInRole(member.Username, "notactivated") == false) + { + if (member.IsApproved) + { +You have already been activated.
+ } + else + { +Your account has been disabled.
+ } + } + else + { + member.IsApproved = true; + memberService.Save(member); + memberService.DissociateRole(member.Id, "notactivated"); + FormsAuthentication.SetAuthCookie(member.Username, true); + +You are now part of the friendliest community on the web. Start with one of the items below.
+You can also rate and categorize content, topics, projects, and users. So get going!
+Invalid activation code.
+ } +} +\ No newline at end of file diff --git a/our.umbraco.org/MigrationsHandler.cs b/our.umbraco.org/MigrationsHandler.cs new file mode 100644 index 00000000..e636d375 --- /dev/null +++ b/our.umbraco.org/MigrationsHandler.cs @@ -0,0 +1,88 @@ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Web.Hosting; +using umbraco.cms.businesslogic.macro; +using Umbraco.Core; +using Umbraco.Core.Logging; +using Umbraco.Core.Models; +using Umbraco.Web; +using File = System.IO.File; + +namespace our +{ + public class MigrationsHandler : ApplicationEventHandler + { + private const string MigrationMarkersPath = "~/App_Data/migrations/"; + + protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + EnsureMigrationsMarkerPathExists(); + MemberActivationMigration(); + } + + private void EnsureMigrationsMarkerPathExists() + { + var path = HostingEnvironment.MapPath(MigrationMarkersPath); + if (Directory.Exists(path) == false) + Directory.CreateDirectory(path); + } + + private void MemberActivationMigration() + { + var migrationName = MethodBase.GetCurrentMethod().Name; + + try + { + var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); + if (File.Exists(path)) + return; + + var macroService = UmbracoContext.Current.Application.Services.MacroService; + var macroAlias = "MembersActivate"; + if (macroService.GetByAlias(macroAlias) == null) + { + // Run migration + + var macro = new Macro + { + Name = "[Members] Activate", + Alias = macroAlias, + ScriptingFile = "~/Views/MacroPartials/Members/Activate.cshtml", + UseInEditor = true + }; + macro.Save(); + } + + var contentService = UmbracoContext.Current.Application.Services.ContentService; + var rootNode = contentService.GetRootContent().First(); + + var memberNode = rootNode.Children().FirstOrDefault(x => x.Name == "Member"); + + var pendingActivationPageName = "Pending activation"; + if (memberNode != null && memberNode.Children().Any(x => x.Name == pendingActivationPageName) == false) + { + var pendingActivationPage = contentService.CreateContent(pendingActivationPageName, memberNode.Id, "Textpage"); + pendingActivationPage.SetValue("bodyText", "
Thanks for signing up!
We\'ve sent you an email containing an activation link.
To be able to continue you need to click the link in that email. If you didn\'t get any mail from us, make sure to check your spam/junkmail folder for mail from robot@umbraco.org.
"); + contentService.SaveAndPublishWithStatus(pendingActivationPage); + } + + var activatePageName = "Activate"; + if (memberNode != null && memberNode.Children().Any(x => x.Name == activatePageName) == false) + { + var activatePage = contentService.CreateContent(activatePageName, memberNode.Id, "Textpage"); + activatePage.SetValue("bodyText", string.Format("", macroAlias)); + contentService.SaveAndPublishWithStatus(activatePage); + } + + string[] lines = {""}; + File.WriteAllLines(path, lines); + } + catch (Exception ex) + { + LogHelper.Error