backend complete
This commit is contained in:
@@ -22,27 +22,28 @@ public class AccountsService(IMongoDatabase db)
|
||||
return await _users.Find(u => u.Id == id).FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<bool> VerifyLoginAsync(string username, string password, CancellationToken cancellationToken = default)
|
||||
public async Task<User?> VerifyLoginAsync(string username, string password, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var user = await _users.Find(u => u.Username == username).FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if(user.IsArgon)
|
||||
return Argon2.Verify(user.PasswordHash, password);
|
||||
if(user.IsArgon && Argon2.Verify(user.PasswordHash, password))
|
||||
return user;
|
||||
|
||||
if(LegacyVerifyPassword( password, user.PasswordHash))
|
||||
{
|
||||
#if !DEBUG
|
||||
var argon2Hash = Argon2.Hash(password);
|
||||
var update = Builders<User>.Update.Set(u => u.PasswordHash, argon2Hash).Set(u => u.IsArgon, true);
|
||||
|
||||
await _users.UpdateOneAsync(u => u.Id == user.Id, update, cancellationToken: cancellationToken);
|
||||
return true;
|
||||
#endif
|
||||
return user;
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public bool LegacyVerifyPassword(string password, string passwordHash)
|
||||
public static bool LegacyVerifyPassword(string password, string passwordHash)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(passwordHash))
|
||||
return false;
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.5" />
|
||||
<PackageReference Include="MaybeError" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.4" />
|
||||
<PackageReference Include="MongoDB.Analyzer" Version="1.5.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="3.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.5" />
|
||||
<PackageReference Include="MongoDB.Analyzer" Version="2.0.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="3.4.0" />
|
||||
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="2.0.0" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -77,8 +77,9 @@ public class AobaService(IMongoDatabase db)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _gridFs.DeleteAsync(fileId, cancellationToken);
|
||||
await _media.DeleteOneAsync(m => m.MediaId == fileId, cancellationToken);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
await _gridFs.DeleteAsync(fileId, CancellationToken.None);
|
||||
await _media.DeleteOneAsync(m => m.MediaId == fileId, CancellationToken.None);
|
||||
}
|
||||
catch (GridFSFileNotFoundException)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@ public static class Extensions
|
||||
services.AddSingleton(dbClient);
|
||||
services.AddSingleton<IMongoDatabase>(db);
|
||||
services.AddSingleton<AobaService>();
|
||||
services.AddSingleton<AccountsService>();
|
||||
services.AddHostedService<AobaIndexCreationService>();
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -32,4 +32,5 @@ public class User
|
||||
id.AddClaim(new Claim(ClaimTypes.Role, Role));
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user