UserAuthenticationHandler.cs 981 B

12345678910111213141516171819202122232425262728
  1. using MediaBrowser.Common.Net.Handlers;
  2. using MediaBrowser.Controller;
  3. using MediaBrowser.Model.Entities;
  4. using System.ComponentModel.Composition;
  5. using System.Net;
  6. using System.Threading.Tasks;
  7. namespace MediaBrowser.Api.HttpHandlers
  8. {
  9. [Export(typeof(BaseHandler))]
  10. class UserAuthenticationHandler : BaseSerializationHandler<AuthenticationResult>
  11. {
  12. public override bool HandlesRequest(HttpListenerRequest request)
  13. {
  14. return ApiService.IsApiUrlMatch("UserAuthentication", request);
  15. }
  16. protected override async Task<AuthenticationResult> GetObjectToSerialize()
  17. {
  18. string userId = await GetFormValue("userid").ConfigureAwait(false);
  19. User user = ApiService.GetUserById(userId, false);
  20. string password = await GetFormValue("password").ConfigureAwait(false);
  21. return Kernel.Instance.AuthenticateUser(user, password);
  22. }
  23. }
  24. }