Add webhook for semi-automatic shareit order notification processing
This commit is contained in:
77
Controllers/OrderController.cs
Normal file
77
Controllers/OrderController.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using rockfishCore.Models;
|
||||
using rockfishCore.Util;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace rockfishCore.Controllers
|
||||
{
|
||||
//### OUR ROUTE CALLED FROM ROCKFISH CLIENT ####
|
||||
[Produces("application/json")]
|
||||
[Route("api/order")]
|
||||
[Authorize]
|
||||
public class OrderController : Controller
|
||||
{
|
||||
private readonly rockfishContext ct;
|
||||
|
||||
|
||||
public OrderController(rockfishContext context)
|
||||
{
|
||||
ct = context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Receive an order notification from ShareIt
|
||||
[HttpPost("shareit")]
|
||||
public async Task<IActionResult> Post([FromHeader] string Authorization, [FromBody] JObject j)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
try
|
||||
{
|
||||
//do stuff with the notification
|
||||
(string username, string password) = rockfishCore.Util.AutoOrderProcessingUtil.GetUsernameAndPasswordFromAuthorizeHeader(Authorization);
|
||||
// Now use username and password with whatever authentication process you want
|
||||
if (username == "Y24PYYDQSA1L12905N5MKU" && password == "GI2F7CP17C2JS872MHASAF")
|
||||
{
|
||||
//put the notification into the db as freeform notification information
|
||||
//to be processed by other code later. i.e. just capture it as is cleanly and don't bother trying to do anything fancy here this should be tight and focused and side effect free
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//todo Log this here
|
||||
System.Diagnostics.Debug.WriteLine($"order/shareit - Exception processing request: {ex.Message}");
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("list/{siteId}")]
|
||||
public async Task<IActionResult> GetList([FromRoute] long siteId)
|
||||
{
|
||||
return Ok(await ct.License.AsNoTracking().Where(z => z.SiteId == siteId).OrderByDescending(z => z.Id).ToListAsync());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
31
util/AutoOrderProcessingUtils.cs
Normal file
31
util/AutoOrderProcessingUtils.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
|
||||
|
||||
namespace rockfishCore.Util
|
||||
{
|
||||
//Import fogbugz stuff into our own db
|
||||
//called by schema update 7
|
||||
//does not modify FB at all
|
||||
//can be called any time, won't re-import
|
||||
public static class AutoOrderProcessingUtil
|
||||
{
|
||||
// static System.Text.Encoding ISO_8859_1_ENCODING = System.Text.Encoding.GetEncoding("ISO-8859-1");
|
||||
static Encoding ISO_8859_1_ENCODING = System.Text.Encoding.GetEncoding("ISO-8859-1");
|
||||
public static (string, string) GetUsernameAndPasswordFromAuthorizeHeader(string authorizeHeader)
|
||||
{
|
||||
if (authorizeHeader == null || !authorizeHeader.Contains("Basic "))
|
||||
return (null, null);
|
||||
|
||||
string encodedUsernamePassword = authorizeHeader.Substring("Basic ".Length).Trim();
|
||||
string usernamePassword = ISO_8859_1_ENCODING.GetString(Convert.FromBase64String(encodedUsernamePassword));
|
||||
|
||||
string username = usernamePassword.Split(':')[0];
|
||||
string password = usernamePassword.Split(':')[1];
|
||||
|
||||
return (username, password);
|
||||
}
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
@@ -13,7 +13,8 @@ app.rfsettings = (function() {
|
||||
var stateMap = {},
|
||||
configModule,
|
||||
onChangePassword,
|
||||
initModule;
|
||||
initModule,
|
||||
onTest;
|
||||
//----------------- END MODULE SCOPE VARIABLES ---------------
|
||||
|
||||
//------------------- BEGIN UTILITY METHODS ------------------
|
||||
@@ -48,6 +49,17 @@ app.rfsettings = (function() {
|
||||
|
||||
return false; //prevent default?
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////
|
||||
//ONTEST
|
||||
//
|
||||
onTest = function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
|
||||
return false; //prevent default?
|
||||
};
|
||||
//-------------------- END EVENT HANDLERS --------------------
|
||||
|
||||
//------------------- BEGIN PUBLIC METHODS -------------------
|
||||
@@ -70,6 +82,7 @@ app.rfsettings = (function() {
|
||||
|
||||
// bind actions
|
||||
$("#btn-change-password").bind("click", onChangePassword);
|
||||
$("#btn-test").bind("click", onTest);
|
||||
|
||||
//Context menu
|
||||
app.nav.contextClear();
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
<div class="app-frm-buttons mt-5">
|
||||
<button id="btn-change-password">Update</button>
|
||||
</div>
|
||||
|
||||
<div class="app-frm-buttons mt-5">
|
||||
<button id="btn-test" class="btn btn-warning">TEST THAT THING</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user