Feature/Auth: last one was authentication, this one is authorization #4
@@ -27,7 +27,7 @@ public class AuthController : ControllerBase {
|
|||||||
|
|
||||||
[HttpPost("register")]
|
[HttpPost("register")]
|
||||||
public async Task<ActionResult> Register(RegisterDto dto) {
|
public async Task<ActionResult> Register(RegisterDto dto) {
|
||||||
var user = new User {
|
User user = new User {
|
||||||
UserName = dto.UserName,
|
UserName = dto.UserName,
|
||||||
Email = dto.Email,
|
Email = dto.Email,
|
||||||
CreatedAt = DateTime.UtcNow // yeah why not utc
|
CreatedAt = DateTime.UtcNow // yeah why not utc
|
||||||
|
|||||||
@@ -32,12 +32,7 @@ public class UsersController : ControllerBase {
|
|||||||
foreach(User user in rawArray) {
|
foreach(User user in rawArray) {
|
||||||
// TODO: can you operator overload a cast? if so cast<UserDto>(UserDto) would go hard
|
// TODO: can you operator overload a cast? if so cast<UserDto>(UserDto) would go hard
|
||||||
// if not then just a new custom cast function that returns a dto type will do
|
// if not then just a new custom cast function that returns a dto type will do
|
||||||
UserDto newDto = new UserDto{
|
UserDto newDto = new UserDto(user);
|
||||||
CreatedAt = user.CreatedAt,
|
|
||||||
Email = user.Email,
|
|
||||||
Id = user.Id,
|
|
||||||
UserName = user.UserName
|
|
||||||
};
|
|
||||||
dtoArray.Add(newDto);
|
dtoArray.Add(newDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,12 +47,7 @@ public class UsersController : ControllerBase {
|
|||||||
|
|
||||||
if (user == null) return NotFound();
|
if (user == null) return NotFound();
|
||||||
|
|
||||||
UserDto newDto = new UserDto{
|
UserDto newDto = new UserDto(user);
|
||||||
CreatedAt = user.CreatedAt,
|
|
||||||
Email = user.Email,
|
|
||||||
Id = user.Id,
|
|
||||||
UserName = user.UserName
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(newDto);
|
return Ok(newDto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,17 @@ public class LoginDto {
|
|||||||
public class UserDto {
|
public class UserDto {
|
||||||
|
|
||||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; // gets compressed to a string'
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; // gets compressed to a string'
|
||||||
public List<string> permissions { get; set; } = [];
|
public List<string>? Permissions { get; set; } = [];
|
||||||
public string? Email { get; set; } = "";
|
public string? Email { get; set; } = "";
|
||||||
public string Id { get; set; } = "";
|
public string Id { get; set; } = "";
|
||||||
public string? UserName { get; set; } = "";
|
public string? UserName { get; set; } = "";
|
||||||
|
|
||||||
|
public UserDto(User user) {
|
||||||
|
CreatedAt = user.CreatedAt;
|
||||||
|
Email = user.Email;
|
||||||
|
Id = user.Id;
|
||||||
|
UserName = user.UserName;
|
||||||
|
Permissions = user.Permissions;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user