1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-10 23:58:13 -05:00

allow user registration for sso ()

This commit is contained in:
Kyle Spearrin 2020-08-13 17:30:10 -04:00 committed by GitHub
parent 4d8090d75e
commit cd926ca8f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 6 deletions
src
Core/Services
Sql/dbo/Tables
util/Migrator/DbScripts

@ -19,6 +19,7 @@ namespace Bit.Core.Services
Task<DateTime> GetAccountRevisionDateByIdAsync(Guid userId); Task<DateTime> GetAccountRevisionDateByIdAsync(Guid userId);
Task SaveUserAsync(User user, bool push = false); Task SaveUserAsync(User user, bool push = false);
Task<IdentityResult> RegisterUserAsync(User user, string masterPassword, string token, Guid? orgUserId); Task<IdentityResult> RegisterUserAsync(User user, string masterPassword, string token, Guid? orgUserId);
Task<IdentityResult> RegisterUserAsync(User user);
Task SendMasterPasswordHintAsync(string email); Task SendMasterPasswordHintAsync(string email);
Task SendTwoFactorEmailAsync(User user); Task SendTwoFactorEmailAsync(User user);
Task<bool> VerifyTwoFactorEmailAsync(User user, string token); Task<bool> VerifyTwoFactorEmailAsync(User user, string token);

@ -293,8 +293,19 @@ namespace Bit.Core.Services
if (result == IdentityResult.Success) if (result == IdentityResult.Success)
{ {
await _mailService.SendWelcomeEmailAsync(user); await _mailService.SendWelcomeEmailAsync(user);
await _referenceEventService.RaiseEventAsync( await _referenceEventService.RaiseEventAsync(new ReferenceEvent(ReferenceEventType.Signup, user));
new ReferenceEvent(ReferenceEventType.Signup, user)); }
return result;
}
public async Task<IdentityResult> RegisterUserAsync(User user)
{
var result = await base.CreateAsync(user);
if (result == IdentityResult.Success)
{
await _mailService.SendWelcomeEmailAsync(user);
await _referenceEventService.RaiseEventAsync(new ReferenceEvent(ReferenceEventType.Signup, user));
} }
return result; return result;
@ -567,7 +578,7 @@ namespace Bit.Core.Services
Logger.LogWarning("Change password failed for user {userId}.", user.Id); Logger.LogWarning("Change password failed for user {userId}.", user.Id);
return IdentityResult.Failed(_identityErrorDescriber.PasswordMismatch()); return IdentityResult.Failed(_identityErrorDescriber.PasswordMismatch());
} }
public async Task<IdentityResult> SetPasswordAsync(User user, string newMasterPassword, string key) public async Task<IdentityResult> SetPasswordAsync(User user, string newMasterPassword, string key)
{ {
if (user == null) if (user == null)
@ -580,7 +591,7 @@ namespace Bit.Core.Services
Logger.LogWarning("Change password failed for user {userId} - already has password.", user.Id); Logger.LogWarning("Change password failed for user {userId} - already has password.", user.Id);
return IdentityResult.Failed(_identityErrorDescriber.UserAlreadyHasPassword()); return IdentityResult.Failed(_identityErrorDescriber.UserAlreadyHasPassword());
} }
var result = await UpdatePasswordHash(user, newMasterPassword); var result = await UpdatePasswordHash(user, newMasterPassword);
if (!result.Succeeded) if (!result.Succeeded)
{ {
@ -807,7 +818,7 @@ namespace Bit.Core.Services
PlanName = PremiumPlanId, PlanName = PremiumPlanId,
}); });
} }
catch when(!_globalSettings.SelfHosted) catch when (!_globalSettings.SelfHosted)
{ {
await paymentService.CancelAndRecoverChargesAsync(user); await paymentService.CancelAndRecoverChargesAsync(user);
throw; throw;

@ -3,7 +3,7 @@
[Name] NVARCHAR (50) NULL, [Name] NVARCHAR (50) NULL,
[Email] NVARCHAR (50) NOT NULL, [Email] NVARCHAR (50) NOT NULL,
[EmailVerified] BIT NOT NULL, [EmailVerified] BIT NOT NULL,
[MasterPassword] NVARCHAR (300) NOT NULL, [MasterPassword] NVARCHAR (300) NULL,
[MasterPasswordHint] NVARCHAR (50) NULL, [MasterPasswordHint] NVARCHAR (50) NULL,
[Culture] NVARCHAR (10) NOT NULL, [Culture] NVARCHAR (10) NOT NULL,
[SecurityStamp] NVARCHAR (50) NOT NULL, [SecurityStamp] NVARCHAR (50) NOT NULL,

@ -0,0 +1,19 @@
ALTER TABLE
[dbo].[User]
ALTER COLUMN
[MasterPassword] NVARCHAR (300) NULL
GO
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'UserView')
BEGIN
DROP VIEW [dbo].[UserView]
END
GO
CREATE VIEW [dbo].[UserView]
AS
SELECT
*
FROM
[dbo].[User]
GO