Skip to content

Instantly share code, notes, and snippets.

@rbaty-barr
Last active October 17, 2017 14:20
Show Gist options
  • Save rbaty-barr/15ac0bd5d4613738bff4f307126a2200 to your computer and use it in GitHub Desktop.
Save rbaty-barr/15ac0bd5d4613738bff4f307126a2200 to your computer and use it in GitHub Desktop.
indexing the grid
contentGrid:{
"name":"Main Layout",
"sections":[
{
"grid":12,
"rows":[
{
"name":"Single Cell Row",
"areas":[
{
"grid":12,
"allowAll":false,
"allowed":[
"rte",
"media",
"embed",
"headline",
"quote",
"hideShowItem",
"calloutBox"
],
"hasConfig":false,
"controls":[
{
"value":"<p>just looking to index data in here - oh, and can we pump some email in too?</p>",
"editor":{
"alias":"rte"
},
"active":false
},
{
"value":[
{
"hideShowTitle":{
"value":"Can Pigs Fly",
"dataTypeGuid":"0cc0eba1-9960-42c9-bf9b-60e150b429ae",
"editorAlias":"hideShowTitle",
"editorName":"Hide Show Title"
},
"hideShowBody":{
"value":"<p>What does a monkey look like?</p>",
"dataTypeGuid":"ca90c950-0aff-4e72-b976-a30b1ac57dad",
"editorAlias":"hideShowBody",
"editorName":"Hide Show Body"
}
}
],
"editor":{
"alias":"hideShowItem"
},
"active":true,
"guid":"a00bac0b-39b6-1fe4-e982-45f58852449a"
}
]
}
],
"hasConfig":false,
"id":"483184c0-5474-5b70-0c9f-9399757465f5"
}
]
}
]
}
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using Examine;
using Examine.Providers;
using Skybrud.Umbraco.GridData;
using Skybrud.Umbraco.GridData.Values;
using Umbraco.Core.Logging;
using System.Net;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Web;
using Umbraco.Web.Mvc;
using System.Linq;
using System.Net.Mail;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace csacBAportal.App_Code
{
public class Startup : ApplicationEventHandler {
private static ExamineIndexer _examineIndexer;
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) {
// Register events for Examine
_examineIndexer = new ExamineIndexer();
}
}
public class ExamineIndexer {
public ExamineIndexer() {
BaseIndexProvider externalIndexer = ExamineManager.Instance.IndexProviderCollection["baIndexer"];
externalIndexer.GatheringNodeData += OnExamineGatheringNodeData;
}
private void OnExamineGatheringNodeData(object sender, IndexingNodeDataEventArgs e) {
try {
string nodeTypeAlias = e.Fields["nodeTypeAlias"];
LogHelper.Info<ExamineIndexer>("Gathering node data for node #" + e.NodeId + " (type: " + nodeTypeAlias + ")");
// if (nodeTypeAlias == "Home" || nodeTypeAlias == "LandingPage" || nodeTypeAlias == "TextPage" || nodeTypeAlias == "BlogPost") {
string value;
if (e.Fields.TryGetValue("contentGrid", out value)) {
LogHelper.Info<ExamineIndexer>("BINGO!! Node has \"content\" value\"");
GridDataModel grid = GridDataModel.Deserialize(e.Fields["contentGrid"]);
StringBuilder combined = new StringBuilder();
foreach (GridControl ctrl in grid.GetAllControls()) {
switch (ctrl.Editor.Alias) {
case "rte": {
// Get the HTML value
string html = ctrl.GetValue<GridControlRichTextValue>().Value;
// Strip any HTML tags so we only have text
string text = Regex.Replace(html, "<.*?>", "");
// Extra decoding may be necessary
text = HttpUtility.HtmlDecode(text);
// Now append the text
combined.AppendLine(text);
break;
}
case "hideShowItem" : {
LogHelper.Info<ExamineIndexer>("found a hide show item");
GridDataModel subGrid = GridDataModel.Deserialize(e.Fields["contentGrid"].["hideShowItem"]);
break;
}
case "media": {
GridControlMediaValue media = ctrl.GetValue<GridControlMediaValue>();
combined.AppendLine(media.Caption);
break;
}
case "headline":
case "quote": {
combined.AppendLine(ctrl.GetValue<GridControlTextValue>().Value);
break;
}
}
}
e.Fields["content"] = combined.ToString();
} else {
// LogHelper.Info<ExamineIndexer>("Node has no \"content\" value\"");
}
// }
} catch (Exception ex) {
LogHelper.Error<ExamineIndexer>("MAYDAY! MAYDAY! MAYDAY!", ex);
}
}
}
public class resetEmailSurfaceController : SurfaceController
{
[HttpPost]
public ActionResult sendReset()
{
string host = System.Web.HttpContext.Current.Request.Url.Host;
string email = Request["email"];
var theMember = Members.GetByEmail(email);
var resultText = "sending...";
Guid theKey = Guid.NewGuid();
if(theMember != null){
var memberService = ApplicationContext.Current.Services.MemberService;
var member = memberService.GetByEmail(email);
member.SetValue("resetPasswordKey", theKey.ToString());
memberService.Save(member);
//var member = Services.MemberService.GetByusername(theMember.LoginName);
//member.SetValue("resetPasswordKey", theKey);
MailMessage message = new MailMessage();
string fromEmail = "password-reset@carpenterssw.org";
message.From = new MailAddress(fromEmail);
message.To.Add(new MailAddress(@email));
message.Bcc.Add(new MailAddress("rbaty-barr@segalco.com"));
message.Subject = "Password reset request form the Carpenters BA Portal";
message.Body = "<table border='0' cellpadding='20' cellspacing='0' width='600' align='center' style='font-family:Helvetica,Arial,sans-serif;'><tr><td>";
message.Body = message.Body + "<h1>Password Reset Details</h1>";
message.Body = message.Body + "<p>You have requested a password reset for the Southwest Carpenters BA Portal. To reset yoru password, please use the following link.</p>";
message.Body = message.Body + "<p><a href='http://" + host + "/reset?id="+ @theKey +"'>Password reset link.</a></p>";
message.Body = message.Body + "</td></tr></table>";
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
NetworkCredential basicCredential = new NetworkCredential("apikey", "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");
client.Host = "smtp.sendgrid.net";
client.UseDefaultCredentials = false;
client.Credentials = basicCredential;
//client.EnableSsl = true;
client.Port=587;
client.Send(message);
resultText = "success";
} else {
resultText = "No Member Exists";
}
return Content(resultText);
}
[HttpPost]
public ActionResult resetPass()
{
string email = Request["email"];
string guid = Request["guid"];
string newPass = Request["newPass"];
var resultText = "resetting...";
var theMember = Members.GetByEmail(email);
if(theMember != null && email != null && guid != null && newPass != null){
var memberService = ApplicationContext.Current.Services.MemberService;
var member = memberService.GetByEmail(email);
if(member.GetValue<string>("resetPasswordKey") == guid){
member.SetValue("resetPasswordKey", "");
memberService.SavePassword(member, newPass);
memberService.Save(member);
resultText = "0";
} else {
resultText = "1";
}
} else {
resultText ="2";
}
return Content(resultText);
}
}
}
@rbaty-barr
Copy link
Author

