Open Kenjiang110 opened 3 months ago
hi
You can try to call the SaveChangesAsync(commit the transaction)
var userName = "test";
var email = "[test@test.com](mailto:test@test.com)";
var user = new IdentityUser(GuidGenerator.Create(), userName, email, CurrentTenant.Id);
await UserManager.CreateAsync(user);
await unitOfWorkManager.Current.SaveChangesAsync();
user = new IdentityUser(GuidGenerator.Create(), userName, email, CurrentTenant.Id);
await UserManager.CreateAsync(user);
await unitOfWorkManager.Current.SaveChangesAsync();
The code I provided is just to reproduce the problem. Sorry for the confusion. My real scenario is calling the method below from a client, so the UnitOfWork will commit automatically?
[UnitOfWork]
protected virtual async Task
return user;
}
Please share steps and code to reproduce.
1)Create a new solution using "MYSQL": abp new Acme.BookStore -dbms MySQL -m none --theme leptonx-lite -csf
2)Add IDemoAppService.cs to project Application.Contracts: public interface IDemoAppService: IApplicationService { Task CreateUserAsync(); }
3)Add DemoAppService.cs to project Application:
namespace Acme.BookStore
{
public class DemoAppService : BookStoreAppService, IDemoAppService
{
protected IdentityUserManager UserManager => LazyServiceProvider.LazyGetRequiredService
[UnitOfWork]
public async Task CreateUserAsync()
{
var userName = $"wx_01";
var user = await UserManager.FindByNameAsync(userName);
if (user == null)
{
var email = ***@***.***";
user = new IdentityUser(GuidGenerator.Create(), userName, email, CurrentTenant.Id)
{
Name = userName
};
await UserManager.CreateAsync(user);
}
}
}
} 4)Add button "Demo" to Pages/Index.cshtml @if (!CurrentUser.IsAuthenticated) { @L["Login"] } else {
}
5) Edit Pages/index.js, add click handler to button "Demo". $(function () { abp.log.debug('Index.js initialized!');
$("#demo").click(function () {
acme.bookStore.demo.createUser();
acme.bookStore.demo.createUser();
});
}); 6)Run project Web, login, click the button "Demo". 7)Goto page "Users"
@.***
From: maliming Date: 2024-08-07 16:06 To: abpframework/abp CC: Kenjiang110; Author Subject: Re: [abpframework/abp] UserName should be unique. (Issue #20418) Please share steps and code to reproduce. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
Hi, do you know if this issue is still open?
It still looks open, but I don't think it will be handled because the bug is almost impossible to trigger under normal circumstances.
@.***
From: Milos Pantelic Date: 2024-08-27 07:07 To: abpframework/abp CC: Kenjiang110; Author Subject: Re: [abpframework/abp] UserName should be unique. (Issue #20418) Hi, do you know if this issue is still open? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
Is there an existing issue for this?
Description
You can use IdentityUserManager to create two users have same username and email.
Reproduction Steps
var userName = "test"; var email = "test@test.com"; var user = new IdentityUser(GuidGenerator.Create(), userName, email, CurrentTenant.Id); await UserManager.CreateAsync(user); user = new IdentityUser(GuidGenerator.Create(), userName, email, CurrentTenant.Id); await UserManager.CreateAsync(user);
Expected behavior
Second "UserManager.CreateAsync(user)" should throw an exception becasue of duplicated userName.
Actual behavior
Two users with same userName and email have been created.
Regression?
No response
Known Workarounds
No response
Version
8.2.0
User Interface
Common (Default)
Database Provider
EF Core (Default)
Tiered or separate authentication server
None (Default)
Operation System
Windows (Default)
Other information
No response