mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-06 08:16:11 +00:00
feat: move MC into Essentials
In order to solve some dependency issues that keep cropping up, MC should be moved back into the Essentials repo and loaded automatically on startup. This will allow for all plugins that use the MC Messengers library to use the same version without fear of overwriting a dll due to loading of plugin libraries.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using PepperDash.Essentials.Core.Web;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PepperDash.Essentials.WebApiHandlers
|
||||
{
|
||||
public class MobileAuthRequestHandler : WebApiBaseRequestAsyncHandler
|
||||
{
|
||||
private readonly MobileControlSystemController mcController;
|
||||
|
||||
public MobileAuthRequestHandler(MobileControlSystemController controller) : base(true)
|
||||
{
|
||||
mcController = controller;
|
||||
}
|
||||
|
||||
protected override async Task HandlePost(HttpCwsContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var requestBody = EssentialsWebApiHelpers.GetRequestBody(context.Request);
|
||||
|
||||
var grantCode = JsonConvert.DeserializeObject<AuthorizationRequest>(requestBody);
|
||||
|
||||
if (string.IsNullOrEmpty(grantCode?.GrantCode))
|
||||
{
|
||||
Debug.LogMessage(Serilog.Events.LogEventLevel.Error, "Missing grant code");
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Missing grant code";
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
var response = await mcController.ApiService.SendAuthorizationRequest(mcController.Host, grantCode.GrantCode, mcController.SystemUuid);
|
||||
|
||||
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, $"response received");
|
||||
if (response.Authorized)
|
||||
{
|
||||
mcController.RegisterSystemToServer();
|
||||
}
|
||||
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
var responseBody = JsonConvert.SerializeObject(response, Formatting.None);
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.Headers.Add("Content-Type", "application/json");
|
||||
context.Response.Write(responseBody, false);
|
||||
context.Response.End();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage(ex, "Exception recieved authorizing system");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user