diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index d2e048284..289974f18 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -954,7 +954,7 @@ namespace Bit.Core.Services throw new BadRequestException("You are already part of this organization."); } - if(!UserInviteTokenIsValid(_dataProtector, token, user.Email, orgUser.Id)) + if(!CoreHelpers.UserInviteTokenIsValid(_dataProtector, token, user.Email, orgUser.Id, _globalSettings)) { throw new BadRequestException("Invalid token."); } @@ -1411,31 +1411,5 @@ namespace Bit.Core.Services $"{plan.MaxAdditionalSeats.GetValueOrDefault(0)} additional users."); } } - - - - public bool UserInviteTokenIsValid(IDataProtector protector, string token, string userEmail, Guid orgUserId) - { - var invalid = true; - try - { - var unprotectedData = protector.Unprotect(token); - var dataParts = unprotectedData.Split(' '); - if(dataParts.Length == 4 && dataParts[0] == "OrganizationUserInvite" && - new Guid(dataParts[1]) == orgUserId && - dataParts[2].Equals(userEmail, StringComparison.InvariantCultureIgnoreCase)) - { - var creationTime = CoreHelpers.FromEpocMilliseconds(Convert.ToInt64(dataParts[3])); - var expTime = creationTime.AddHours(_globalSettings.OrganizationInviteExpirationHours); - invalid = expTime < DateTime.UtcNow; - } - } - catch - { - invalid = true; - } - - return !invalid; - } } } diff --git a/src/Core/Services/Implementations/UserService.cs b/src/Core/Services/Implementations/UserService.cs index 14054b516..cccf40c2e 100644 --- a/src/Core/Services/Implementations/UserService.cs +++ b/src/Core/Services/Implementations/UserService.cs @@ -250,7 +250,7 @@ namespace Bit.Core.Services if(_globalSettings.DisableUserRegistration && !string.IsNullOrWhiteSpace(token) && orgUserId.HasValue) { tokenValid = CoreHelpers.UserInviteTokenIsValid(_organizationServiceDataProtector, token, - user.Email, orgUserId.Value); + user.Email, orgUserId.Value, _globalSettings); } if(_globalSettings.DisableUserRegistration && !tokenValid) diff --git a/src/Core/Utilities/CoreHelpers.cs b/src/Core/Utilities/CoreHelpers.cs index dcf53029b..41791158d 100644 --- a/src/Core/Utilities/CoreHelpers.cs +++ b/src/Core/Utilities/CoreHelpers.cs @@ -476,5 +476,30 @@ namespace Bit.Core.Utilities { return string.Concat("Custom_", type.ToString()); } + + public static bool UserInviteTokenIsValid(IDataProtector protector, string token, string userEmail, Guid orgUserId, + GlobalSettings globalSettings) + { + var invalid = true; + try + { + var unprotectedData = protector.Unprotect(token); + var dataParts = unprotectedData.Split(' '); + if(dataParts.Length == 4 && dataParts[0] == "OrganizationUserInvite" && + new Guid(dataParts[1]) == orgUserId && + dataParts[2].Equals(userEmail, StringComparison.InvariantCultureIgnoreCase)) + { + var creationTime = FromEpocMilliseconds(Convert.ToInt64(dataParts[3])); + var expTime = creationTime.AddHours(globalSettings.OrganizationInviteExpirationHours); + invalid = expTime < DateTime.UtcNow; + } + } + catch + { + invalid = true; + } + + return !invalid; + } } }