diff --git a/.gitignore b/.gitignore index 93460bb0..327d1a16 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,4 @@ OurUmbraco.Site/[Ww]eb.config OurUmbraco.Site/[Aa]ssets/css/style.min.css OurUmbraco.Site/[Aa]ssets/js/app.min.js .vs/ +OurUmbraco.Site/App_Data/migrations/*.txt diff --git a/OurUmbraco.Site/OurUmbraco.Site.csproj b/OurUmbraco.Site/OurUmbraco.Site.csproj index 77de4a93..363623dd 100644 --- a/OurUmbraco.Site/OurUmbraco.Site.csproj +++ b/OurUmbraco.Site/OurUmbraco.Site.csproj @@ -1852,6 +1852,7 @@ + @@ -4762,6 +4763,7 @@ + diff --git a/OurUmbraco.Site/Views/MacroPartials/Members/Activate.cshtml b/OurUmbraco.Site/Views/MacroPartials/Members/Activate.cshtml new file mode 100644 index 00000000..2b17ede2 --- /dev/null +++ b/OurUmbraco.Site/Views/MacroPartials/Members/Activate.cshtml @@ -0,0 +1,53 @@ +@using uForum.Extensions +@inherits Umbraco.Web.Macros.PartialViewMacroPage +@{ + var memberGuid = Request.QueryString["id"]; + + if (string.IsNullOrWhiteSpace(memberGuid) == false) + { + var memberService = UmbracoContext.Current.Application.Services.MemberService; + var member = memberService.GetByKey(new Guid(memberGuid)); + + if (member == null) + { +

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); + +

Thank you for signing up!

+
+

You are now part of the friendliest community on the web. Start with one of the items below.

+
    +
  • Get help or offer your own assistance in the Forum
  • +
  • Find answers to your questions in the Documentation
  • +
  • Browse projects or create your own in Projects
  • +
+

You can also rate and categorize content, topics, projects, and users. So get going!

+
+ } + } + } + else + { +

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(string.Format("Migration: '{0}' failed", migrationName), ex); + } + } + } +} diff --git a/our.umbraco.org/our.umbraco.org.csproj b/our.umbraco.org/our.umbraco.org.csproj index 6a5e235c..391d2b0a 100644 --- a/our.umbraco.org/our.umbraco.org.csproj +++ b/our.umbraco.org/our.umbraco.org.csproj @@ -286,6 +286,7 @@ + diff --git a/our.umbraco.org/usercontrols/Signup.ascx.cs b/our.umbraco.org/usercontrols/Signup.ascx.cs index c8eaa2db..9c0f6d4c 100644 --- a/our.umbraco.org/usercontrols/Signup.ascx.cs +++ b/our.umbraco.org/usercontrols/Signup.ascx.cs @@ -1,13 +1,15 @@ using System; using System.Configuration; +using System.Linq; using System.Net; using System.Web.Hosting; using umbraco; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Models; -using Umbraco.Web.UI.Controls; +using Umbraco.Web; using File = System.IO.File; +using UmbracoUserControl = Umbraco.Web.UI.Controls.UmbracoUserControl; namespace our.usercontrols { @@ -145,8 +147,21 @@ namespace our.usercontrols uForum.Library.Utils.SendActivationMail(member); uForum.Library.Utils.SendMemberSignupMail(member); } + memberService.AssignRole(member.Id, "notactivated"); - //Response.Redirect(library.NiceUrl(NextPage)); + var redirectPage = "/"; + var contentService = UmbracoContext.Current.Application.Services.ContentService; + var rootNode = contentService.GetRootContent().First(); + + var memberNode = rootNode.Children().FirstOrDefault(x => x.Name == "Member"); + if (memberNode != null) + { + var pendingActivationPage = memberNode.Children().FirstOrDefault(x => x.Name == "Pending activation"); + if (pendingActivationPage != null) + redirectPage = library.NiceUrl(pendingActivationPage.Id); + } + + Response.Redirect(redirectPage); } else {