Add in verify company email
This commit is contained in:
@@ -2,13 +2,18 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using BoredCareers.Services.DatabaseService;
|
using BoredCareers.Services.DatabaseService;
|
||||||
using BoredCareers.Entities;
|
using BoredCareers.Entities;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
|
using BoredCareers.Services;
|
||||||
|
|
||||||
namespace BoredCareers.Controllers {
|
namespace BoredCareers.Controllers {
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/company")]
|
[Route("api/company")]
|
||||||
public class CompanyController : MistoxControllerBase {
|
public class CompanyController : MistoxControllerBase {
|
||||||
|
|
||||||
public CompanyController(DatabaseService db) : base(db) {}
|
EmailService _emailContext;
|
||||||
|
|
||||||
|
public CompanyController(DatabaseService db, EmailService emailContext) : base(db) {
|
||||||
|
_emailContext = emailContext;
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetCompany(int CompanyID) {
|
public async Task<IActionResult> GetCompany(int CompanyID) {
|
||||||
@@ -60,6 +65,57 @@ namespace BoredCareers.Controllers {
|
|||||||
return NotFound("Not logged in");
|
return NotFound("Not logged in");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("sendverifyemail")]
|
||||||
|
public async Task<ActionResult<string>> SendVerify([FromQuery] int CompanyID) {
|
||||||
|
try {
|
||||||
|
string key = "v" + CompanyID;
|
||||||
|
// Stop from sending multiple emails quickly
|
||||||
|
if (_emailContext._SentEmails.ContainsKey(key)) {
|
||||||
|
DateTime PreviousSentTime = _emailContext._SentEmails.GetValueOrDefault(key);
|
||||||
|
if (PreviousSentTime.AddMinutes(5) > DateTime.Now) {
|
||||||
|
return NotFound("Cannot sent another verify email until 5 minutes has elapsed");
|
||||||
|
} else {
|
||||||
|
_emailContext._SentEmails.Remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Company? test = await _databaseService.GetCompany(CompanyID);
|
||||||
|
if (test != null) {
|
||||||
|
test.EmailToken = Guid.NewGuid().ToString();
|
||||||
|
await _databaseService.SetCompany(test);
|
||||||
|
|
||||||
|
string EmailContents = EmailService.CompanyVerifyEmailSubject;
|
||||||
|
EmailContents = Substitue(EmailContents, "@CompanyName", test.Name);
|
||||||
|
EmailContents = Substitue(EmailContents, "@ID", CompanyID.ToString());
|
||||||
|
EmailContents = Substitue(EmailContents, "@VerifyPassword", test.EmailToken);
|
||||||
|
|
||||||
|
string result = _emailContext.Send(test.Email, EmailService.CompanyVerifyEmailSubject, EmailContents);
|
||||||
|
_emailContext._SentEmails.Add(key, DateTime.Now);
|
||||||
|
return Redirect("/");
|
||||||
|
}
|
||||||
|
return NotFound("Account not found");
|
||||||
|
} catch (Exception) {
|
||||||
|
return NotFound("An internal server error has occured");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("verifyemail")]
|
||||||
|
public async Task<ActionResult<bool>> VerifyEmail([FromQuery] int CompanyID, [FromQuery] string EmailToken) {
|
||||||
|
try {
|
||||||
|
Company? test = await _databaseService.GetCompany(CompanyID);
|
||||||
|
if (test != null) {
|
||||||
|
if (test.EmailToken == EmailToken) {
|
||||||
|
test.EmailToken = "";
|
||||||
|
test.EmailVerified = true;
|
||||||
|
await _databaseService.SetCompany(test);
|
||||||
|
return Redirect("/");
|
||||||
|
}
|
||||||
|
return BadRequest("The token isn't valid");
|
||||||
|
}
|
||||||
|
return BadRequest("Account not found"); ;
|
||||||
|
} catch {
|
||||||
|
return BadRequest("An internal server error has occured");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
namespace BoredCareers.Services {
|
||||||
|
public partial class EmailService {
|
||||||
|
|
||||||
|
// @UserName
|
||||||
|
// @VerifyPassword
|
||||||
|
// https://mistox.com/api/account/verifyemail?UserName=@UserName&Guid=@VerifyPassword
|
||||||
|
|
||||||
|
public static string CompanyVerifyEmailSubject = "Verify Your Email Address";
|
||||||
|
public static string CompanyVerifyEmailBody = @"
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang=""en"">
|
||||||
|
<head>
|
||||||
|
<meta charset=""UTF-8"">
|
||||||
|
<meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">
|
||||||
|
<title>Verify Your Email</title>
|
||||||
|
</head>
|
||||||
|
<body style=""font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0;"">
|
||||||
|
<table role=""presentation"" style=""width: 100%; background-color: #f4f4f4; padding: 20px 0;"">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<table role=""presentation"" style=""max-width: 600px; width: 100%; background-color: #ffffff; margin: 0 auto; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);"">
|
||||||
|
<tr>
|
||||||
|
<td style=""padding: 20px; text-align: center; background-color: #4CAF50; color: #ffffff; border-top-left-radius: 8px; border-top-right-radius: 8px;"">
|
||||||
|
<h2>Verify Email Request</h2>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style=""padding: 20px; text-align: left; font-size: 16px; color: #333333;"">
|
||||||
|
<p>Hi @CompanyName,</p>
|
||||||
|
<p>Thank you for making an account with us:</p>
|
||||||
|
<p>In order to start using your account we need to verify your email address by clicking the link below:</p>
|
||||||
|
<p style=""text-align: center;"">
|
||||||
|
<a href=""https://boredcareers.com/api/company/verifyemail?CompanyID=@ID&EmailToken=@VerifyPassword"" style=""background-color: #4CAF50; color: #ffffff; text-decoration: none; padding: 15px 25px; font-size: 16px; border-radius: 5px; display: inline-block;"">Verify Email</a>
|
||||||
|
</p>
|
||||||
|
<p>If you didn't create an account please ignore this email.</p>
|
||||||
|
<p>Best regards</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style=""padding: 10px; text-align: center; background-color: #f4f4f4; color: #888888; font-size: 12px; border-bottom-left-radius: 8px; border-bottom-right-radius: 8px;"">
|
||||||
|
<p>If you have any questions, feel free to <a href=""mailto:webmaster@mistox.com"" style=""color: #4CAF50; text-decoration: none;"">contact support</a>.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ namespace BoredCareers.Services {
|
|||||||
// https://mistox.com/api/account/verifyemail?UserName=@UserName&Guid=@VerifyPassword
|
// https://mistox.com/api/account/verifyemail?UserName=@UserName&Guid=@VerifyPassword
|
||||||
|
|
||||||
public static string JobAutoClosedSubject = "Verify Your Email Address";
|
public static string JobAutoClosedSubject = "Verify Your Email Address";
|
||||||
public static string JobAutoClosedEmail = @"
|
public static string JobAutoClosedBody = @"
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang=""en"">
|
<html lang=""en"">
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
Reference in New Issue
Block a user