Skip to content

Commit 407d5d8

Browse files
committed
Zapier workflow integration
1 parent 78687ba commit 407d5d8

File tree

12 files changed

+254
-2
lines changed

12 files changed

+254
-2
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Ignore Visual Studio temporary files, build results, and
1+
## Ignore Visual Studio temporary files, build results, and
22
## files generated by popular Visual Studio add-ons.
33
##
44
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
@@ -397,4 +397,6 @@ src/Umbraco.Forms.Integrations.TestSite/scripts
397397
src/Umbraco.Forms.Integrations.TestSite/Umbraco
398398
src/Umbraco.Forms.Integrations.TestSite/Views
399399
*.zip
400-
appsettings.Local.json
400+
appsettings.Local.json
401+
src/Umbraco.Forms.Integrations.Automation.Zapier/app.config
402+
src/Umbraco.Forms.Integrations.Automation.Zapier/packages.config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div ng-controller="Umbraco.Forms.Integrations.Automation.Zapier.MainController as vm">
2+
<p>TEST</p>
3+
<umb-button type="button" action="vm.addMapping()" label="Add mapping"></umb-button>
4+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function mainController($scope, $routeParams, pickerResource, notificationsService) {
2+
3+
var vm = this;
4+
5+
var formId = $routeParams.id;
6+
7+
if (formId !== -1) {
8+
getFormFields(formId);
9+
} else {
10+
notificationsService.warning("Cannot retrieve form details");
11+
}
12+
13+
function getFormFields(formId) {
14+
pickerResource.getAllFields(formId).then(function(response) {
15+
});
16+
}
17+
18+
}
19+
20+
angular.module("umbraco")
21+
.controller("Umbraco.Forms.Integrations.Automation.Zapier.MainController", mainController)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"javascript": [
3+
"~/App_Plugins/UmbracoForms.Integrations/Automation/Zapier/main.controller.js"
4+
]
5+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Linq;
2+
using System.Web.Http;
3+
4+
using Umbraco.Core.Services;
5+
using Umbraco.Forms.Integrations.Automation.Zapier.Models;
6+
using Umbraco.Web.WebApi;
7+
8+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers
9+
{
10+
public class AuthController : UmbracoApiController
11+
{
12+
[HttpPost]
13+
public bool ValidateUser([FromBody] UserModel userModel)
14+
{
15+
var isUserValid = Security.ValidateBackOfficeCredentials(userModel.Username, userModel.Password);
16+
if (!isUserValid) return false;
17+
18+
IUserService userService = Services.UserService;
19+
20+
var user = userService.GetByUsername(userModel.Username);
21+
22+
return user != null && user.Groups.Any(p => p.Alias == "admin");
23+
}
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Models
4+
{
5+
public class Mapping
6+
{
7+
[JsonProperty("alias")]
8+
public string Alias { get; set; }
9+
10+
[JsonProperty("value")]
11+
public string Value { get; set; }
12+
13+
[JsonProperty("staticValue")]
14+
public string StaticValue { get; set; }
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+

2+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Models
3+
{
4+
public class UserModel
5+
{
6+
public string Username { get; set; }
7+
8+
public string Password { get; set; }
9+
}
10+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net472</TargetFramework>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<PackageId>Umbraco.Forms.Integrations.Automation.Zapier</PackageId>
9+
<Title>Umbraco Forms Integrations: Automation - Zapier</Title>
10+
<Description>An extension for Umbraco Forms to add support for triggering zaps.</Description>
11+
<PackageIconUrl></PackageIconUrl>
12+
<PackageProjectUrl>https://github.com/umbraco/Umbraco.Forms.Integrations</PackageProjectUrl>
13+
<RepositoryUrl>https://github.com/umbraco/Umbraco.Forms.Integrations</RepositoryUrl>
14+
<Version>1.0.0</Version>
15+
<Authors>Umbraco HQ</Authors>
16+
<Company>Umbraco</Company>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="UmbracoCms.Web" Version="8.1.0" />
21+
<PackageReference Include="UmbracoCms.Core" Version="8.1.0" />
22+
<PackageReference Include="UmbracoForms.Core" Version="8.11.0" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<Content Include="App_Plugins\UmbracoForms.Integrations\Automation\Zapier\**\*.*">
27+
<Pack>true</Pack>
28+
<PackagePath>App_Plugins\UmbracoForms.Integrations\Automation\Zapier\</PackagePath>
29+
</Content>
30+
</ItemGroup>
31+
32+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.RegularExpressions;
4+
5+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Validators
6+
{
7+
public class WebHookValidator : WorkflowBaseValidator<string>
8+
{
9+
private const string Pattern =
10+
"((http|https)://)(www.)?[a-zA-Z0-9@:%._\\+~#?&//=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*)";
11+
12+
public override bool IsValid(string input, ref List<Exception> exceptions)
13+
{
14+
if (string.IsNullOrEmpty(input))
15+
{
16+
exceptions.Add(new Exception("URL is required"));
17+
return false;
18+
}
19+
20+
var regex = new Regex(Pattern);
21+
22+
var result = regex.IsMatch(input);
23+
24+
if(!result)
25+
exceptions.Add(new Exception("Invalid URL format"));
26+
27+
return result;
28+
}
29+
}
30+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Validators
5+
{
6+
public abstract class WorkflowBaseValidator<T>
7+
where T : class
8+
{
9+
public abstract bool IsValid(T input, ref List<Exception> exceptions);
10+
}
11+
}

0 commit comments

Comments
 (0)