diff --git a/Controllers/LoginController.cs b/Controllers/LoginController.cs index fd9e444..a102f5d 100644 --- a/Controllers/LoginController.cs +++ b/Controllers/LoginController.cs @@ -240,6 +240,12 @@ namespace CarCareTracker.Controllers return Json(result); } [HttpPost] + public IActionResult SendRegistrationToken(LoginModel credentials) + { + var result = _loginLogic.SendRegistrationToken(credentials); + return Json(result); + } + [HttpPost] public IActionResult RequestResetPassword(LoginModel credentials) { var result = _loginLogic.RequestResetPassword(credentials); diff --git a/Helper/ConfigHelper.cs b/Helper/ConfigHelper.cs index b34c2f9..ad1fd0a 100644 --- a/Helper/ConfigHelper.cs +++ b/Helper/ConfigHelper.cs @@ -26,6 +26,7 @@ namespace CarCareTracker.Helper string GetAllowedFileUploadExtensions(); bool DeleteUserConfig(int userId); bool GetInvariantApi(); + bool GetServerOpenRegistration(); } public class ConfigHelper : IConfigHelper { @@ -61,6 +62,10 @@ namespace CarCareTracker.Helper var motd = CheckString("LUBELOGGER_MOTD"); return motd; } + public bool GetServerOpenRegistration() + { + return CheckBool(CheckString("LUBELOGGER_OPEN_REGISTRATION")); + } public OpenIDConfig GetOpenIDConfig() { OpenIDConfig openIdConfig = _config.GetSection("OpenIDConfig").Get() ?? new OpenIDConfig(); diff --git a/Logic/LoginLogic.cs b/Logic/LoginLogic.cs index 7a71b55..27f8e5e 100644 --- a/Logic/LoginLogic.cs +++ b/Logic/LoginLogic.cs @@ -21,6 +21,7 @@ namespace CarCareTracker.Logic OperationResponse RequestResetPassword(LoginModel credentials); OperationResponse ResetPasswordByUser(LoginModel credentials); OperationResponse ResetUserPassword(LoginModel credentials); + OperationResponse SendRegistrationToken(LoginModel credentials); UserData ValidateUserCredentials(LoginModel credentials); UserData ValidateOpenIDUser(LoginModel credentials); bool CheckIfUserIsValid(int userId); @@ -190,6 +191,16 @@ namespace CarCareTracker.Logic return OperationResponse.Failed(); } } + public OperationResponse SendRegistrationToken(LoginModel credentials) + { + if (_configHelper.GetServerOpenRegistration()) + { + return GenerateUserToken(credentials.EmailAddress, true); + } else + { + return OperationResponse.Failed("Open Registration Disabled"); + } + } /// /// Generates a token and notifies user via email so they can reset their password. /// diff --git a/Views/Login/OpenIDRegistration.cshtml b/Views/Login/OpenIDRegistration.cshtml index 42b2fd5..17dd7b6 100644 --- a/Views/Login/OpenIDRegistration.cshtml +++ b/Views/Login/OpenIDRegistration.cshtml @@ -3,6 +3,7 @@ @inject ITranslationHelper translator @{ var userLanguage = config.GetServerLanguage(); + var openRegistrationEnabled = config.GetServerOpenRegistration(); } @model string @{ @@ -17,7 +18,19 @@
- + @if (openRegistrationEnabled) + { +
+ +
+ +
+
+ } + else + { + + }
@@ -46,4 +59,14 @@ } }); } + function sendOpenIdRegistrationToken(){ + var userEmail = decodeHTMLEntities('@Model'); + $.post('/Login/SendRegistrationToken', { emailAddress: userEmail }, function (data) { + if (data.success) { + successToast(data.message); + } else { + errorToast(data.message); + } + }); + } \ No newline at end of file diff --git a/Views/Login/Registration.cshtml b/Views/Login/Registration.cshtml index 5f24494..14a0055 100644 --- a/Views/Login/Registration.cshtml +++ b/Views/Login/Registration.cshtml @@ -3,6 +3,7 @@ @inject ITranslationHelper translator @{ var userLanguage = config.GetServerLanguage(); + var openRegistrationEnabled = config.GetServerOpenRegistration(); } @{ ViewData["Title"] = "Register"; @@ -16,10 +17,19 @@
- + @if (openRegistrationEnabled) { +
+ +
+ +
+
+ } else { + + }
- +
diff --git a/wwwroot/js/login.js b/wwwroot/js/login.js index fa47b40..c4a3f56 100644 --- a/wwwroot/js/login.js +++ b/wwwroot/js/login.js @@ -67,4 +67,18 @@ function remoteLogin() { window.location.href = data; } }) +} +function sendRegistrationToken() { + var userEmail = $("#inputEmail").val(); + if (userEmail.trim() == '') { + errorToast("No Email Address Provided"); + return; + } + $.post('/Login/SendRegistrationToken', { emailAddress: userEmail }, function (data) { + if (data.success) { + successToast(data.message); + } else { + errorToast(data.message); + } + }); } \ No newline at end of file