1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

allow org user reg. when reg. is disabled

This commit is contained in:
Kyle Spearrin
2018-05-24 16:53:07 -04:00
parent 1b1ec7629b
commit 72e95e2a98
6 changed files with 49 additions and 26 deletions

View File

@ -13,6 +13,7 @@ using System.Text.RegularExpressions;
using Dapper;
using System.Globalization;
using System.Web;
using Microsoft.AspNetCore.DataProtection;
namespace Bit.Core.Utilities
{
@ -452,5 +453,29 @@ namespace Bit.Core.Utilities
}
return new Uri(string.Format("{0}?{1}", baseUri, queryCollection), uriKind);
}
public static 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 = FromEpocMilliseconds(Convert.ToInt64(dataParts[3]));
invalid = creationTime.AddDays(5) < DateTime.UtcNow;
}
}
catch
{
invalid = true;
}
return !invalid;
}
}
}