Added roles (may or may not be used)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using AipsCore.Domain.Models.User.External;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace AipsCore.Infrastructure.Persistence.Db;
|
||||
|
||||
public static class DbInitializer
|
||||
{
|
||||
public static async Task SeedRolesAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
var roleManager = scope.ServiceProvider.GetRequiredService<RoleManager<IdentityRole<Guid>>>();
|
||||
|
||||
var roleNames = UserRole.All();
|
||||
|
||||
foreach (var roleName in roleNames)
|
||||
{
|
||||
var roleExist = await roleManager.RoleExistsAsync(roleName.Name);
|
||||
if (!roleExist)
|
||||
{
|
||||
await roleManager.CreateAsync(new IdentityRole<Guid>
|
||||
{
|
||||
Name = roleName.Name,
|
||||
NormalizedName = roleName.Name.ToUpperInvariant()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,8 +65,7 @@ public class UserRepository : AbstractRepository<Domain.Models.User.User, UserId
|
||||
throw new Exception($"User registration failed: {errors}");
|
||||
}
|
||||
|
||||
//Realno nebitno, ali postoji infrastruktura ako treba da se koristi kasnije
|
||||
//await _userManager.AddToRoleAsync(entity, "User");
|
||||
await _userManager.AddToRoleAsync(entity, UserRole.User.Name);
|
||||
}
|
||||
|
||||
public async Task<LoginResult> LoginWithEmailAndPasswordAsync(string email, string password, CancellationToken cancellationToken = default)
|
||||
|
||||
Reference in New Issue
Block a user