New users.resource
This commit is contained in:
@@ -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
|
||||
* <pre>
|
||||
* contentResource.getByIds( [1234,2526,28262])
|
||||
* entityResource.getByIds( [1234,2526,28262])
|
||||
* .then(function(contentArray) {
|
||||
* var myDoc = contentArray;
|
||||
* alert('they are here!');
|
||||
|
||||
@@ -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
|
||||
* <pre>
|
||||
* userResource.getById(1234)
|
||||
* .then(function(ent) {
|
||||
* var myUser = ent;
|
||||
* alert('im here!');
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @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
|
||||
* <pre>
|
||||
* contentResource.getAll()
|
||||
* .then(function(userArray) {
|
||||
* var myUsers = userArray;
|
||||
* alert('they are here!');
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @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);
|
||||
@@ -59,6 +59,23 @@ namespace Umbraco.Web.Editors
|
||||
throw new HttpResponseException(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all users
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs a user in
|
||||
/// </summary>
|
||||
|
||||
@@ -14,7 +14,7 @@ using Umbraco.Core.Models;
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
[PluginController("UmbracoApi")]
|
||||
public class EntityController : UmbracoAuthorizedJsonController
|
||||
|
||||
44
src/Umbraco.Web/Editors/UserController.cs
Normal file
44
src/Umbraco.Web/Editors/UserController.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Controller to back the User.Resource service, used for fetching user data when already authenticated. user.service is currently used for handling authentication
|
||||
/// </summary>
|
||||
[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<UserBasic> GetAll()
|
||||
{
|
||||
return legacyUser.getAll().Where(x => !x.Disabled).Select(x => new UserBasic() { Name = x.Name, UserId = x.Id });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,6 +302,7 @@
|
||||
<Compile Include="Editors\DataTypeController.cs" />
|
||||
<Compile Include="Editors\DataTypeValidateAttribute.cs" />
|
||||
<Compile Include="Editors\EntityController.cs" />
|
||||
<Compile Include="Editors\UserController.cs" />
|
||||
<Compile Include="Models\ContentEditing\DataTypeDisplay.cs" />
|
||||
<Compile Include="Models\ContentEditing\DataTypeSave.cs" />
|
||||
<Compile Include="Models\ContentEditing\EntityBasic.cs" />
|
||||
|
||||
Reference in New Issue
Block a user