This commit is contained in:
@@ -38,10 +38,10 @@ namespace rockfishCore.Controllers
|
||||
|
||||
#if (DEBUG)
|
||||
private const string LICENSE_SERVER_URL = "http://localhost:3001/";
|
||||
private const string SUPPORT_EMAIL = "cardjohn@ayanova.com";
|
||||
public const string SUPPORT_EMAIL = "cardjohn@ayanova.com";
|
||||
#else
|
||||
private const string LICENSE_SERVER_URL = "https://rockfish.ayanova.com/";
|
||||
private const string SUPPORT_EMAIL="support@ayanova.com";
|
||||
public const string SUPPORT_EMAIL="support@ayanova.com";
|
||||
#endif
|
||||
|
||||
[HttpPost]
|
||||
@@ -66,7 +66,7 @@ namespace rockfishCore.Controllers
|
||||
System.Diagnostics.Debug.WriteLine("RvRController:Post - TODO: Test MustBeOlderThan date code");
|
||||
|
||||
//if there is an active trial for this db then can't do this they must request we re-release it or completely zap the database instead
|
||||
var MustBeOlderThan = DateUtil.DateToEpoch(DateTime.Now.AddDays(-45));
|
||||
var MustBeOlderThan = DateUtil.DateToEpoch(DateTime.Now.AddDays((RavenKeyFactory.TRIAL_PERIOD_DAYS * -1)));
|
||||
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");
|
||||
@@ -114,7 +114,7 @@ namespace rockfishCore.Controllers
|
||||
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@ayanova.com", "AyaNova trial request requiring action", body, false);
|
||||
RfMail.SendMessage("support@ayanova.com", SUPPORT_EMAIL, "AyaNova trial request requiring action", body, false);
|
||||
|
||||
return new ContentResult
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
using rockfishCore.Util;
|
||||
|
||||
namespace rockfishCore.Controllers
|
||||
{
|
||||
@@ -65,44 +65,74 @@ namespace rockfishCore.Controllers
|
||||
return Ok(rec);
|
||||
}
|
||||
|
||||
|
||||
// PUT: api/TrialRequest/5
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutTrialRequest([FromRoute] long id, [FromBody] TrialRequest TrialRequest)
|
||||
//Approve
|
||||
[HttpPost("approve/{id}")]
|
||||
public async Task<IActionResult> ApproveTrial([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
var trial = await ct.TrialRequest.SingleOrDefaultAsync(m => m.Id == id);
|
||||
if (trial == null)
|
||||
return NotFound();
|
||||
//DO APPROVE
|
||||
//check not already processed and ignore if so
|
||||
if(trial.DtProcessed!=null){
|
||||
//already processed, nothing to do here
|
||||
return BadRequest("Already processed");
|
||||
}
|
||||
|
||||
if (id != TrialRequest.Id)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
//generate license key and insert in record
|
||||
trial.Key = RavenKeyFactory.GetRavenTrialKey(trial.DbId, trial.CompanyName);
|
||||
trial.Status = TrialRequest.TrialRequestStatus.Approved;
|
||||
trial.DtProcessed = DateUtil.NowAsEpoch();
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
ct.Entry(TrialRequest).State = EntityState.Modified;
|
||||
//send approved email to user
|
||||
var body = $"Your trial license request has been approved.\r\nThe license will fetch and install automatically shortly or you can fetch it now in the License form menu.";
|
||||
//send confirmation email
|
||||
RfMail.SendMessage("support@ayanova.com", trial.Email, "AyaNova trial request approved", body, false);
|
||||
|
||||
try
|
||||
{
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await TrialRequestExistsAsync(id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return Ok(trial);
|
||||
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
//Reject
|
||||
[HttpPost("reject/{id}")]
|
||||
public async Task<IActionResult> RejectTrial([FromRoute] long id, [FromQuery] string rejectReason)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
var trial = await ct.TrialRequest.SingleOrDefaultAsync(m => m.Id == id);
|
||||
if (trial == null)
|
||||
return NotFound();
|
||||
//DO REJECT
|
||||
//check not already processed and ignore if so
|
||||
if(trial.DtProcessed!=null){
|
||||
//already processed, nothing to do here
|
||||
return BadRequest("Already processed");
|
||||
}
|
||||
//generate license key and insert in record
|
||||
trial.RejectReason=rejectReason;
|
||||
trial.Status = TrialRequest.TrialRequestStatus.Rejected;
|
||||
trial.DtProcessed = DateUtil.NowAsEpoch();
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//send approved email to user
|
||||
string reason=string.Empty;
|
||||
if(!string.IsNullOrWhiteSpace(rejectReason)){
|
||||
reason=$"The request was rejected due to:\r\n{rejectReason}";
|
||||
}
|
||||
var body = $"Your trial license request was not approved.\r\n{reason}";
|
||||
//send confirmation email
|
||||
RfMail.SendMessage("support@ayanova.com", trial.Email, "AyaNova trial request approved", body, false);
|
||||
|
||||
return Ok(trial);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private async Task<bool> TrialRequestExistsAsync(long id)
|
||||
@@ -110,7 +140,7 @@ namespace rockfishCore.Controllers
|
||||
return await ct.TrialRequest.AnyAsync(e => e.Id == id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
}//eoc
|
||||
|
||||
Reference in New Issue
Block a user