fix: add transaction to avoid not updating the password
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 2s
Build, Package and Push Images / build (push) Successful in 28s
Build, Package and Push Images / sonarqube (push) Has been skipped
Build, Package and Push Images / sbom-scan (push) Successful in 33s
Build, Package and Push Images / container-build (push) Successful in 3m6s
Build, Package and Push Images / container-sbom-scan (push) Successful in 39s
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 2s
Build, Package and Push Images / build (push) Successful in 28s
Build, Package and Push Images / sonarqube (push) Has been skipped
Build, Package and Push Images / sbom-scan (push) Successful in 33s
Build, Package and Push Images / container-build (push) Successful in 3m6s
Build, Package and Push Images / container-sbom-scan (push) Successful in 39s
This commit is contained in:
parent
497d415fb6
commit
dc7daaef5c
2 changed files with 28 additions and 10 deletions
|
@ -28,6 +28,8 @@ insert_final_newline = true
|
|||
indent_size = 4
|
||||
dotnet_sort_system_directives_first = true
|
||||
|
||||
MA0004.report = DetectContext # (default) Try to detect the current context and report only if it considers ConfigureAwait is needed
|
||||
MA0004.report = Always # Always report missing ConfigureAwait whatever the context
|
||||
# Don't use this. qualifier
|
||||
dotnet_style_qualification_for_field = false:suggestion
|
||||
dotnet_style_qualification_for_property = false:suggestion
|
||||
|
|
|
@ -43,10 +43,17 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
|||
if (account == null)
|
||||
{
|
||||
if (this._configuration.GetSection("Testing").GetValue<bool>("CreateAccountOnLogin"))
|
||||
{
|
||||
var transaction =
|
||||
await _wonderkingContext.Database.BeginTransactionAsync().ConfigureAwait(true);
|
||||
await using (transaction.ConfigureAwait(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
argon2Id.Salt = RandomNumberGenerator.GetBytes(16);
|
||||
var finalAccount =
|
||||
await this._wonderkingContext.Accounts.AddAsync(new Account(packet.Username, Array.Empty<byte>(), "",
|
||||
await this._wonderkingContext.Accounts.AddAsync(new Account(packet.Username,
|
||||
Array.Empty<byte>(), "",
|
||||
0, argon2Id.Salt)).ConfigureAwait(true);
|
||||
await this._wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
|
||||
argon2Id.AssociatedData = finalAccount.Entity.Id.ToByteArray();
|
||||
|
@ -54,6 +61,15 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
|||
this._wonderkingContext.Accounts.Update(finalAccount.Entity);
|
||||
loginResponseReason = LoginResponseReason.Ok;
|
||||
await this._wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
|
||||
|
||||
await transaction.CommitAsync().ConfigureAwait(true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await transaction.RollbackAsync().ConfigureAwait(true); // Rollback the transaction on error
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue