I have created User, UserOperationClaim, OperationClaim tables for using Authentication:
public class User : IEntity { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } public byte[] PasswordSalt { get; set; } public byte[] PasswordHash { get; set; } public bool Status { get; set; } public ICollection<UserOperationClaim> UserOperationClaims { get; set; } }
public class UserOperationClaim { public int Id { get; set; } public int UserId { get; set; } public int OperationClaimId { get; set; } public User User { get; set; } public OperationClaim OperationClaims { get; set; } }
`
public class OperationClaim
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection UserOperationClaims { get; set; }
}
`
I have created login & register controller:
`
[HttpPost(“login”)]
public ActionResult Login(UserForLoginDto userForLoginDto)
{
var userToLogin = _authService.Login(userForLoginDto);
if(!userToLogin.IsSuccess)
{
return BadRequest(userToLogin.Message);
}
var result = _authService.CreateAccessToken(userToLogin.Data);
if(result.IsSuccess)
{
return Ok(result);
}
return BadRequest(result.Message);
}
[HttpPost("register")]
public ActionResult Register(UserForRegisterDto userForRegisterDto)
{
var userExists = _authService.UserExists(userForRegisterDto.Email);
if(!userExists.IsSuccess)
{
return BadRequest(userExists.Message);
}
var registerResult = _authService.Register(userForRegisterDto);
var result = _authService.CreateAccessToken(registerResult.Data);
if(result.IsSuccess)
{
return Ok(result.Data);
}
return BadRequest(result.Message);
}`
but i didn’t know what to do and how, can someone explain that?
When i tried login & register. Its output successful. But when i add product unauthorize & i can’t see who has what authority to add products
Haktan Özyaşar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.