This commit is contained in:
@@ -11,34 +11,94 @@ using rockfishCore.Util;
|
|||||||
|
|
||||||
namespace rockfishCore.Controllers
|
namespace rockfishCore.Controllers
|
||||||
{
|
{
|
||||||
[Produces("text/plain")]
|
[Produces("application/json")]
|
||||||
[Route("rvf")]
|
[Route("rvf")]
|
||||||
|
|
||||||
public class RvfController : Controller //RAVEN License fetch route
|
public class RvfController : Controller //RAVEN License fetch route
|
||||||
{
|
{
|
||||||
private readonly rockfishContext _context;
|
private readonly rockfishContext ct;
|
||||||
|
|
||||||
public RvfController(rockfishContext context)
|
public RvfController(rockfishContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
ct = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpGet("{dbid}")]
|
[HttpGet("{dbid}")]
|
||||||
public ActionResult Get([FromRoute] Guid dbid)
|
public async Task<IActionResult> Get([FromRoute] Guid dbid)
|
||||||
{
|
{
|
||||||
|
//this is called after a successful check says there is a key below so it's not hammered (in theory)
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string LicenseKey = null;
|
||||||
|
//check for a key for this dbid, first check licensed then check trial
|
||||||
|
var PurchasedLicense = await ct.License.Where(z => z.DbId == dbid && z.Fetched == false).FirstOrDefaultAsync();
|
||||||
|
if (PurchasedLicense != null)
|
||||||
|
{
|
||||||
|
LicenseKey = PurchasedLicense.Key;
|
||||||
|
PurchasedLicense.Fetched = true;
|
||||||
|
PurchasedLicense.DtFetched = DateUtil.NowAsEpoch();
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//is it a trial request
|
||||||
|
var TrialRequest = await ct.TrialRequest.Where(z => z.DbId == dbid && z.DtFetched == null).FirstOrDefaultAsync();
|
||||||
|
LicenseKey = TrialRequest.Key;
|
||||||
|
TrialRequest.DtFetched = DateUtil.NowAsEpoch();
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LicenseKey == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
key = LicenseKey
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// //This is to simulate the scenarios where there is no license to return
|
||||||
|
// //either due to no current account / canceled or simply no license exists
|
||||||
|
// //Changes here must be reflected in RAVEN Util.License.Fetch block
|
||||||
|
// bool bTestStatusOtherThanOk = false;
|
||||||
|
// if (bTestStatusOtherThanOk)
|
||||||
|
// {
|
||||||
|
// return Json(new {Status="NONE", Reason="No license"});
|
||||||
|
// //return Json(new {Status="Canceled", Reason="Non payment"});
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// return Ok(RavenKeyFactory.GetRavenTestKey(dbid));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet("hello/{dbid}")]
|
||||||
|
public ActionResult Hello([FromRoute] Guid dbid)
|
||||||
|
{
|
||||||
|
//check to see if there is anything of note for this server like a new key or a message etc
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState);
|
||||||
|
}
|
||||||
|
|
||||||
|
//return a json object with results if anything to report
|
||||||
|
|
||||||
//This is to simulate the scenarios where there is no license to return
|
//This is to simulate the scenarios where there is no license to return
|
||||||
//either due to no current account / canceled or simply no license exists
|
//either due to no current account / canceled or simply no license exists
|
||||||
//Changes here must be reflected in RAVEN Util.License.Fetch block
|
//Changes here must be reflected in RAVEN Util.License.Fetch block
|
||||||
bool bTestStatusOtherThanOk = false;
|
bool bTestStatusOtherThanOk = false;
|
||||||
if (bTestStatusOtherThanOk)
|
if (bTestStatusOtherThanOk)
|
||||||
{
|
{
|
||||||
return Json(new {Status="NONE", Reason="No license"});
|
return Json(new { Status = "NONE", Reason = "No license" });
|
||||||
//return Json(new {Status="Canceled", Reason="Non payment"});
|
//return Json(new {Status="Canceled", Reason="Non payment"});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -52,9 +112,10 @@ namespace rockfishCore.Controllers
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private bool LicenseExists(long id)
|
private bool LicenseExists(long id)
|
||||||
{
|
{
|
||||||
return _context.License.Any(e => e.Id == id);
|
return ct.License.Any(e => e.Id == id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ namespace rockfishCore.Models
|
|||||||
public string FetchFrom { get; set; }
|
public string FetchFrom { get; set; }
|
||||||
public long? DtFetched { get; set; }
|
public long? DtFetched { get; set; }
|
||||||
public bool Fetched { get; set; }
|
public bool Fetched { get; set; }
|
||||||
|
public Guid DbId { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace rockfishCore.Models
|
|||||||
public partial class TrialRequest
|
public partial class TrialRequest
|
||||||
{
|
{
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public string DbId { get; set; }
|
public Guid DbId { get; set; }
|
||||||
public string CompanyName { get; set; }
|
public string CompanyName { get; set; }
|
||||||
public string ContactName { get; set; }
|
public string ContactName { get; set; }
|
||||||
public string Notes { get; set; }
|
public string Notes { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user