This commit is contained in:
2020-06-17 18:58:37 +00:00
parent fb586e0f5b
commit 305b61045d
6 changed files with 140 additions and 111 deletions

View File

@@ -8,6 +8,7 @@ using rockfishCore.Util;
namespace rockfishCore.Controllers
{
//### CUSTOMER ROUTE CALLED FROM RAVEN NO AUTH ####
[Produces("application/json")]
[Route("rvf")]
public class RvfController : Controller //RAVEN License fetch route
@@ -20,6 +21,7 @@ namespace rockfishCore.Controllers
}
//### CUSTOMER ROUTE CALLED FROM RAVEN ####
[HttpGet("{dbid}")]
public async Task<IActionResult> Get([FromRoute] Guid dbid)
{
@@ -63,46 +65,8 @@ namespace rockfishCore.Controllers
key = LicenseKey
}
});
}
// [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
// //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));
// }
// }
private bool LicenseExists(long id)
{
return ct.License.Any(e => e.Id == id);
}
}
}

View File

@@ -12,9 +12,11 @@ using System.ComponentModel.DataAnnotations;
namespace rockfishCore.Controllers
{
[Produces("text/plain")]
//### OUR ROUTE CALLED FROM ROCKFISH CLIENT ####
[Produces("application/json")]
[Route("rvl")]
public class RvlController : Controller //RAVEN license controller
[Authorize]
public class RvlController : Controller
{
private readonly rockfishContext ct;
@@ -98,74 +100,84 @@ namespace rockfishCore.Controllers
return BadRequest($"Customer {Customer.Name} is set to DO NOT CONTACT, unable to process and send key");
}
var newLicense = new RavenKeyFactory.AyaNovaLicenseKey();
newLicense.RegisteredTo = l.RegisteredTo;
newLicense.DbId = l.DbId;
newLicense.LicenseExpiration = DateUtil.EpochToDate(l.LicenseExpiration);
newLicense.MaintenanceExpiration = DateUtil.EpochToDate(l.MaintenanceExpiration);
foreach (dtoLicenseFeature f in l.Features)
try
{
newLicense.Features.Add(new RavenKeyFactory.LicenseFeature() { Feature = f.Feature, Count = f.Count });
}
var newLicense = new RavenKeyFactory.AyaNovaLicenseKey();
//Everything seems to be in order generate the license, save it and send it
var NewRequest = new TrialRequest();
NewRequest.Email = r.Email;
NewRequest.DbId = r.DbId;
NewRequest.CompanyName = r.Company;
NewRequest.ContactName = r.Contact;
await ct.TrialRequest.AddAsync(NewRequest);
await ct.SaveChangesAsync();
NewRequest.EmailConfirmCode = NewRequest.Id.ToString() + FetchKeyCode.generate();
await ct.SaveChangesAsync();
var verifyUrl = LICENSE_SERVER_URL + $"rvr/verify/{NewRequest.EmailConfirmCode}";
var body = $"Please verify your email address by clicking the link below or copy and pasting into a browser\r\n{verifyUrl}\r\n(If you did not request this you can ignore this message)";
//send confirmation email
RfMail.SendMessage("support@ayanova.com", NewRequest.Email, "AyaNova trial request email verification", body, false);
//return Ok(new { Accepted = true });
return Accepted();
}
[HttpGet("verify/{code}")]
public async Task<IActionResult> GetVerify([FromRoute] string code)
{
//is there a valid trial request
var req = await ct.TrialRequest.Where(z => z.EmailConfirmCode == code && z.DtFetched == null && z.Status == TrialRequest.TrialRequestStatus.NotSet).FirstOrDefaultAsync();
if (req == null)
{
return new ContentResult
newLicense.RegisteredTo = l.RegisteredTo;
newLicense.DbId = l.DbId;
newLicense.LicenseExpiration = DateUtil.EpochToDate(l.LicenseExpiration);
newLicense.MaintenanceExpiration = DateUtil.EpochToDate(l.MaintenanceExpiration);
foreach (dtoLicenseFeature f in l.Features)
{
ContentType = "text/html",
StatusCode = 200,
Content = "<html><body><h4>Request not found</h4><p>There was no evaluation request associated with this verification code.</p></body></html>"
};
newLicense.Features.Add(new RavenKeyFactory.LicenseFeature() { Feature = f.Feature, Count = f.Count });
}
//Everything seems to be in order generate the license, save it and send it
var Key = RavenKeyFactory.GenerateRavenKey(newLicense);
//save it to the database
var DBLicense = new License();
DBLicense.CustomerId = CustomerId;
DBLicense.SiteId = l.SiteId;
DBLicense.Email = Customer.AdminEmail;
DBLicense.DbId = l.DbId;
DBLicense.Key = Key;
DBLicense.RegTo = l.RegisteredTo;
await ct.License.AddAsync(DBLicense);
await ct.SaveChangesAsync();
//Key generated, record saved successfully
//inform customer and return no content
var body = $"Thank you for your purchase!\nYour AyaNova license key is ready to be installed.\nAyaNova will fetch it automatically within 24 hours or you can force it to fetch immediately from the License page in AyaNova now.\n---\n{l}";
//send license email
RfMail.SendMessage("support@ayanova.com", Customer.AdminEmail, "AyaNova license key", body, false);
return NoContent();
}
req.EmailValidated = true;
await ct.SaveChangesAsync();
//notify *us*
//http://localhost:3001/default.htm#!/trials/[id]
var rfUrl = LICENSE_SERVER_URL + $"default.htm#!/trialEdit/{req.Id}";
var body = $"Email address {req.Email} was just verified for {req.ContactName} at {req.CompanyName}.\r\nTrial key is ready to be processed now:\r\n{rfUrl}";
//send confirmation email
RfMail.SendMessage("support@ayanova.com", SUPPORT_EMAIL, "AyaNova trial request requiring action", body, false);
return new ContentResult
catch (Exception ex)
{
ContentType = "text/html",
StatusCode = 200,
Content = "<html><body><h4>Email validated!</h4><p>Your request is being processed and you will receive an email with instructions for starting your AyaNova evaluation.</p></body></html>"
};
return StatusCode(500, $"Exception processing request: {ex.Message}");
}
}
// [HttpGet("verify/{code}")]
// public async Task<IActionResult> GetVerify([FromRoute] string code)
// {
// //is there a valid trial request
// var req = await ct.TrialRequest.Where(z => z.EmailConfirmCode == code && z.DtFetched == null && z.Status == TrialRequest.TrialRequestStatus.NotSet).FirstOrDefaultAsync();
// if (req == null)
// {
// return new ContentResult
// {
// ContentType = "text/html",
// StatusCode = 200,
// Content = "<html><body><h4>Request not found</h4><p>There was no evaluation request associated with this verification code.</p></body></html>"
// };
// }
// req.EmailValidated = true;
// await ct.SaveChangesAsync();
// //notify *us*
// //http://localhost:3001/default.htm#!/trials/[id]
// var rfUrl = LICENSE_SERVER_URL + $"default.htm#!/trialEdit/{req.Id}";
// var body = $"Email address {req.Email} was just verified for {req.ContactName} at {req.CompanyName}.\r\nTrial key is ready to be processed now:\r\n{rfUrl}";
// //send confirmation email
// RfMail.SendMessage("support@ayanova.com", SUPPORT_EMAIL, "AyaNova trial request requiring action", body, false);
// return new ContentResult
// {
// ContentType = "text/html",
// StatusCode = 200,
// Content = "<html><body><h4>Email validated!</h4><p>Your request is being processed and you will receive an email with instructions for starting your AyaNova evaluation.</p></body></html>"
// };
// }
}//eoc
}//eons

View File

@@ -1,10 +1,7 @@
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;
@@ -12,6 +9,7 @@ using System.ComponentModel.DataAnnotations;
namespace rockfishCore.Controllers
{
//### CUSTOMER ROUTES NO AUTH
[Produces("text/plain")]
[Route("rvr")]
public class RvrController : Controller //RAVEN trial license request
@@ -44,6 +42,7 @@ namespace rockfishCore.Controllers
public const string SUPPORT_EMAIL="support@ayanova.com";
#endif
//### CUSTOMER ROUTE CALLED FROM RAVEN ####
[HttpPost]
public async Task<IActionResult> Post([FromBody] dtoRequest r)
{
@@ -98,6 +97,7 @@ namespace rockfishCore.Controllers
}
//### CUSTOMER ROUTE CALLED FROM CUSTOMER BROWSER / EMAIL ####
[HttpGet("verify/{code}")]
public async Task<IActionResult> GetVerify([FromRoute] string code)
{
@@ -131,6 +131,5 @@ namespace rockfishCore.Controllers
};
}
}//eoc
}//eons