here is the json:
contentGrid: {
"name": "Main Layout",
"sections": [
{
"grid": 12,
"rows": [
{
"name": "Single Cell Row",
"areas": [
{
"grid": 12,
"allowAll": false,
"allowed": [
"rte",
"media",
"embed",
"headline",
"quote",
"hideShowItem",
"calloutBox"
],
"hasConfig": false,
"controls": [
{
"value": "

just looking to index data in here - oh, and can we pump some email in too?

",
"editor": {
"alias": "rte"
},
"active": false
},
{
"value": [
{
"hideShowTitle": {
"value": "Can Pigs Fly",
"dataTypeGuid": "0cc0eba1-9960-42c9-bf9b-60e150b429ae",
"editorAlias": "hideShowTitle",
"editorName": "Hide Show Title"
},
"hideShowBody": {
"value": "

What does a monkey look like?

",
"dataTypeGuid": "ca90c950-0aff-4e72-b976-a30b1ac57dad",
"editorAlias": "hideShowBody",
"editorName": "Hide Show Body"
}
}
],
"editor": {
"alias": "hideShowItem"
},
"active": true,
"guid": "a00bac0b-39b6-1fe4-e982-45f58852449a"
}
]
}
],
"hasConfig": false,
"id": "483184c0-5474-5b70-0c9f-9399757465f5"
}
]
}
]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment