diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js index 7f8238a584..2c3be1949d 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js @@ -46,15 +46,15 @@ function entityResource($q, $http, umbRequestHelper) { /** * @ngdoc method - * @name umbraco.resources.contentResource#getByIds - * @methodOf umbraco.resources.contentResource + * @name umbraco.resources.entityResource#getByIds + * @methodOf umbraco.resources.entityResource * * @description - * Gets an array of content items, given a collection of ids + * Gets an array of entities, given a collection of ids * * ##usage *
-         * contentResource.getByIds( [1234,2526,28262])
+         * entityResource.getByIds( [1234,2526,28262])
          *    .then(function(contentArray) {
          *        var myDoc = contentArray; 
          *        alert('they are here!');
diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/user.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/user.resource.js
new file mode 100644
index 0000000000..91033cc3db
--- /dev/null
+++ b/src/Umbraco.Web.UI.Client/src/common/resources/user.resource.js
@@ -0,0 +1,75 @@
+/**
+    * @ngdoc service
+    * @name umbraco.resources.userResource
+    * @description Retrives user data from the server, cannot be used for authentication, for this, use the user.service
+    * 
+    *
+    **/
+function userResource($q, $http, umbRequestHelper) {
+
+    //the factory object returned
+    return {
+        
+        /**
+         * @ngdoc method
+         * @name umbraco.resources.userResource#getById
+         * @methodOf umbraco.resources.userResource
+         *
+         * @description
+         * Gets a user with a given id
+         *
+         * ##usage
+         * 
+         * userResource.getById(1234)
+         *    .then(function(ent) {
+         *        var myUser = ent; 
+         *        alert('im here!');
+         *    });
+         * 
+ * + * @param {Int} id id of user to return + * @returns {Promise} resourcePromise object containing the user. + * + */ + getById: function (id) { + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "userApiBaseUrl", + "GetById", + [{ id: id }])), + 'Failed to retreive user data for id ' + id); + }, + + /** + * @ngdoc method + * @name umbraco.resources.userResource#getAll + * @methodOf umbraco.resources.userResource + * + * @description + * Gets all users available on the system + * + * ##usage + *
+         * contentResource.getAll()
+         *    .then(function(userArray) {
+         *        var myUsers = userArray; 
+         *        alert('they are here!');
+         *    });
+         * 
+ * + * @returns {Promise} resourcePromise object containing the user array. + * + */ + getAll: function () { + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "userApiBaseUrl", + "GetAll")), + 'Failed to retreive all users'); + } + }; +} + +angular.module('umbraco.resources').factory('userResource', userResource); diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index 4a19f6bd9c..d3eb2a5d77 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -59,6 +59,23 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(HttpStatusCode.Unauthorized); } + /// + /// Returns all users + /// + /// + public UserDetail GetCurrentUser() + { + var attempt = UmbracoContext.Security.AuthorizeRequest(); + if (attempt == ValidateRequestAttempt.Success) + { + var user = Services.UserService.GetUserById(UmbracoContext.Security.GetUserId()); + return _userModelMapper.ToUserDetail(user); + } + + //return Unauthorized (401) because the user is not authorized right now + throw new HttpResponseException(HttpStatusCode.Unauthorized); + } + /// /// Logs a user in /// diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index 3750f440e0..b88e563ca1 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -14,7 +14,7 @@ using Umbraco.Core.Models; namespace Umbraco.Web.Editors { /// - /// The API controller used for using the list of sections + /// The API controller used for getting entity objects, basic name, icon, id representation of any umbraco object /// [PluginController("UmbracoApi")] public class EntityController : UmbracoAuthorizedJsonController diff --git a/src/Umbraco.Web/Editors/UserController.cs b/src/Umbraco.Web/Editors/UserController.cs new file mode 100644 index 0000000000..929ae46831 --- /dev/null +++ b/src/Umbraco.Web/Editors/UserController.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Umbraco.Web.Models.ContentEditing; +using Umbraco.Web.Models.Mapping; +using Umbraco.Web.Mvc; + +using legacyUser = umbraco.BusinessLogic.User; + + +namespace Umbraco.Web.Editors +{ + /// + /// Controller to back the User.Resource service, used for fetching user data when already authenticated. user.service is currently used for handling authentication + /// + [PluginController("UmbracoApi")] + public class UserController : UmbracoAuthorizedJsonController + { + private readonly UserModelMapper _userModelMapper; + public UserController() + : this(new UserModelMapper()) + { + } + internal UserController(UserModelMapper userModelMapper) + { + _userModelMapper = userModelMapper; + } + + public UserDetail GetById(int id) + { + var user = Services.UserService.GetUserById(id); + return _userModelMapper.ToUserDetail(user); + } + + //TODO: Change to a service / repo + public IEnumerable GetAll() + { + return legacyUser.getAll().Where(x => !x.Disabled).Select(x => new UserBasic() { Name = x.Name, UserId = x.Id }); + } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 57c102db95..268b6396ee 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -302,6 +302,7 @@ +