aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/HttpHandlers/UserAuthenticationHandler.cs
blob: fa9d9759834da93dd6b2aedcc4611f5ad94a7a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Authentication;
using System.ComponentModel.Composition;
using System.Net;
using System.Threading.Tasks;

namespace MediaBrowser.Api.HttpHandlers
{
    [Export(typeof(BaseHandler))]
    class UserAuthenticationHandler : BaseSerializationHandler<AuthenticationResult>
    {
        public override bool HandlesRequest(HttpListenerRequest request)
        {
            return ApiService.IsApiUrlMatch("UserAuthentication", request);
        }
        
        protected override async Task<AuthenticationResult> GetObjectToSerialize()
        {
            string userId = await GetFormValue("userid").ConfigureAwait(false);
            User user = ApiService.GetUserById(userId, false);

            string password = await GetFormValue("password").ConfigureAwait(false);

            return Kernel.Instance.AuthenticateUser(user, password);
        }
    }
}