-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
127 additions
and
99 deletions.
There are no files selected for viewing
14 changes: 7 additions & 7 deletions
14
...e/ChangePassword/ChangePasswordRequest.cs → ...ion/DTOs/Profile/ChangePasswordRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
namespace Application.DTOs.Profile.ChangePassword; | ||
|
||
public class ChangePasswordRequest | ||
{ | ||
public string UserId { get; set; } = string.Empty; | ||
public string CurrentPassword { get; set; } = string.Empty; | ||
public string NewPassword { get; set; } = string.Empty; | ||
namespace Application.DTOs.Profile; | ||
|
||
public class ChangePasswordRequest | ||
{ | ||
public string UserId { get; set; } = string.Empty; | ||
public string CurrentPassword { get; set; } = string.Empty; | ||
public string NewPassword { get; set; } = string.Empty; | ||
} |
2 changes: 1 addition & 1 deletion
2
...DTOs/User/ChangeRole/ChangeRoleRequest.cs → ...pplication/DTOs/User/ChangeRoleRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tion/DTOs/User/GetUser/GetUserResponse.cs → src/Application/DTOs/User/GetUserResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Application.DTOs.Identity.GetUser; | ||
namespace Application.DTOs.User; | ||
|
||
public class GetUserResponse | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
src/Web/Identity/Claims.cs → src/Web/AccessControl/Claims.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
namespace Web.Identity; | ||
|
||
public static class Claims | ||
{ | ||
public const string UserId = nameof(UserId); | ||
public const string Role = nameof(Role); | ||
namespace Web.AccessControl; | ||
|
||
public static class Claims | ||
{ | ||
public const string UserId = nameof(UserId); | ||
public const string Role = nameof(Role); | ||
} |
68 changes: 34 additions & 34 deletions
68
src/Web/Identity/RequiresClaimAttribute.cs → ...b/AccessControl/RequiresClaimAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace Web.Identity; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public class RequiresAnyRoleAttribute : Attribute, IAuthorizationFilter | ||
{ | ||
private readonly string _claimName; | ||
private readonly string[] _roles; | ||
|
||
public RequiresAnyRoleAttribute(string claimName, params string[] roles) | ||
{ | ||
_claimName = claimName; | ||
_roles = roles; | ||
} | ||
|
||
public void OnAuthorization(AuthorizationFilterContext context) | ||
{ | ||
var user = context.HttpContext.User; | ||
|
||
if (user.Identity is { IsAuthenticated: false }) | ||
{ | ||
context.Result = new UnauthorizedResult(); | ||
return; | ||
} | ||
|
||
var hasRequiredRole = _roles.Any(role => user.HasClaim(_claimName, role)); | ||
|
||
if (!hasRequiredRole) | ||
{ | ||
context.Result = new ForbidResult(); | ||
} | ||
} | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace Web.AccessControl; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public class RequiresAnyRoleAttribute : Attribute, IAuthorizationFilter | ||
{ | ||
private readonly string _claimName; | ||
private readonly string[] _roles; | ||
|
||
public RequiresAnyRoleAttribute(string claimName, params string[] roles) | ||
{ | ||
_claimName = claimName; | ||
_roles = roles; | ||
} | ||
|
||
public void OnAuthorization(AuthorizationFilterContext context) | ||
{ | ||
var user = context.HttpContext.User; | ||
|
||
if (user.Identity is { IsAuthenticated: false }) | ||
{ | ||
context.Result = new UnauthorizedResult(); | ||
return; | ||
} | ||
|
||
var hasRequiredRole = _roles.Any(role => user.HasClaim(_claimName, role)); | ||
|
||
if (!hasRequiredRole) | ||
{ | ||
context.Result = new ForbidResult(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/Web/DTOs/User/Login/UserLoggedInDto.cs → src/Web/DTOs/User/Login/LoginResponseDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/Web/DTOs/User/Signup/UserSignedUpDto.cs → ...Web/DTOs/User/Signup/SignupResponseDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.