UserAuthenticationHandler.cs 1.0 KB

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