This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -8,6 +8,7 @@ namespace rockfishCore.Models
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public long CustomerId { get; set; }
|
||||
public long SiteId { get; set; }
|
||||
public long DtCreated { get; set; }
|
||||
public string RegTo { get; set; }
|
||||
public string Key { get; set; }
|
||||
|
||||
@@ -13,23 +13,21 @@ namespace rockfishCore.Util
|
||||
//Key generator controller
|
||||
public static class RavenKeyFactory
|
||||
{
|
||||
public const int TRIAL_PERIOD_DAYS = 45;
|
||||
|
||||
//Unlicensed token
|
||||
private const string UNLICENSED_TOKEN = "UNLICENSED";
|
||||
|
||||
//REVOKED token
|
||||
private const string REVOKED_TOKEN = "REVOKED";
|
||||
|
||||
//FEATURE NAMES
|
||||
//Scheduleable users
|
||||
private const string SERVICE_TECHS_FEATURE_NAME = "ServiceTechs";
|
||||
|
||||
//Accounting add-on
|
||||
private const string ACCOUNTING_FEATURE_NAME = "Accounting";
|
||||
|
||||
//This feature name means it's a trial key
|
||||
private const string TRIAL_FEATURE_NAME = "TrialMode";
|
||||
|
||||
public const int TRIAL_PERIOD_DAYS = 45;
|
||||
|
||||
//This feature name means it's a SAAS or rental mode key for month to month hosted service
|
||||
private const string RENTAL_FEATURE_NAME = "ServiceMode";
|
||||
|
||||
@@ -63,6 +61,60 @@ namespace rockfishCore.Util
|
||||
Id = $"00-{sId}";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
/*LICENSE DETAILS
|
||||
Registered to: Montacargas y Equipos Colombia
|
||||
Fetch address: facordoba@jycexports.com
|
||||
Fetch code: ZgVySojpHg
|
||||
Scheduleable resources: Up to 15
|
||||
Support and updates until: Thursday, August 13, 2020
|
||||
|
||||
|
||||
Plugins:
|
||||
WBI - Web browser interface support and updates until: Tuesday, June 15, 2021
|
||||
ExportToXls support and updates until: Tuesday, June 15, 2021
|
||||
ImportExportCSVDuplicate support and updates until: Friday, July 17, 2020
|
||||
RI - Responsive Interface support and updates until: Tuesday, June 15, 2021 */
|
||||
System.Text.StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("LICENSE DETAILS");
|
||||
sb.AppendLine($"Registered to: {RegisteredTo}");
|
||||
sb.AppendLine($"Database id: {DbId}");
|
||||
if (WillExpire)
|
||||
sb.AppendLine($"License valid until: {LicenseExpiration.ToLongDateString()}");
|
||||
sb.AppendLine($"Support and updates until: {MaintenanceExpiration.ToLongDateString()}");
|
||||
foreach (LicenseFeature f in Features)
|
||||
{
|
||||
if (f.Feature == TRIAL_FEATURE_NAME)
|
||||
{
|
||||
sb.AppendLine("Temporary license for evaluation");
|
||||
continue;
|
||||
}
|
||||
if (f.Feature == RENTAL_FEATURE_NAME)
|
||||
{
|
||||
sb.AppendLine("Service / Rental license");
|
||||
continue;
|
||||
}
|
||||
if (f.Feature == ACCOUNTING_FEATURE_NAME)
|
||||
{
|
||||
sb.AppendLine("Accounting option");
|
||||
continue;
|
||||
}
|
||||
if (f.Feature == SERVICE_TECHS_FEATURE_NAME)
|
||||
{
|
||||
sb.AppendLine($"Scheduleable resources: {f.Count}");
|
||||
continue;
|
||||
}
|
||||
//default for items added later not tokenized
|
||||
if (f.Count > 0)
|
||||
sb.AppendLine($"{f.Feature}: {f.Count}");
|
||||
else
|
||||
sb.AppendLine($"{f.Feature}");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get
|
||||
|
||||
@@ -363,7 +363,7 @@ namespace rockfishCore.Util
|
||||
//////////////////////////////////////////////////
|
||||
//schema 16 RAVEN stuff
|
||||
if (currentSchema < 16)
|
||||
{
|
||||
{
|
||||
exec("CREATE TABLE trialrequest (" +
|
||||
"id INTEGER PRIMARY KEY, dbid text not null, companyname text not null, contactname text not null, notes text, email text not null, " +
|
||||
"emailconfirmcode text not null, emailvalidated boolean default 0 NOT NULL CHECK (emailvalidated IN (0,1)), dtrequested integer, " +
|
||||
@@ -373,6 +373,7 @@ namespace rockfishCore.Util
|
||||
exec("alter table site add dbid text default 'v7_no_dbid' NOT NULL");
|
||||
exec("update site set legacyv7 = 1");
|
||||
exec("alter table license add dbid text default 'v7_no_dbid' NOT NULL");
|
||||
exec("alter table license add siteid integer");
|
||||
exec("alter table purchase add quantity integer default 1 not null");
|
||||
exec("insert into product (name, productCode, price, renewPrice) values ('TEST RAVEN schedulable resource 1 year subscription license','testfeatscheduser',15900, 5565);");
|
||||
exec("insert into product (name, productCode, price, renewPrice) values ('TEST RAVEN Accounting 1 year subscription license','testfeatacct',15000, 5250);");
|
||||
|
||||
Reference in New Issue
Block a user