diff --git a/Controllers/AdminController.cs b/Controllers/AdminController.cs index 6197bba..a704d34 100644 --- a/Controllers/AdminController.cs +++ b/Controllers/AdminController.cs @@ -2,6 +2,8 @@ using CarCareTracker.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System.Net; +using System.Net.Mail; namespace CarCareTracker.Controllers { @@ -25,6 +27,8 @@ namespace CarCareTracker.Controllers public IActionResult GenerateNewToken(string emailAddress) { var result = _loginLogic.GenerateUserToken(emailAddress); + //send an email test block. + SendEmail(emailAddress); return Json(result); } public IActionResult DeleteToken(int tokenId) @@ -32,5 +36,31 @@ namespace CarCareTracker.Controllers var result = _loginLogic.DeleteUserToken(tokenId); return Json(result); } + private bool SendEmail(string emailAddress) + { + var mailConfig = new MailConfig(); + string to = emailAddress; + string from = mailConfig.EmailFrom; + var server = mailConfig.EmailServer; + MailMessage message = new MailMessage(from, to); + message.Subject = "Using the new SMTP client."; + message.Body = @"Using this new feature, you can send an email message from an application very easily."; + SmtpClient client = new SmtpClient(server); + client.EnableSsl = mailConfig.UseSSL; + client.Port = mailConfig.Port; + client.Credentials = new NetworkCredential(mailConfig.Username, mailConfig.Password); + + try + { + client.Send(message); + return true; + } + catch (Exception ex) + { + Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", + ex.ToString()); + return false; + } + } } } diff --git a/Logic/LoginLogic.cs b/Logic/LoginLogic.cs index 22a425c..cefd889 100644 --- a/Logic/LoginLogic.cs +++ b/Logic/LoginLogic.cs @@ -83,7 +83,8 @@ namespace CarCareTracker.Logic { Id = -1, UserName = credentials.UserName, - IsAdmin = true + IsAdmin = true, + IsRootUser = true }; } else diff --git a/Models/Configuration/MailConfig.cs b/Models/Configuration/MailConfig.cs new file mode 100644 index 0000000..23243e8 --- /dev/null +++ b/Models/Configuration/MailConfig.cs @@ -0,0 +1,12 @@ +namespace CarCareTracker.Models +{ + public class MailConfig + { + public string EmailServer { get; set; } + public string EmailFrom { get; set; } + public bool UseSSL { get; set; } + public int Port { get; set; } + public string Username { get; set; } + public string Password { get; set; } + } +} diff --git a/Models/Login/UserData.cs b/Models/Login/UserData.cs index 29e5505..6fb77a1 100644 --- a/Models/Login/UserData.cs +++ b/Models/Login/UserData.cs @@ -7,5 +7,6 @@ public string EmailAddress { get; set; } public string Password { get; set; } public bool IsAdmin { get; set; } + public bool IsRootUser { get; set; } = false; } } \ No newline at end of file