@@ -379,12 +379,12 @@ protected internal bool MobilePhoneExistsOtherThan(TAccount account, string phon
379379 return false ;
380380 }
381381
382- public virtual TAccount CreateAccount ( string username , string password , string email )
382+ public virtual TAccount CreateAccount ( string username , string password , string email , Guid ? id = null , DateTime ? dateCreated = null )
383383 {
384- return CreateAccount ( null , username , password , email ) ;
384+ return CreateAccount ( null , username , password , email , id , dateCreated ) ;
385385 }
386386
387- public virtual TAccount CreateAccount ( string tenant , string username , string password , string email )
387+ public virtual TAccount CreateAccount ( string tenant , string username , string password , string email , Guid ? id = null , DateTime ? dateCreated = null )
388388 {
389389 if ( Configuration . EmailIsUsername )
390390 {
@@ -401,7 +401,7 @@ public virtual TAccount CreateAccount(string tenant, string username, string pas
401401 Tracing . Information ( "[UserAccountService.CreateAccount] called: {0}, {1}, {2}" , tenant , username , email ) ;
402402
403403 var account = this . userRepository . Create ( ) ;
404- Init ( account , tenant , username , password , email ) ;
404+ Init ( account , tenant , username , password , email , id , dateCreated ) ;
405405
406406 ValidateEmail ( account , email ) ;
407407 ValidateUsername ( account , username ) ;
@@ -414,7 +414,7 @@ public virtual TAccount CreateAccount(string tenant, string username, string pas
414414 return account ;
415415 }
416416
417- protected void Init ( TAccount account , string tenant , string username , string password , string email )
417+ protected void Init ( TAccount account , string tenant , string username , string password , string email , Guid ? id = null , DateTime ? dateCreated = null )
418418 {
419419 Tracing . Information ( "[UserAccountService.Init] called" ) ;
420420
@@ -448,15 +448,22 @@ protected void Init(TAccount account, string tenant, string username, string pas
448448 throw new Exception ( "Can't call Init if UserAccount is already assigned an ID" ) ;
449449 }
450450
451- account . ID = Guid . NewGuid ( ) ;
451+ var now = UtcNow ;
452+ if ( dateCreated > now )
453+ {
454+ Tracing . Error ( "[UserAccountService.Init] failed -- date created in the future" ) ;
455+ throw new Exception ( "dateCreated can't be in the future" ) ;
456+ }
457+
458+ account . ID = id ?? Guid . NewGuid ( ) ;
452459 account . Tenant = tenant ;
453460 account . Username = username ;
454461 account . Email = email ;
455- account . Created = UtcNow ;
456- account . LastUpdated = account . Created ;
462+ account . Created = dateCreated ?? now ;
463+ account . LastUpdated = now ;
457464 account . HashedPassword = password != null ?
458465 Configuration . Crypto . HashPassword ( password , this . Configuration . PasswordHashingIterationCount ) : null ;
459- account . PasswordChanged = password != null ? account . Created : ( DateTime ? ) null ;
466+ account . PasswordChanged = password != null ? now : ( DateTime ? ) null ;
460467 account . IsAccountVerified = false ;
461468 account . AccountTwoFactorAuthMode = TwoFactorAuthMode . None ;
462469 account . CurrentTwoFactorAuthStatus = TwoFactorAuthMode . None ;
0 commit comments