1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
2
3
3
4
using System . Linq ;
4
5
@@ -24,14 +25,14 @@ public class ContentController : UmbracoApiController
24
25
{
25
26
private readonly ZapierSettings Options ;
26
27
27
- private IContentService _contentService ;
28
+ private IContentTypeService _contentTypeService ;
28
29
29
30
private readonly IUserValidationService _userValidationService ;
30
31
31
32
#if NETCOREAPP
32
- public ContentController ( IOptions < ZapierSettings > options , IContentService contentService , IUserValidationService userValidationService )
33
+ public ContentController ( IOptions < ZapierSettings > options , IContentTypeService contentTypeService , IUserValidationService userValidationService )
33
34
#else
34
- public ContentController ( IContentService contentService , IUserValidationService userValidationService )
35
+ public ContentController ( IContentTypeService contentTypeService , IUserValidationService userValidationService )
35
36
#endif
36
37
{
37
38
#if NETCOREAPP
@@ -40,44 +41,45 @@ public ContentController(IContentService contentService, IUserValidationService
40
41
Options = new ZapierSettings ( ConfigurationManager . AppSettings ) ;
41
42
#endif
42
43
43
- _contentService = contentService ;
44
+ _contentTypeService = contentTypeService ;
44
45
45
46
_userValidationService = userValidationService ;
46
47
}
47
48
48
- public List < ContentTypeDto > Get ( )
49
+ public IEnumerable < ContentTypeDto > GetContentTypes ( )
49
50
{
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 >
51
+ string username = string . Empty ;
52
+ string password = string . Empty ;
53
+
54
+ #if NETCOREAPP
55
+ if ( Request . Headers . TryGetValue ( Constants . ZapierAppConfiguration . UsernameHeaderKey ,
56
+ out var usernameValues ) )
57
+ username = usernameValues . First ( ) ;
58
+ if ( Request . Headers . TryGetValue ( Constants . ZapierAppConfiguration . PasswordHeaderKey ,
59
+ out var passwordValues ) )
60
+ password = passwordValues . First ( ) ;
61
+ #else
62
+ if ( Request . Headers . TryGetValues ( Constants . ZapierAppConfiguration . UsernameHeaderKey ,
63
+ out var usernameValues ) )
64
+ username = usernameValues . First ( ) ;
65
+ if ( Request . Headers . TryGetValues ( Constants . ZapierAppConfiguration . PasswordHeaderKey ,
66
+ out var passwordValues ) )
67
+ password = passwordValues . First ( ) ;
68
+ #endif
69
+
70
+ if ( string . IsNullOrEmpty ( username ) || string . IsNullOrEmpty ( password ) ) return Enumerable . Empty < ContentTypeDto > ( ) ;
71
+
72
+ var isAuthorized = _userValidationService . Validate ( username , password , Options . UserGroup ) . GetAwaiter ( ) . GetResult ( ) ;
73
+ if ( ! isAuthorized ) return Enumerable . Empty < ContentTypeDto > ( ) ;
74
+
75
+ var contentTypes = _contentTypeService . GetAll ( ) ;
76
+
77
+ return contentTypes . Select ( p => new ContentTypeDto
78
78
{
79
- new ContentTypeDto { Id = root . Id , Name = root . Name }
80
- } ;
79
+ Id = p . Id ,
80
+ Alias = p . Alias ,
81
+ Name = p . Name
82
+ } ) ;
81
83
}
82
84
83
85
}
0 commit comments