Skip to content

Commit 01c3f5a

Browse files
committed
Zapier authentication controller.
1 parent 33a5e18 commit 01c3f5a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Configuration;
2+
using System.Linq;
3+
using System.Web.Http;
4+
5+
using Umbraco.Cms.Integrations.Automation.Zapier.Models;
6+
using Umbraco.Core.Services;
7+
using Umbraco.Web.WebApi;
8+
9+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
10+
{
11+
public class AuthController : UmbracoApiController
12+
{
13+
private const string UmbracoCmsIntegrationsAutomationZapierUserGroup = "Umbraco.Cms.Integrations.Automation.Zapier.UserGroup";
14+
15+
[HttpPost]
16+
public bool ValidateUser([FromBody] UserModel userModel)
17+
{
18+
var isUserValid = Security.ValidateBackOfficeCredentials(userModel.Username, userModel.Password);
19+
if (!isUserValid) return false;
20+
21+
var userGroup = ConfigurationManager.AppSettings[UmbracoCmsIntegrationsAutomationZapierUserGroup];
22+
if (!string.IsNullOrEmpty(userGroup))
23+
{
24+
IUserService userService = Services.UserService;
25+
26+
var user = userService.GetByUsername(userModel.Username);
27+
28+
var isValid = user != null && user.Groups.Any(p => p.Name == userGroup);
29+
30+
return isValid;
31+
}
32+
33+
return true;
34+
}
35+
}
36+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+

2+
namespace Umbraco.Cms.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+
}

0 commit comments

Comments
 (0)