C
C#2d ago
heyoka955

identity server cannot login even data is saved in the database

So I created a new user in my IS and the user is successfully saved in the database but when i try to log in the account there is written unvalid try! I am not sure how to solve it. The senior developer is right now busy and i am learning new this stuff.
12 Replies
Salman
Salman2d ago
can you share the repo/code
heyoka955
heyoka9552d ago
which part of it? how the user is saved in the database?
Salman
Salman2d ago
yeah and login as well
heyoka955
heyoka9552d ago
public async Task<IActionResult> RegisterWebshopUser(WebshopUserDto webshopUser)
{
try
{
var existingUser = await this.UserManager.FindByEmailAsync(webshopUser.Email);

if (existingUser == null)
{
var user = new ApplicationUser
{
UserName = webshopUser.First + webshopUser.Last,
Email = webshopUser.Email,
RegisteredOn = DateTime.Now,
NeedToChangePassword = false,
UserType = UserTypes.WebUser,
EmailConfirmed = true,
IsEnabled = true
};
var result = await this.UserManager.CreateAsync(user, webshopUser.Password);

if (result.Succeeded)
{
await this.UserManager.AddClaimsAsync(user, new[]
{
new Claim(JwtClaimTypes.FamilyName, webshopUser.Last),
new Claim(JwtClaimTypes.GivenName, webshopUser.First)
});

}
var newUser = await this.UserManager.FindByEmailAsync(webshopUser.Email);
return Created("User created", newUser);
}
//
}
public async Task<IActionResult> RegisterWebshopUser(WebshopUserDto webshopUser)
{
try
{
var existingUser = await this.UserManager.FindByEmailAsync(webshopUser.Email);

if (existingUser == null)
{
var user = new ApplicationUser
{
UserName = webshopUser.First + webshopUser.Last,
Email = webshopUser.Email,
RegisteredOn = DateTime.Now,
NeedToChangePassword = false,
UserType = UserTypes.WebUser,
EmailConfirmed = true,
IsEnabled = true
};
var result = await this.UserManager.CreateAsync(user, webshopUser.Password);

if (result.Succeeded)
{
await this.UserManager.AddClaimsAsync(user, new[]
{
new Claim(JwtClaimTypes.FamilyName, webshopUser.Last),
new Claim(JwtClaimTypes.GivenName, webshopUser.First)
});

}
var newUser = await this.UserManager.FindByEmailAsync(webshopUser.Email);
return Created("User created", newUser);
}
//
}
i did not show the whole code because the is the most important part if you do find something then tell me the login i send i look for it
Salman
Salman2d ago
@heyoka955 can you share the login part as well
heyoka955
heyoka9552d ago
takes lil bit
Salman
Salman2d ago
register looks okay
heyoka955
heyoka9552d ago
but the login is in angular
Salman
Salman2d ago
I mean the login backend or endpoint, that'd be in c#
heyoka955
heyoka9552d ago
how can i find it at asiest? We have identityServer, our backend, IdneityManager are there keywords to look for? ?
Salman
Salman2d ago
I mean just like you shared the register method, there'd be a login method as well
heyoka955
heyoka955this hour
Solved it UserName was not same as email but do not know why it need it?
Want results from more Discord servers?
Add your server