This commit is contained in:
2020-06-11 22:28:39 +00:00
parent 9ebf44f9d5
commit 59fcaa6f18
3 changed files with 51 additions and 20 deletions

View File

@@ -18,6 +18,7 @@ namespace rockfishCore.Controllers
{
private readonly rockfishContext ct;
public RvrController(rockfishContext context)
{
ct = context;
@@ -35,6 +36,10 @@ namespace rockfishCore.Controllers
public string Contact { get; set; }
}
// private const string LICENSE_SERVER_URL = "https://rockfish.ayanova.com/";
private const string LICENSE_SERVER_URL = "http://localhost:3001/";
[HttpPost]
public async Task<IActionResult> Post([FromBody] dtoRequest r)
{
@@ -60,33 +65,58 @@ namespace rockfishCore.Controllers
var MustBeOlderThan = DateUtil.DateToEpoch(DateTime.Now.AddDays(-45));
if (await ct.TrialRequest.Where(z => z.DbId == r.DbId && z.DtProcessed != null && z.DtProcessed > MustBeOlderThan).AnyAsync())
{
return BadRequest("E1000 - Can't trial; there is already an active trial license issued for this database Id");
return BadRequest("E1000 - Can't trial; there is already an active trial license issued for this database Id");
}
//Everything seems to be in order, save the request and return ok
var NewRequest=new TrialRequest();
NewRequest.Email=r.Email;
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?code={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 });
}
[HttpGet("verify")]
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>"
};
}
//TODO: closer to release as ROCKFISH might change before then
//Attempt to match customer by dbid if not then create new customer of trial type for the indicated dbid and regto
//ensure this email goes into the adminEmail array if not already there
//Flag customer record has having an unfulfilled trial request
//If it's a new customer or an existing one with non-matching email then send a verification email to the customer
//When a response is spotted in email then Rockfish should see it and flag the customer as verified
//Probably some general purpose email Verify code would be helpful here as it would likely be useful for all manner of things
//When user releases trial in Rockfish a license key will be generated ready for the customers RAVEN to retrieve
return Ok("Request accepted. Awaiting email verification and approval.");
req.EmailValidated = true;
await ct.SaveChangesAsync();
//notify *us*
//http://localhost:3001/default.htm#!/trials/[id]
var rfUrl = LICENSE_SERVER_URL + $"default.htm#!/trials/{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@ayanova.com", "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>"
};
}

View File

@@ -33,6 +33,7 @@ namespace rockfishCore.Models
public string ContactName { get; set; }
public string Notes { get; set; }
public string Email { get; set; }
public string EmailConfirmCode {get;set;}
public bool EmailValidated { get; set; }
public long? DtRequested { get; set; }
public long? DtProcessed { get; set; }

View File

@@ -366,7 +366,7 @@ namespace rockfishCore.Util
{
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, " +
"emailvalidated boolean default 0 NOT NULL CHECK (emailvalidated IN (0,1)), dtrequested integer, " +
"emailconfirmcode text not null, emailvalidated boolean default 0 NOT NULL CHECK (emailvalidated IN (0,1)), dtrequested integer, " +
"dtprocessed integer, status integer default 0 not null, rejectreason text, key text, dtfetched integer" +
")");
exec("alter table site add legacyv7 boolean default 0 NOT NULL CHECK (legacyv7 IN (0,1))");