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

@@ -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