From 2f7da902c9afeb3df31f59fa6c16223990f51eb6 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 14 Dec 2022 10:38:08 +0100 Subject: feat: Working email validation --- .../Internal/Account/CreateAccountRoute.cs | 10 ++++---- .../Internal/Account/CreateInitialAccountRoute.cs | 2 +- .../src/Endpoints/Internal/Account/LoginRoute.cs | 4 +--- .../Internal/Account/UpdateAccountRoute.cs | 2 -- .../CreateResetRequestRoute.cs | 2 -- .../FulfillResetRequestRoute.cs | 2 -- .../src/Endpoints/Internal/Root/ValidateRoute.cs | 28 ++++++++++++++++------ .../Endpoints/V1/Customers/CreateCustomerRoute.cs | 2 -- .../Endpoints/V1/Projects/CreateProjectRoute.cs | 2 -- 9 files changed, 28 insertions(+), 26 deletions(-) (limited to 'code/api/src/Endpoints') diff --git a/code/api/src/Endpoints/Internal/Account/CreateAccountRoute.cs b/code/api/src/Endpoints/Internal/Account/CreateAccountRoute.cs index c114bb8..a145c38 100644 --- a/code/api/src/Endpoints/Internal/Account/CreateAccountRoute.cs +++ b/code/api/src/Endpoints/Internal/Account/CreateAccountRoute.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.Localization; - namespace IOL.GreatOffice.Api.Endpoints.Internal.Account; public class CreateAccountRoute : RouteBaseAsync.WithRequest.WithActionResult @@ -7,11 +5,13 @@ public class CreateAccountRoute : RouteBaseAsync.WithRequest _localizer; + private readonly EmailValidationService _emailValidation; - public CreateAccountRoute(UserService userService, MainAppDatabase database, IStringLocalizer localizer) { + public CreateAccountRoute(UserService userService, MainAppDatabase database, IStringLocalizer localizer, EmailValidationService emailValidation) { _userService = userService; _database = database; _localizer = localizer; + _emailValidation = emailValidation; } public class Payload @@ -45,8 +45,8 @@ public class CreateAccountRoute : RouteBaseAsync.WithRequest _userService.SendValidationEmail(user), cancellationToken); + await _userService.LogInUserAsync(HttpContext, user); + await _emailValidation.SendValidationEmailAsync(user); return Ok(); } } \ No newline at end of file diff --git a/code/api/src/Endpoints/Internal/Account/CreateInitialAccountRoute.cs b/code/api/src/Endpoints/Internal/Account/CreateInitialAccountRoute.cs index 56ff9c6..01cad3f 100644 --- a/code/api/src/Endpoints/Internal/Account/CreateInitialAccountRoute.cs +++ b/code/api/src/Endpoints/Internal/Account/CreateInitialAccountRoute.cs @@ -26,7 +26,7 @@ public class CreateInitialAccountRoute : RouteBaseAsync.WithoutRequest.WithActio user.HashAndSetPassword("ivar123"); _database.Users.Add(user); await _database.SaveChangesAsync(cancellationToken); - await _userService.LogInUser(HttpContext, user); + await _userService.LogInUserAsync(HttpContext, user); return Redirect("/"); } } \ No newline at end of file diff --git a/code/api/src/Endpoints/Internal/Account/LoginRoute.cs b/code/api/src/Endpoints/Internal/Account/LoginRoute.cs index eaebc2a..8a3dff4 100644 --- a/code/api/src/Endpoints/Internal/Account/LoginRoute.cs +++ b/code/api/src/Endpoints/Internal/Account/LoginRoute.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.Localization; - namespace IOL.GreatOffice.Api.Endpoints.Internal.Account; public class LoginRoute : RouteBaseAsync.WithRequest.WithActionResult @@ -29,7 +27,7 @@ public class LoginRoute : RouteBaseAsync.WithRequest.WithAct return KnownProblem(_localizer["Invalid username or password"]); } - await _userService.LogInUser(HttpContext, user, request.Persist); + await _userService.LogInUserAsync(HttpContext, user, request.Persist); return Ok(); } } \ No newline at end of file diff --git a/code/api/src/Endpoints/Internal/Account/UpdateAccountRoute.cs b/code/api/src/Endpoints/Internal/Account/UpdateAccountRoute.cs index c75e750..1081240 100644 --- a/code/api/src/Endpoints/Internal/Account/UpdateAccountRoute.cs +++ b/code/api/src/Endpoints/Internal/Account/UpdateAccountRoute.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.Localization; - namespace IOL.GreatOffice.Api.Endpoints.Internal.Account; public class UpdateAccountRoute : RouteBaseAsync.WithRequest.WithActionResult diff --git a/code/api/src/Endpoints/Internal/PasswordResetRequests/CreateResetRequestRoute.cs b/code/api/src/Endpoints/Internal/PasswordResetRequests/CreateResetRequestRoute.cs index 9a22ab3..c6ed417 100644 --- a/code/api/src/Endpoints/Internal/PasswordResetRequests/CreateResetRequestRoute.cs +++ b/code/api/src/Endpoints/Internal/PasswordResetRequests/CreateResetRequestRoute.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.Localization; - namespace IOL.GreatOffice.Api.Endpoints.Internal.PasswordResetRequests; public class CreateResetRequestRoute : RouteBaseAsync.WithRequest.WithActionResult diff --git a/code/api/src/Endpoints/Internal/PasswordResetRequests/FulfillResetRequestRoute.cs b/code/api/src/Endpoints/Internal/PasswordResetRequests/FulfillResetRequestRoute.cs index 8c7ce03..a8797b8 100644 --- a/code/api/src/Endpoints/Internal/PasswordResetRequests/FulfillResetRequestRoute.cs +++ b/code/api/src/Endpoints/Internal/PasswordResetRequests/FulfillResetRequestRoute.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.Localization; - namespace IOL.GreatOffice.Api.Endpoints.Internal.PasswordResetRequests; public class FulfillResetRequestRoute : RouteBaseAsync.WithRequest.WithActionResult diff --git a/code/api/src/Endpoints/Internal/Root/ValidateRoute.cs b/code/api/src/Endpoints/Internal/Root/ValidateRoute.cs index 428a1a2..8f0882d 100644 --- a/code/api/src/Endpoints/Internal/Root/ValidateRoute.cs +++ b/code/api/src/Endpoints/Internal/Root/ValidateRoute.cs @@ -2,13 +2,15 @@ namespace IOL.GreatOffice.Api.Endpoints.Internal.Root; public class ValidateRoute : RouteBaseSync.WithRequest.WithActionResult { - private readonly UserService _userService; - private readonly string _continueTo; + private readonly EmailValidationService _emailValidation; + private readonly string CanonicalFrontendUrl; + private readonly ILogger _logger; - public ValidateRoute(UserService userService, VaultService vaultService) { - _userService = userService; + public ValidateRoute(VaultService vaultService, EmailValidationService emailValidation, ILogger logger) { + _emailValidation = emailValidation; + _logger = logger; var c = vaultService.GetCurrentAppConfiguration(); - _continueTo = c.CANONICAL_FRONTEND_URL + "/portal?msg=emailValidated"; + CanonicalFrontendUrl = c.CANONICAL_FRONTEND_URL; } public class QueryParams @@ -19,7 +21,19 @@ public class ValidateRoute : RouteBaseSync.WithRequest + +

The validation could not be completed

+

We are working on fixing this, in the meantime, have patience.

+Click here to go back to {CanonicalFrontendUrl} + +"""); + } + + return Redirect(CanonicalFrontendUrl + "/portal?msg=emailValidated"); } } \ No newline at end of file diff --git a/code/api/src/Endpoints/V1/Customers/CreateCustomerRoute.cs b/code/api/src/Endpoints/V1/Customers/CreateCustomerRoute.cs index b20b404..e58aa37 100644 --- a/code/api/src/Endpoints/V1/Customers/CreateCustomerRoute.cs +++ b/code/api/src/Endpoints/V1/Customers/CreateCustomerRoute.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.Localization; - namespace IOL.GreatOffice.Api.Endpoints.V1.Customers; public class CreateCustomerRoute : RouteBaseAsync.WithRequest.WithActionResult diff --git a/code/api/src/Endpoints/V1/Projects/CreateProjectRoute.cs b/code/api/src/Endpoints/V1/Projects/CreateProjectRoute.cs index 04a3a9a..795422a 100644 --- a/code/api/src/Endpoints/V1/Projects/CreateProjectRoute.cs +++ b/code/api/src/Endpoints/V1/Projects/CreateProjectRoute.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.Localization; - namespace IOL.GreatOffice.Api.Endpoints.V1.Projects; public class CreateProjectRoute : RouteBaseAsync.WithRequest.WithActionResult -- cgit v1.3