|
|
@ -1,6 +1,7 @@
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
using MediaBrowser.Model.Users;
|
|
|
|
using MediaBrowser.Model.Users;
|
|
|
@ -172,12 +173,14 @@ namespace MediaBrowser.Api
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
|
|
|
|
private readonly ISessionManager _sessionMananger;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="UserService" /> class.
|
|
|
|
/// Initializes a new instance of the <see cref="UserService" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="xmlSerializer">The XML serializer.</param>
|
|
|
|
/// <param name="xmlSerializer">The XML serializer.</param>
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
|
|
|
|
|
|
|
/// <param name="dtoService">The dto service.</param>
|
|
|
|
/// <exception cref="System.ArgumentNullException">xmlSerializer</exception>
|
|
|
|
/// <exception cref="System.ArgumentNullException">xmlSerializer</exception>
|
|
|
|
public UserService(IXmlSerializer xmlSerializer, IUserManager userManager, IDtoService dtoService)
|
|
|
|
public UserService(IXmlSerializer xmlSerializer, IUserManager userManager, IDtoService dtoService)
|
|
|
|
: base()
|
|
|
|
: base()
|
|
|
@ -300,17 +303,15 @@ namespace MediaBrowser.Api
|
|
|
|
throw new ResourceNotFoundException("User not found");
|
|
|
|
throw new ResourceNotFoundException("User not found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var success = await _userManager.AuthenticateUser(user, request.Password).ConfigureAwait(false);
|
|
|
|
var auth = AuthorizationRequestFilterAttribute.GetAuthorization(Request);
|
|
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
var session = await _sessionMananger.AuthenticateNewSession(user, request.Password, auth.Client, auth.Version,
|
|
|
|
{
|
|
|
|
auth.DeviceId, auth.Device, Request.RemoteIp).ConfigureAwait(false);
|
|
|
|
// Unauthorized
|
|
|
|
|
|
|
|
throw new UnauthorizedAccessException("Invalid user or password entered.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = new AuthenticationResult
|
|
|
|
var result = new AuthenticationResult
|
|
|
|
{
|
|
|
|
{
|
|
|
|
User = _dtoService.GetUserDto(user)
|
|
|
|
User = _dtoService.GetUserDto(user),
|
|
|
|
|
|
|
|
SessionInfo = _dtoService.GetSessionInfoDto(session)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|