From 59fcaa6f187f150f624bf368eec705a495e41d24 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 11 Jun 2020 22:28:39 +0000 Subject: [PATCH] --- Controllers/RvrController.cs | 68 ++++++++++++++++++++++++++---------- Models/TrialRequest.cs | 1 + util/RfSchema.cs | 2 +- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Controllers/RvrController.cs b/Controllers/RvrController.cs index 627fcbc..d6baa3f 100644 --- a/Controllers/RvrController.cs +++ b/Controllers/RvrController.cs @@ -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 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 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 = "

Request not found

There was no evaluation request associated with this verification code.

" + }; + } - //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 = "

Email validated!

Your request is being processed and you will receive an email with instructions for starting your AyaNova evaluation.

" + }; } diff --git a/Models/TrialRequest.cs b/Models/TrialRequest.cs index 44af014..031ec70 100644 --- a/Models/TrialRequest.cs +++ b/Models/TrialRequest.cs @@ -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; } diff --git a/util/RfSchema.cs b/util/RfSchema.cs index 1119fe0..dffb733 100644 --- a/util/RfSchema.cs +++ b/util/RfSchema.cs @@ -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))");