|
| 1 | +using System.Collections.Generic; |
| 2 | + |
| 3 | +using System.Linq; |
| 4 | + |
| 5 | +using Umbraco.Cms.Integrations.Automation.Zapier.Configuration; |
| 6 | +using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos; |
| 7 | +using Umbraco.Cms.Integrations.Automation.Zapier.Services; |
| 8 | + |
| 9 | +#if NETCOREAPP |
| 10 | +using Microsoft.Extensions.Options; |
| 11 | + |
| 12 | +using Umbraco.Cms.Web.Common.Controllers; |
| 13 | +using Umbraco.Cms.Core.Services; |
| 14 | +#else |
| 15 | +using System.Configuration; |
| 16 | + |
| 17 | +using Umbraco.Web.WebApi; |
| 18 | +using Umbraco.Core.Services; |
| 19 | +#endif |
| 20 | + |
| 21 | +namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers |
| 22 | +{ |
| 23 | + public class ContentController : UmbracoApiController |
| 24 | + { |
| 25 | + private readonly ZapierSettings Options; |
| 26 | + |
| 27 | + private IContentService _contentService; |
| 28 | + |
| 29 | + private readonly IUserValidationService _userValidationService; |
| 30 | + |
| 31 | +#if NETCOREAPP |
| 32 | + public ContentController(IOptions<ZapierSettings> options, IContentService contentService, IUserValidationService userValidationService) |
| 33 | +#else |
| 34 | + public ContentController(IContentService contentService, IUserValidationService userValidationService) |
| 35 | +#endif |
| 36 | + { |
| 37 | +#if NETCOREAPP |
| 38 | + Options = options.Value; |
| 39 | +#else |
| 40 | + Options = new ZapierSettings(ConfigurationManager.AppSettings); |
| 41 | +#endif |
| 42 | + |
| 43 | + _contentService = contentService; |
| 44 | + |
| 45 | + _userValidationService = userValidationService; |
| 46 | + } |
| 47 | + |
| 48 | + public List<ContentTypeDto> Get() |
| 49 | + { |
| 50 | +// string username = string.Empty; |
| 51 | +// string password = string.Empty; |
| 52 | + |
| 53 | +//#if NETCOREAPP |
| 54 | +// if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.UsernameHeaderKey, |
| 55 | +// out var usernameValues)) |
| 56 | +// username = usernameValues.First(); |
| 57 | +// if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.PasswordHeaderKey, |
| 58 | +// out var passwordValues)) |
| 59 | +// password = passwordValues.First(); |
| 60 | +//#else |
| 61 | +// if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.UsernameHeaderKey, |
| 62 | +// out var usernameValues)) |
| 63 | +// username = usernameValues.First(); |
| 64 | +// if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.PasswordHeaderKey, |
| 65 | +// out var passwordValues)) |
| 66 | +// password = passwordValues.First(); |
| 67 | +//#endif |
| 68 | + |
| 69 | +// if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return null; |
| 70 | + |
| 71 | +// var isAuthorized = _userValidationService.Validate(username, password, Options.UserGroup).GetAwaiter().GetResult(); |
| 72 | +// if (!isAuthorized) return null; |
| 73 | + |
| 74 | + var root = _contentService.GetRootContent().Where(p => p.Published) |
| 75 | + .OrderByDescending(p => p.PublishDate).FirstOrDefault(); |
| 76 | + |
| 77 | + return new List<ContentTypeDto> |
| 78 | + { |
| 79 | + new ContentTypeDto { Id = root.Id, Name = root.Name} |
| 80 | + }; |
| 81 | + } |
| 82 | + |
| 83 | + } |
| 84 | +} |
0 commit comments