mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
back to corehelpers
This commit is contained in:
parent
6ab2f4ff87
commit
ad7c4b89c4
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user