Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
HIAST-Clinics
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
almohanad.hafez
HIAST-Clinics
Commits
66384a51
Commit
66384a51
authored
Aug 21, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add role to JWT, make controllers authorized
parent
2ea3eb22
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
7 deletions
+12
-7
Roles.cs
Clinics.Backend/Domain/Entities/Identity/UserRoles/Roles.cs
+7
-3
JWTProvider.cs
...nd/Persistence/Identity/Authentication/JWT/JWTProvider.cs
+2
-2
EmployeesController.cs
...s.Backend/Presentation/Controllers/EmployeesController.cs
+3
-2
No files found.
Clinics.Backend/Domain/Entities/Identity/UserRoles/Roles.cs
View file @
66384a51
...
@@ -4,9 +4,13 @@ public static class Roles
...
@@ -4,9 +4,13 @@ public static class Roles
{
{
#
region
Constant
values
#
region
Constant
values
public
static
int
Count
=>
3
;
public
static
int
Count
=>
3
;
public
static
Role
Admin
=>
Role
.
Create
(
1
,
"admin"
);
public
const
string
AdminName
=
"admin"
;
public
static
Role
Doctor
=>
Role
.
Create
(
2
,
"doctor"
);
public
const
string
DoctorName
=
"doctor"
;
public
static
Role
Receptionist
=>
Role
.
Create
(
3
,
"receptionist"
);
public
const
string
ReceptionistName
=
"receptionist"
;
public
static
Role
Admin
=>
Role
.
Create
(
1
,
AdminName
);
public
static
Role
Doctor
=>
Role
.
Create
(
2
,
DoctorName
);
public
static
Role
Receptionist
=>
Role
.
Create
(
3
,
ReceptionistName
);
public
static
List
<
Role
>
GetAll
()
public
static
List
<
Role
>
GetAll
()
{
{
...
...
Clinics.Backend/Persistence/Identity/Authentication/JWT/JWTProvider.cs
View file @
66384a51
...
@@ -21,8 +21,8 @@ public sealed class JWTProvider : IJWTProvider
...
@@ -21,8 +21,8 @@ public sealed class JWTProvider : IJWTProvider
{
{
var
claims
=
new
Claim
[]
var
claims
=
new
Claim
[]
{
{
new
(
JwtRegisteredClaimNames
.
Sub
,
user
.
Id
.
ToString
()
),
new
(
ClaimTypes
.
Name
,
user
.
UserName
),
new
(
JwtRegisteredClaimNames
.
UniqueName
,
user
.
UserName
),
new
(
ClaimTypes
.
Role
,
user
.
Role
.
Name
)
};
};
...
...
Clinics.Backend/Presentation/Controllers/EmployeesController.cs
View file @
66384a51
using
Application.Employees.Commands.AttachFamilyMemberToEmployee
;
using
Application.Employees.Commands.AttachFamilyMemberToEmployee
;
using
Application.Employees.Commands.CreateEmployee
;
using
Application.Employees.Commands.CreateEmployee
;
using
Domain.Entities.Identity.UserRoles
;
using
MediatR
;
using
MediatR
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
...
@@ -17,7 +18,7 @@ public class EmployeesController : ApiController
...
@@ -17,7 +18,7 @@ public class EmployeesController : ApiController
}
}
#
endregion
#
endregion
[
Authorize
]
[
Authorize
(
Roles
=
Roles
.
AdminName
)
]
[
HttpPost
]
[
HttpPost
]
public
async
Task
<
IActionResult
>
Create
([
FromBody
]
CreateEmployeeCommand
command
)
public
async
Task
<
IActionResult
>
Create
([
FromBody
]
CreateEmployeeCommand
command
)
{
{
...
@@ -26,7 +27,7 @@ public class EmployeesController : ApiController
...
@@ -26,7 +27,7 @@ public class EmployeesController : ApiController
return
HandleFailure
(
result
);
return
HandleFailure
(
result
);
return
Created
();
return
Created
();
}
}
[
Authorize
(
Roles
=
Roles
.
DoctorName
)]
[
HttpPut
(
"FamilyMembers"
)]
[
HttpPut
(
"FamilyMembers"
)]
public
async
Task
<
IActionResult
>
AttachFamilyMember
([
FromBody
]
AttachFamilyMemberToEmployeeCommand
command
)
public
async
Task
<
IActionResult
>
AttachFamilyMember
([
FromBody
]
AttachFamilyMemberToEmployeeCommand
command
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment