Create activation macro and pages

This commit is contained in:
Sebastiaan Janssen
2015-07-23 15:16:16 +02:00
parent 2cef3c44c7
commit ae37daffad
6 changed files with 162 additions and 2 deletions
+1
View File
@@ -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
+2
View File
@@ -1852,6 +1852,7 @@
<Content Include="Views\MacroPartials\Rss\Packages.cshtml" />
<Content Include="Views\MacroPartials\Rss\Topic.cshtml" />
<Content Include="Views\MacroPartials\Rss\Participated.cshtml" />
<Content Include="Views\MacroPartials\Members\Activate.cshtml" />
<None Include="Views\Partials\Forum\MemberBadge.cshtml" />
<Content Include="Views\Search\Search.aspx" />
<Content Include="Views\Web.config" />
@@ -4762,6 +4763,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\migrations\" />
<Folder Include="App_Plugins\" />
<Folder Include="css\img\Cached\" />
<Folder Include="umbraco\dashboard\air\" />
@@ -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)
{
<p>Member was not found.</p>
}
else
{
if (Roles.IsUserInRole(member.Username, "notactivated") == false)
{
if (member.IsApproved)
{
<p>You have already been activated.</p>
}
else
{
<p>Your account has been disabled.</p>
}
}
else
{
member.IsApproved = true;
memberService.Save(member);
memberService.DissociateRole(member.Id, "notactivated");
FormsAuthentication.SetAuthCookie(member.Username, true);
<h2>Thank you for signing up!</h2>
<div class="notice">
<p>You are now part of the friendliest community on the web. Start with one of the items below.</p>
<ul>
<li>Get help or offer your own assistance in the <a href="/forum" title="Forum">Forum</a></li>
<li>Find answers to your questions in the <a href="/documentation" title="Documentation">Documentation</a></li>
<li>Browse projects or create your own in <a href="/projects" title="Projects">Projects</a></li>
</ul>
<p>You can also rate and categorize content, topics, projects, and users. So get going!</p>
</div>
}
}
}
else
{
<p>Invalid activation code.</p>
}
}
<p>&nbsp;</p>
+88
View File
@@ -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", "<p>Thanks for signing up! <br />We\'ve sent you an email containing an activation link.</p><p>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.</p>");
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("<?UMBRACO_MACRO macroAlias=\"{0}\" />", macroAlias));
contentService.SaveAndPublishWithStatus(activatePage);
}
string[] lines = {""};
File.WriteAllLines(path, lines);
}
catch (Exception ex)
{
LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
}
}
}
}
+1
View File
@@ -286,6 +286,7 @@
<Compile Include="Examine\DocumentationIndexConfig.cs" />
<Compile Include="CustomHandlers\ForumIndexer.cs" />
<Compile Include="library.cs" />
<Compile Include="MigrationsHandler.cs" />
<Compile Include="Models\ProfileModel.cs" />
<Compile Include="Models\ProfileNotificationModel.cs" />
<Compile Include="Models\RegisterModel.cs" />
+17 -2
View File
@@ -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
{