2012-09-07 16:17:39 +00:00
|
|
|
|
using MediaBrowser.Common.Net.Handlers;
|
2012-09-06 18:38:29 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
2012-09-08 15:10:26 +00:00
|
|
|
|
using MediaBrowser.Model.Authentication;
|
2012-09-06 18:38:29 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2012-09-08 14:52:13 +00:00
|
|
|
|
using System.ComponentModel.Composition;
|
|
|
|
|
using System.Net;
|
2012-09-07 16:17:39 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2012-09-06 18:38:29 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.HttpHandlers
|
|
|
|
|
{
|
2012-09-08 14:52:13 +00:00
|
|
|
|
[Export(typeof(BaseHandler))]
|
2012-09-06 18:38:29 +00:00
|
|
|
|
class UserAuthenticationHandler : BaseSerializationHandler<AuthenticationResult>
|
|
|
|
|
{
|
2012-09-08 14:52:13 +00:00
|
|
|
|
public override bool HandlesRequest(HttpListenerRequest request)
|
|
|
|
|
{
|
|
|
|
|
return ApiService.IsApiUrlMatch("UserAuthentication", request);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-06 18:38:29 +00:00
|
|
|
|
protected override async Task<AuthenticationResult> GetObjectToSerialize()
|
|
|
|
|
{
|
2012-09-07 16:17:39 +00:00
|
|
|
|
string userId = await GetFormValue("userid").ConfigureAwait(false);
|
|
|
|
|
User user = ApiService.GetUserById(userId, false);
|
2012-09-06 18:38:29 +00:00
|
|
|
|
|
|
|
|
|
string password = await GetFormValue("password").ConfigureAwait(false);
|
|
|
|
|
|
2012-09-07 16:17:39 +00:00
|
|
|
|
return Kernel.Instance.AuthenticateUser(user, password);
|
2012-09-06 18:38:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|