From 5b511325cea098b93b81d15aca3d7ea83e49be18 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sat, 11 Feb 2023 23:57:59 +0300 Subject: [PATCH 01/27] JwtBearer nuget --- Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj index 240ce06..b52aa45 100644 --- a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj +++ b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj @@ -9,6 +9,7 @@ + From 3e3a19c9e755dd55a05f7c2aa0edce4449ed1163 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sat, 11 Feb 2023 23:58:25 +0300 Subject: [PATCH 02/27] controllers --- .../Controllers/ApplicationServicesController.cs | 12 ++++++++++++ .../HyBe.WebAPI/Controllers/AuthController.cs | 12 ++++++++++++ .../Controllers/AuthorizationEndpointsController.cs | 12 ++++++++++++ .../HyBe.WebAPI/Controllers/RolesController.cs | 12 ++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs create mode 100644 Presentation/HyBe.WebAPI/Controllers/AuthController.cs create mode 100644 Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs create mode 100644 Presentation/HyBe.WebAPI/Controllers/RolesController.cs diff --git a/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs new file mode 100644 index 0000000..6054d17 --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.WebAPI.Controllers +{ + public class ApplicationServicesController + { + + } +} \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs new file mode 100644 index 0000000..ad12ea7 --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.WebAPI.Controllers +{ + public class AuthController + { + + } +} \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs new file mode 100644 index 0000000..847c755 --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.WebAPI.Controllers +{ + public class AuthorizationEndpointsController + { + + } +} \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/RolesController.cs b/Presentation/HyBe.WebAPI/Controllers/RolesController.cs new file mode 100644 index 0000000..f2f74a0 --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/RolesController.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.WebAPI.Controllers +{ + public class RolesController + { + + } +} \ No newline at end of file From e2227c680ccfef7f0c3b2aebd92f7c7a7568d3a6 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sat, 11 Feb 2023 23:59:23 +0300 Subject: [PATCH 03/27] user controller --- .../HyBe.WebAPI/Controllers/UsersController.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Presentation/HyBe.WebAPI/Controllers/UsersController.cs diff --git a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs new file mode 100644 index 0000000..5c88e24 --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.WebAPI.Controllers +{ + public class UsersController + { + + } +} \ No newline at end of file From a3ce56d2dc3c8842ee2a640975c8ff77c6aaf96c Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:00:43 +0300 Subject: [PATCH 04/27] auth,role,user services --- .../HyBe.Persistence/Services/AuthService.cs | 12 ++++++++++++ .../HyBe.Persistence/Services/RoleService.cs | 12 ++++++++++++ .../HyBe.Persistence/Services/UserService.cs | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 Infrastructure/HyBe.Persistence/Services/AuthService.cs create mode 100644 Infrastructure/HyBe.Persistence/Services/RoleService.cs create mode 100644 Infrastructure/HyBe.Persistence/Services/UserService.cs diff --git a/Infrastructure/HyBe.Persistence/Services/AuthService.cs b/Infrastructure/HyBe.Persistence/Services/AuthService.cs new file mode 100644 index 0000000..345b45f --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Services/AuthService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Persistence.Services +{ + public class AuthService + { + + } +} \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/RoleService.cs b/Infrastructure/HyBe.Persistence/Services/RoleService.cs new file mode 100644 index 0000000..c559e4e --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Services/RoleService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Persistence.Services +{ + public class RoleService + { + + } +} \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/UserService.cs b/Infrastructure/HyBe.Persistence/Services/UserService.cs new file mode 100644 index 0000000..ec5186a --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Services/UserService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Persistence.Services +{ + public class UserService + { + + } +} \ No newline at end of file From 341ce5cb607480c8f02d91c31841979ed333be46 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:01:17 +0300 Subject: [PATCH 05/27] other services --- .../HyBe.Infrastructure/Services/MailService.cs | 12 ++++++++++++ .../Services/Token/TokenHandler.cs | 12 ++++++++++++ .../Services/AuthorizationEndpointService.cs | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 Infrastructure/HyBe.Infrastructure/Services/MailService.cs create mode 100644 Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs create mode 100644 Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs diff --git a/Infrastructure/HyBe.Infrastructure/Services/MailService.cs b/Infrastructure/HyBe.Infrastructure/Services/MailService.cs new file mode 100644 index 0000000..0fffdf9 --- /dev/null +++ b/Infrastructure/HyBe.Infrastructure/Services/MailService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Infrastructure.Services +{ + public class MailService + { + + } +} \ No newline at end of file diff --git a/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs new file mode 100644 index 0000000..c3db6ae --- /dev/null +++ b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Infrastructure.Services.Token +{ + public class TokenHandler + { + + } +} \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs b/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs new file mode 100644 index 0000000..3f8c265 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Persistence.Services +{ + public class AuthorizationEndpointService + { + + } +} \ No newline at end of file From fbfc71c2c4e9fe2805dc8d7e9be652780dd58b40 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:04:23 +0300 Subject: [PATCH 06/27] roles query --- .../Queries/GetRoleById/GetRoleByIdQueryHandler.cs | 12 ++++++++++++ .../Queries/GetRoleById/GetRoleByIdQueryRequest.cs | 12 ++++++++++++ .../Queries/GetRoleById/GetRoleByIdQueryResponse.cs | 12 ++++++++++++ .../Role/Queries/GetRoles/GetRolesQueryHandler.cs | 12 ++++++++++++ .../Role/Queries/GetRoles/GetRolesQueryRequest.cs | 12 ++++++++++++ .../Role/Queries/GetRoles/GetRolesQueryResponse.cs | 12 ++++++++++++ 6 files changed, 72 insertions(+) create mode 100644 Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryHandler.cs create mode 100644 Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs create mode 100644 Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryResponse.cs create mode 100644 Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryHandler.cs create mode 100644 Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs create mode 100644 Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryResponse.cs diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryHandler.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryHandler.cs new file mode 100644 index 0000000..30e6afa --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoleById +{ + public class GetRoleByIdQueryHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs new file mode 100644 index 0000000..f607ef8 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoleById +{ + public class GetRoleByIdQueryRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryResponse.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryResponse.cs new file mode 100644 index 0000000..bda23b8 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoleById +{ + public class GetRoleByIdQueryResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryHandler.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryHandler.cs new file mode 100644 index 0000000..2f5721b --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoles +{ + public class GetRolesQueryHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs new file mode 100644 index 0000000..310cd69 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoles +{ + public class GetRolesQueryRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryResponse.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryResponse.cs new file mode 100644 index 0000000..ea5aa96 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Queries.GetRoles +{ + public class GetRolesQueryResponse + { + + } +} \ No newline at end of file From d12a4b10c90e174d52b6fa7c151b23cedb1578bc Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:05:17 +0300 Subject: [PATCH 07/27] roles commands --- .../Commands/CreateRole/CreateRoleCommandHandler.cs | 12 ++++++++++++ .../Commands/CreateRole/CreateRoleCommandRequest.cs | 12 ++++++++++++ .../Commands/CreateRole/CreateRoleCommandResponse.cs | 12 ++++++++++++ .../Commands/DeleteRole/DeleteRoleCommandHandler.cs | 12 ++++++++++++ .../Commands/DeleteRole/DeleteRoleCommandRequest.cs | 12 ++++++++++++ .../Commands/DeleteRole/DeleteRoleCommandResponse.cs | 12 ++++++++++++ .../Commands/UpdateRole/UpdateRoleCommandHandler.cs | 12 ++++++++++++ .../Commands/UpdateRole/UpdateRoleCommandRequest.cs | 12 ++++++++++++ .../Commands/UpdateRole/UpdateRoleCommandResponse.cs | 12 ++++++++++++ 9 files changed, 108 insertions(+) create mode 100644 Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs create mode 100644 Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs create mode 100644 Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs new file mode 100644 index 0000000..b7228cd --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Commands.CreateRole +{ + public class CreateRoleCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs new file mode 100644 index 0000000..428bd5a --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Commands.CreateRole +{ + public class CreateRoleCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs new file mode 100644 index 0000000..9f145f5 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Commands.CreateRole +{ + public class CreateRoleCommandResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs new file mode 100644 index 0000000..4280a1e --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Commands.DeleteRole +{ + public class DeleteRoleCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs new file mode 100644 index 0000000..1301410 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Commands.DeleteRole +{ + public class DeleteRoleCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs new file mode 100644 index 0000000..f1ab9e6 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Commands.DeleteRole +{ + public class DeleteRoleCommandResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs new file mode 100644 index 0000000..7dc3fc7 --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Commands.UpdateRole +{ + public class UpdateRoleCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs new file mode 100644 index 0000000..c1b13ee --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Commands.UpdateRole +{ + public class UpdateRoleCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs new file mode 100644 index 0000000..1183cdc --- /dev/null +++ b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.Role.Commands.UpdateRole +{ + public class UpdateRoleCommandResponse + { + + } +} \ No newline at end of file From 0f62f5d5e4d9f520723d2adebf9504ba2b67ebd8 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:06:59 +0300 Subject: [PATCH 08/27] users query --- .../Queries/GetAllUsers/GetAllUsersQueryHandler.cs | 12 ++++++++++++ .../Queries/GetAllUsers/GetAllUsersQueryRequest.cs | 12 ++++++++++++ .../Queries/GetAllUsers/GetAllUsersQueryResponse.cs | 12 ++++++++++++ .../GetRolesToUser/GetRolesToUserQueryHandler.cs | 12 ++++++++++++ .../GetRolesToUser/GetRolesToUserQueryRequest.cs | 12 ++++++++++++ .../GetRolesToUser/GetRolesToUserQueryResponse.cs | 12 ++++++++++++ 6 files changed, 72 insertions(+) create mode 100644 Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs new file mode 100644 index 0000000..5090a0e --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Queries.GetAllUsers +{ + public class GetAllUsersQueryHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs new file mode 100644 index 0000000..f3985f6 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Queries.GetAllUsers +{ + public class GetAllUsersQueryRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs new file mode 100644 index 0000000..f4e4c32 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Queries.GetAllUsers +{ + public class GetAllUsersQueryResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs new file mode 100644 index 0000000..e41df61 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Queries.GetRolesToUser +{ + public class GetRolesToUserQueryHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs new file mode 100644 index 0000000..4310b80 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Queries.GetRolesToUser +{ + public class GetRolesToUserQueryRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs new file mode 100644 index 0000000..b58f8a0 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Queries.GetRolesToUser +{ + public class GetRolesToUserQueryResponse + { + + } +} \ No newline at end of file From 102b295a52e54547155e36b7604dfd387f97c093 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:08:01 +0300 Subject: [PATCH 09/27] identity --- Core/HyBe.Domain/Entities/Identity/AppRole.cs | 12 ++++++++++++ Core/HyBe.Domain/Entities/Identity/AppUser.cs | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 Core/HyBe.Domain/Entities/Identity/AppRole.cs create mode 100644 Core/HyBe.Domain/Entities/Identity/AppUser.cs diff --git a/Core/HyBe.Domain/Entities/Identity/AppRole.cs b/Core/HyBe.Domain/Entities/Identity/AppRole.cs new file mode 100644 index 0000000..9cf6b9f --- /dev/null +++ b/Core/HyBe.Domain/Entities/Identity/AppRole.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Domain.Entities.Identity +{ + public class AppRole + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Domain/Entities/Identity/AppUser.cs b/Core/HyBe.Domain/Entities/Identity/AppUser.cs new file mode 100644 index 0000000..fce2127 --- /dev/null +++ b/Core/HyBe.Domain/Entities/Identity/AppUser.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Domain.Entities.Identity +{ + public class AppUser + { + + } +} \ No newline at end of file From efe2f25ad2f3c5828d6a87e8f63b7af6b6c19059 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:08:49 +0300 Subject: [PATCH 10/27] abstractions --- .../Authentications/IInternalAuthentication.cs | 12 ++++++++++++ .../Services/Configurations/IApplicationService.cs | 12 ++++++++++++ .../Abstractions/Services/IAuthService.cs | 12 ++++++++++++ .../Services/IAuthorizationEndpointService.cs | 12 ++++++++++++ .../Abstractions/Services/IMailService.cs | 12 ++++++++++++ .../Abstractions/Services/IRoleService.cs | 12 ++++++++++++ .../Abstractions/Services/IUserService.cs | 12 ++++++++++++ .../Abstractions/Token/ITokenHandler.cs | 12 ++++++++++++ 8 files changed, 96 insertions(+) create mode 100644 Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs create mode 100644 Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs create mode 100644 Core/HyBe.Application/Abstractions/Services/IAuthService.cs create mode 100644 Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs create mode 100644 Core/HyBe.Application/Abstractions/Services/IMailService.cs create mode 100644 Core/HyBe.Application/Abstractions/Services/IRoleService.cs create mode 100644 Core/HyBe.Application/Abstractions/Services/IUserService.cs create mode 100644 Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs diff --git a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs new file mode 100644 index 0000000..17f28e0 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Services.Authentications +{ + public interface IInternalAuthentication + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs new file mode 100644 index 0000000..e2300d0 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Services.Configurations +{ + public interface IApplicationService + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs new file mode 100644 index 0000000..18d5072 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Services +{ + public interface IAuthService + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs new file mode 100644 index 0000000..0876c59 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Services +{ + public interface IAuthorizationEndpointService + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IMailService.cs b/Core/HyBe.Application/Abstractions/Services/IMailService.cs new file mode 100644 index 0000000..137f409 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/IMailService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Services +{ + public interface IMailService + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IRoleService.cs b/Core/HyBe.Application/Abstractions/Services/IRoleService.cs new file mode 100644 index 0000000..b451a22 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/IRoleService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Services +{ + public interface IRoleService + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IUserService.cs b/Core/HyBe.Application/Abstractions/Services/IUserService.cs new file mode 100644 index 0000000..c585a20 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/IUserService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Services +{ + public interface IUserService + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs b/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs new file mode 100644 index 0000000..5465cc1 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Token +{ + public interface ITokenHandler + { + + } +} \ No newline at end of file From 478e2c6b7c3b4ad936a9391d793b49f4b43c290a Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:09:21 +0300 Subject: [PATCH 11/27] DTOs --- Core/HyBe.Application/DTOs/Token.cs | 12 ++++++++++++ Core/HyBe.Application/DTOs/User/CreateUser.cs | 12 ++++++++++++ .../HyBe.Application/DTOs/User/CreateUserResponse.cs | 12 ++++++++++++ Core/HyBe.Application/DTOs/User/ListUser.cs | 12 ++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 Core/HyBe.Application/DTOs/Token.cs create mode 100644 Core/HyBe.Application/DTOs/User/CreateUser.cs create mode 100644 Core/HyBe.Application/DTOs/User/CreateUserResponse.cs create mode 100644 Core/HyBe.Application/DTOs/User/ListUser.cs diff --git a/Core/HyBe.Application/DTOs/Token.cs b/Core/HyBe.Application/DTOs/Token.cs new file mode 100644 index 0000000..39f1a6e --- /dev/null +++ b/Core/HyBe.Application/DTOs/Token.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.DTOs +{ + public class Token + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/CreateUser.cs b/Core/HyBe.Application/DTOs/User/CreateUser.cs new file mode 100644 index 0000000..d7ce38c --- /dev/null +++ b/Core/HyBe.Application/DTOs/User/CreateUser.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.DTOs.User +{ + public class CreateUser + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs b/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs new file mode 100644 index 0000000..6ec098a --- /dev/null +++ b/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.DTOs.User +{ + public class CreateUserResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/ListUser.cs b/Core/HyBe.Application/DTOs/User/ListUser.cs new file mode 100644 index 0000000..42c9c2f --- /dev/null +++ b/Core/HyBe.Application/DTOs/User/ListUser.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.DTOs.User +{ + public class ListUser + { + + } +} \ No newline at end of file From a853f3ee00d848f80feed9c59a68a33713c39261 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:09:55 +0300 Subject: [PATCH 12/27] exceptions --- .../Exceptions/AuthenticationErrorException.cs | 12 ++++++++++++ .../Exceptions/NotFoundUserException.cs | 12 ++++++++++++ .../Exceptions/PasswordChangeFailedException.cs | 12 ++++++++++++ .../Exceptions/UserCreateFailedException.cs | 12 ++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs create mode 100644 Core/HyBe.Application/Exceptions/NotFoundUserException.cs create mode 100644 Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs create mode 100644 Core/HyBe.Application/Exceptions/UserCreateFailedException.cs diff --git a/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs b/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs new file mode 100644 index 0000000..80b0228 --- /dev/null +++ b/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Exceptions +{ + public class AuthenticationErrorException + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Exceptions/NotFoundUserException.cs b/Core/HyBe.Application/Exceptions/NotFoundUserException.cs new file mode 100644 index 0000000..324cb6e --- /dev/null +++ b/Core/HyBe.Application/Exceptions/NotFoundUserException.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Exceptions +{ + public class NotFoundUserException + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs b/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs new file mode 100644 index 0000000..bffedd6 --- /dev/null +++ b/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Exceptions +{ + public class PasswordChangeFailedException + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs b/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs new file mode 100644 index 0000000..f089422 --- /dev/null +++ b/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Exceptions +{ + public class UserCreateFailedException + { + + } +} \ No newline at end of file From b44bd4c49acb0d5cfd5c9bc1aeb4af3b616cb978 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:11:14 +0300 Subject: [PATCH 13/27] users commands --- .../AssignRoleToUserCommandHandler.cs | 12 ++++++++++++ .../AssignRoleToUserCommandRequest.cs | 12 ++++++++++++ .../AssignRoleToUserCommandResponse.cs | 12 ++++++++++++ .../Commands/CreateUser/CreateUserCommandHandler.cs | 12 ++++++++++++ .../Commands/CreateUser/CreateUserCommandRequest.cs | 12 ++++++++++++ .../CreateUser/CreateUserCommandResponse.cs | 12 ++++++++++++ .../Commands/LoginUser/LoginUserCommandHandler.cs | 12 ++++++++++++ .../Commands/LoginUser/LoginUserCommandRequest.cs | 12 ++++++++++++ .../Commands/LoginUser/LoginUserCommandResponse.cs | 12 ++++++++++++ .../PasswordReset/PasswordResetCommandHandler.cs | 12 ++++++++++++ .../PasswordReset/PasswordResetCommandRequest.cs | 12 ++++++++++++ .../PasswordReset/PasswordResetCommandResponse.cs | 12 ++++++++++++ .../RefreshTokenLoginCommandHandler.cs | 12 ++++++++++++ .../RefreshTokenLoginCommandRequest.cs | 12 ++++++++++++ .../RefreshTokenLoginCommandResponse.cs | 12 ++++++++++++ .../UpdatePassword/UpdatePasswordCommandHandler.cs | 12 ++++++++++++ .../UpdatePassword/UpdatePasswordCommandRequest.cs | 12 ++++++++++++ .../UpdatePassword/UpdatePasswordCommandResponse.cs | 12 ++++++++++++ .../VerifyResetTokenCommandHandler.cs | 13 +++++++++++++ .../VerifyResetTokenCommandRequest.cs | 12 ++++++++++++ .../VerifyResetTokenCommandResponse.cs | 12 ++++++++++++ 21 files changed, 253 insertions(+) create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs new file mode 100644 index 0000000..97a4d33 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.AssignRoleToUser +{ + public class AssignRoleToUserCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs new file mode 100644 index 0000000..71164e8 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.AssignRoleToUser +{ + public class AssignRoleToUserCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs new file mode 100644 index 0000000..1c0c60b --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.AssignRoleToUser +{ + public class AssignRoleToUserCommandResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs new file mode 100644 index 0000000..0753be9 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.CreateUser +{ + public class CreateUserCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs new file mode 100644 index 0000000..d93893f --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.CreateUser +{ + public class CreateUserCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs new file mode 100644 index 0000000..6e8694a --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.CreateUser +{ + public class CreateUserCommandResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs new file mode 100644 index 0000000..d495756 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.LoginUser +{ + public class LoginUserCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs new file mode 100644 index 0000000..8951e31 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.LoginUser +{ + public class LoginUserCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs new file mode 100644 index 0000000..3feebcd --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.LoginUser +{ + public class LoginUserCommandResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs new file mode 100644 index 0000000..96b500c --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.PasswordReset +{ + public class PasswordResetCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs new file mode 100644 index 0000000..f0f031e --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.PasswordReset +{ + public class PasswordResetCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs new file mode 100644 index 0000000..2864b93 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.PasswordReset +{ + public class PasswordResetCommandResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs new file mode 100644 index 0000000..98a0722 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin +{ + public class RefreshTokenLoginCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs new file mode 100644 index 0000000..b4b0212 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin +{ + public class RefreshTokenLoginCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs new file mode 100644 index 0000000..7b31a05 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin +{ + public class RefreshTokenLoginCommandResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs new file mode 100644 index 0000000..cb4d8f1 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.UpdatePassword +{ + public class UpdatePasswordCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs new file mode 100644 index 0000000..72bb07d --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.UpdatePassword +{ + public class UpdatePasswordCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs new file mode 100644 index 0000000..7053726 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.UpdatePassword +{ + public class UpdatePasswordCommandResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs new file mode 100644 index 0000000..9baec22 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs @@ -0,0 +1,13 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.VerifyResetToken +{ + public class VerifyResetTokenCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs new file mode 100644 index 0000000..8144dd1 --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.VerifyResetToken +{ + public class VerifyResetTokenCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs new file mode 100644 index 0000000..5ed926e --- /dev/null +++ b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.VerifyResetToken +{ + public class VerifyResetTokenCommandResponse + { + + } +} \ No newline at end of file From 8437bb36aa9505dc5530bca26d8b845af856179a Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:13:16 +0300 Subject: [PATCH 14/27] AuthorizeDefinitionAttribute --- .../CustomAttributes/AuthorizeDefinitionAttribute.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs diff --git a/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs b/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs new file mode 100644 index 0000000..1e2c0a5 --- /dev/null +++ b/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.CustomAttributes +{ + public class AuthorizeDefinitionAttribute + { + + } +} \ No newline at end of file From 57352b04ae477dd3a8ccc0cb45cdb2341ee878c8 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Sun, 12 Feb 2023 00:13:48 +0300 Subject: [PATCH 15/27] endpoints --- .../AssignRoleEndpointCommandHandler.cs | 12 ++++++++++++ .../AssignRoleEndpointCommandRequest.cs | 12 ++++++++++++ .../AssignRoleEndpointCommandResponse.cs | 12 ++++++++++++ .../GetRolesToEndpointQueryHandler.cs | 12 ++++++++++++ .../GetRolesToEndpointQueryRequest.cs | 13 +++++++++++++ .../GetRolesToEndpointQueryResponse.cs | 12 ++++++++++++ 6 files changed, 73 insertions(+) create mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandHandler.cs create mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs create mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandResponse.cs create mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryHandler.cs create mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs create mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryResponse.cs diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandHandler.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandHandler.cs new file mode 100644 index 0000000..dce1e49 --- /dev/null +++ b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint +{ + public class AssignRoleEndpointCommandHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs new file mode 100644 index 0000000..9f16867 --- /dev/null +++ b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint +{ + public class AssignRoleEndpointCommandRequest + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandResponse.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandResponse.cs new file mode 100644 index 0000000..70bd9fb --- /dev/null +++ b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint +{ + public class AssignRoleEndpointCommandResponse + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryHandler.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryHandler.cs new file mode 100644 index 0000000..c269b60 --- /dev/null +++ b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryHandler.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint +{ + public class GetRolesToEndpointQueryHandler + { + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs new file mode 100644 index 0000000..ba5a6f9 --- /dev/null +++ b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint +{ + public class GetRolesToEndpointQueryRequest + { + + + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryResponse.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryResponse.cs new file mode 100644 index 0000000..a930f8a --- /dev/null +++ b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint +{ + public class GetRolesToEndpointQueryResponse + { + + } +} \ No newline at end of file From 553627d1e737215f88f288514e2c0678b5ccf1f1 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Fri, 24 Feb 2023 16:22:52 +0300 Subject: [PATCH 16/27] controllers updated --- .../ApplicationServicesController.cs | 21 +++++++- .../HyBe.WebAPI/Controllers/AuthController.cs | 44 ++++++++++++++- .../AuthorizationEndpointsController.cs | 27 +++++++++- .../Controllers/RolesController.cs | 53 +++++++++++++++++- .../Controllers/UsersController.cs | 54 ++++++++++++++++++- Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj | 1 + 6 files changed, 194 insertions(+), 6 deletions(-) diff --git a/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs index 6054d17..9d2a506 100644 --- a/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs @@ -7,6 +7,25 @@ namespace HyBe.WebAPI.Controllers { public class ApplicationServicesController { - + [Route("api/[controller]")] + [ApiController] + [Authorize(AuthenticationSchemes = "Admin")] + public class ApplicationServicesController : ControllerBase + { + readonly IApplicationService _applicationService; + + public ApplicationServicesController(IApplicationService applicationService) + { + _applicationService = applicationService; + } + + [HttpGet] + [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get Authorize Definition Endpoints", Menu = "Application Services")] + public IActionResult GetAuthorizeDefinitionEndpoints() + { + var datas = _applicationService.GetAuthorizeDefinitionEndpoints(typeof(Program)); + return Ok(datas); + } + } } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs index ad12ea7..ea0cd11 100644 --- a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs @@ -1,12 +1,52 @@ using System; using System.Collections.Generic; using System.Linq; +using HyBe.Application.Features.AppUser.Commands.LoginUser; +using HyBe.Application.Features.AppUser.Commands.PasswordReset; +using HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin; +using HyBe.Application.Features.AppUser.Commands.VerifyResetToken; +using MediatR; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; namespace HyBe.WebAPI.Controllers { - public class AuthController + [Route("api/[controller]")] + [ApiController] + public class AuthController : ControllerBase { - + readonly IMediator _mediator; + public AuthController(IMediator mediator) + { + _mediator = mediator; + } + [HttpPost("[action]")] + public async Task Login(LoginUserCommandRequest loginUserCommandRequest) + { + LoginUserCommandResponse response = await _mediator.Send(loginUserCommandRequest); + return Ok(response); + } + + [HttpPost("[action]")] + public async Task RefreshTokenLogin([FromBody] RefreshTokenLoginCommandRequest refreshTokenLoginCommandRequest) + { + RefreshTokenLoginCommandResponse response = await _mediator.Send(refreshTokenLoginCommandRequest); + return Ok(response); + } + + [HttpPost("password-reset")] + public async Task PasswordReset([FromBody] PasswordResetCommandRequest passwordResetCommandRequest) + { + PasswordResetCommandResponse response = await _mediator.Send(passwordResetCommandRequest); + return Ok(response); + } + + [HttpPost("verify-reset-token")] + public async Task VerifyResetToken([FromBody] VerifyResetTokenCommandRequest verifyResetTokenCommandRequest) + { + VerifyResetTokenCommandResponse response = await _mediator.Send(verifyResetTokenCommandRequest); + return Ok(response); + } } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs index 847c755..fa20601 100644 --- a/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs @@ -7,6 +7,31 @@ namespace HyBe.WebAPI.Controllers { public class AuthorizationEndpointsController { - + [Route("api/[controller]")] + [ApiController] + public class AuthorizationEndpointsController : ControllerBase + { + readonly IMediator _mediator; + + public AuthorizationEndpointsController(IMediator mediator) + { + _mediator = mediator; + } + + [HttpPost("[action]")] + public async Task GetRolesToEndpoint(GetRolesToEndpointQueryRequest rolesToEndpointQueryRequest) + { + GetRolesToEndpointQueryResponse response = await _mediator.Send(rolesToEndpointQueryRequest); + return Ok(response); + } + + [HttpPost] + public async Task AssignRoleEndpoint(AssignRoleEndpointCommandRequest assignRoleEndpointCommandRequest) + { + assignRoleEndpointCommandRequest.Type = typeof(Program); + AssignRoleEndpointCommandResponse response = await _mediator.Send(assignRoleEndpointCommandRequest); + return Ok(response); + } + } } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/RolesController.cs b/Presentation/HyBe.WebAPI/Controllers/RolesController.cs index f2f74a0..4a54212 100644 --- a/Presentation/HyBe.WebAPI/Controllers/RolesController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/RolesController.cs @@ -7,6 +7,57 @@ namespace HyBe.WebAPI.Controllers { public class RolesController { - + [Route("api/[controller]")] + [ApiController] + [Authorize(AuthenticationSchemes = "Admin")] + public class RolesController : ControllerBase + { + readonly IMediator _mediator; + + public RolesController(IMediator mediator) + { + _mediator = mediator; + } + + [HttpGet] + [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get Roles", Menu = "Roles")] + public async Task GetRoles([FromQuery] GetRolesQueryRequest getRolesQueryRequest) + { + GetRolesQueryResponse response = await _mediator.Send(getRolesQueryRequest); + return Ok(response); + } + + [HttpGet("{Id}")] + [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get Role By Id", Menu = "Roles")] + public async Task GetRoles([FromRoute] GetRoleByIdQueryRequest getRoleByIdQueryRequest) + { + GetRoleByIdQueryResponse response = await _mediator.Send(getRoleByIdQueryRequest); + return Ok(response); + } + + [HttpPost()] + [AuthorizeDefinition(ActionType = ActionType.Writing, Definition = "Create Role", Menu = "Roles")] + public async Task CreateRole([FromBody] CreateRoleCommandRequest createRoleCommandRequest) + { + CreateRoleCommandResponse response = await _mediator.Send(createRoleCommandRequest); + return Ok(response); + } + + [HttpPut("{Id}")] + [AuthorizeDefinition(ActionType = ActionType.Updating, Definition = "Update Role", Menu = "Roles")] + public async Task UpdateRole([FromBody, FromRoute] UpdateRoleCommandRequest updateRoleCommandRequest) + { + UpdateRoleCommandResponse response = await _mediator.Send(updateRoleCommandRequest); + return Ok(response); + } + + [HttpDelete("{Id}")] + [AuthorizeDefinition(ActionType = ActionType.Deleting, Definition = "Delete Role", Menu = "Roles")] + public async Task DeleteRole([FromRoute] DeleteRoleCommandRequest deleteRoleCommandRequest) + { + DeleteRoleCommandResponse response = await _mediator.Send(deleteRoleCommandRequest); + return Ok(response); + } + } } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs index 5c88e24..053be60 100644 --- a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs @@ -7,6 +7,58 @@ namespace HyBe.WebAPI.Controllers { public class UsersController { - + [Route("api/[controller]")] + [ApiController] + public class UsersController : ControllerBase + { + readonly IMediator _mediator; + readonly IMailService _mailService; + public UsersController(IMediator mediator, IMailService mailService) + { + _mediator = mediator; + _mailService = mailService; + } + + [HttpPost] + public async Task CreateUser(CreateUserCommandRequest createUserCommandRequest) + { + CreateUserCommandResponse response = await _mediator.Send(createUserCommandRequest); + return Ok(response); + } + + [HttpPost("update-password")] + public async Task UpdatePassword([FromBody] UpdatePasswordCommandRequest updatePasswordCommandRequest) + { + UpdatePasswordCommandResponse response = await _mediator.Send(updatePasswordCommandRequest); + return Ok(response); + } + + [HttpGet] + [Authorize(AuthenticationSchemes = "Admin")] + [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get All Users", Menu = "Users")] + public async Task GetAllUsers([FromQuery] GetAllUsersQueryRequest getAllUsersQueryRequest) + { + GetAllUsersQueryResponse response = await _mediator.Send(getAllUsersQueryRequest); + return Ok(response); + } + + [HttpGet("get-roles-to-user/{UserId}")] + [Authorize(AuthenticationSchemes = "Admin")] + [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get Roles To Users", Menu = "Users")] + public async Task GetRolesToUser([FromRoute]GetRolesToUserQueryRequest getRolesToUserQueryRequest) + { + GetRolesToUserQueryResponse response = await _mediator.Send(getRolesToUserQueryRequest); + return Ok(response); + } + + [HttpPost("assign-role-to-user")] + [Authorize(AuthenticationSchemes = "Admin")] + [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Assign Role To User", Menu = "Users")] + public async Task AssignRoleToUser(AssignRoleToUserCommandRequest assignRoleToUserCommandRequest) + { + AssignRoleToUserCommandResponse response = await _mediator.Send(assignRoleToUserCommandRequest); + return Ok(response); + } + } } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj index b52aa45..ed41e21 100644 --- a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj +++ b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj @@ -9,6 +9,7 @@ + From ee023f655e7896ff44230431152bae83e3820017 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Fri, 24 Feb 2023 17:00:30 +0300 Subject: [PATCH 17/27] Abstractions updated --- .../Authentications/IInternalAuthentication.cs | 3 ++- .../Services/Configurations/IApplicationService.cs | 2 +- .../Abstractions/Services/IAuthService.cs | 6 ++++-- .../Services/IAuthorizationEndpointService.cs | 3 ++- .../Abstractions/Services/IMailService.cs | 4 +++- .../Abstractions/Services/IRoleService.cs | 6 +++++- .../Abstractions/Services/IUserService.cs | 14 ++++++++++---- .../Abstractions/Token/ITokenHandler.cs | 8 +++----- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs index 17f28e0..2aed14d 100644 --- a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs +++ b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs @@ -7,6 +7,7 @@ namespace HyBe.Application.Abstractions.Services.Authentications { public interface IInternalAuthentication { - + Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime); + Task RefreshTokenLoginAsync(string refreshToken); } } \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs index e2300d0..242daff 100644 --- a/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs +++ b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs @@ -7,6 +7,6 @@ namespace HyBe.Application.Abstractions.Services.Configurations { public interface IApplicationService { - + List GetAuthorizeDefinitionEndpoints(Type type); } } \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs index 18d5072..57b814b 100644 --- a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs @@ -1,3 +1,4 @@ +using HyBe.Application.Abstractions.Services.Authentications; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +6,9 @@ namespace HyBe.Application.Abstractions.Services { - public interface IAuthService + public interface IAuthService : IInternalAuthentication { - + Task PasswordResetAsync(string email); + Task VerifyResetTokenAsync(string resetToken, string userId); } } \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs index 0876c59..354a263 100644 --- a/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs @@ -7,6 +7,7 @@ namespace HyBe.Application.Abstractions.Services { public interface IAuthorizationEndpointService { - + public Task AssignRoleEndpointAsync(string[] roles, string code); //missign (string menu); + public Task> GetRolesToEndpointAsync(string code); } } \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IMailService.cs b/Core/HyBe.Application/Abstractions/Services/IMailService.cs index 137f409..6915e85 100644 --- a/Core/HyBe.Application/Abstractions/Services/IMailService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IMailService.cs @@ -7,6 +7,8 @@ namespace HyBe.Application.Abstractions.Services { public interface IMailService { - + Task SendMailAsync(string to, string subject, string body, bool isBodyHtml = true); + Task SendMailAsync(string[] tos, string subject, string body, bool isBodyHtml = true); + Task SendPasswordResetMailAsync(string to, string userId, string resetToken); } } \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IRoleService.cs b/Core/HyBe.Application/Abstractions/Services/IRoleService.cs index b451a22..e6c9888 100644 --- a/Core/HyBe.Application/Abstractions/Services/IRoleService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IRoleService.cs @@ -7,6 +7,10 @@ namespace HyBe.Application.Abstractions.Services { public interface IRoleService { - + (object, int) GetAllRoles(int page, int size); + Task<(string id, string name)> GetRoleById(string id); + Task CreateRole(string name); + Task DeleteRole(string id); + Task UpdateRole(string id, string name); } } \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IUserService.cs b/Core/HyBe.Application/Abstractions/Services/IUserService.cs index c585a20..242ca51 100644 --- a/Core/HyBe.Application/Abstractions/Services/IUserService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IUserService.cs @@ -1,12 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using HyBe.Application.DTOs.User; +using HyBe.Domain.Entities.Identity; namespace HyBe.Application.Abstractions.Services { public interface IUserService { + Task CreateAsync(CreateUser model); + Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate); + Task UpdatePasswordAsync(string userId, string resetToken, string newPassword); + Task> GetAllUsersAsync(int page, int size); + Task AssignRoleToUserAsnyc(string userId, string[] roles); + Task GetRolesToUserAsync(string userIdOrName); + Task HasRolePermissionToEndpointAsync(string name, string code); + } } \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs b/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs index 5465cc1..0d662e0 100644 --- a/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs +++ b/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using HyBe.Domain.Entities.Identity; namespace HyBe.Application.Abstractions.Token { public interface ITokenHandler { - + DTOs.Token CreateAccessToken(int second, AppUser appUser); + string CreateRefreshToken(); } } \ No newline at end of file From 74fae6901348990f16711a158c2197d87f33e675 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Fri, 24 Feb 2023 17:02:16 +0300 Subject: [PATCH 18/27] CustomAttributes updated --- .../CustomAttributes/AuthorizeDefinitionAttribute.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs b/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs index 1e2c0a5..25a906c 100644 --- a/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs +++ b/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs @@ -5,8 +5,10 @@ namespace HyBe.Application.CustomAttributes { - public class AuthorizeDefinitionAttribute + public class AuthorizeDefinitionAttribute : Attribute { - + public string Menu { get; set; } + public string Definition { get; set; } + public ActionType ActionType { get; set; } } } \ No newline at end of file From 37c21b3574b64b5b75a78e96e3936bf2532e5490 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Fri, 24 Feb 2023 17:09:49 +0300 Subject: [PATCH 19/27] DTO's updated --- .../CustomAttributes/AuthorizeDefinitionAttribute.cs | 1 + Core/HyBe.Application/DTOs/Token.cs | 4 +++- Core/HyBe.Application/DTOs/User/CreateUser.cs | 6 +++++- Core/HyBe.Application/DTOs/User/CreateUserResponse.cs | 3 ++- Core/HyBe.Application/DTOs/User/ListUser.cs | 6 +++++- Core/HyBe.Domain/Enums/ActionType.cs | 10 ++++++++++ 6 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 Core/HyBe.Domain/Enums/ActionType.cs diff --git a/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs b/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs index 25a906c..c4281bd 100644 --- a/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs +++ b/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Domain.Enums; namespace HyBe.Application.CustomAttributes { diff --git a/Core/HyBe.Application/DTOs/Token.cs b/Core/HyBe.Application/DTOs/Token.cs index 39f1a6e..e3f6373 100644 --- a/Core/HyBe.Application/DTOs/Token.cs +++ b/Core/HyBe.Application/DTOs/Token.cs @@ -7,6 +7,8 @@ namespace HyBe.Application.DTOs { public class Token { - + public string AccessToken { get; set; } + public DateTime Expiration { get; set; } + public string RefreshToken { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/CreateUser.cs b/Core/HyBe.Application/DTOs/User/CreateUser.cs index d7ce38c..d517f03 100644 --- a/Core/HyBe.Application/DTOs/User/CreateUser.cs +++ b/Core/HyBe.Application/DTOs/User/CreateUser.cs @@ -7,6 +7,10 @@ namespace HyBe.Application.DTOs.User { public class CreateUser { - + public string NameSurname { get; set; } + public string Username { get; set; } + public string Email { get; set; } + public string Password { get; set; } + public string PasswordConfirm { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs b/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs index 6ec098a..602779d 100644 --- a/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs +++ b/Core/HyBe.Application/DTOs/User/CreateUserResponse.cs @@ -7,6 +7,7 @@ namespace HyBe.Application.DTOs.User { public class CreateUserResponse { - + public bool Succeeded { get; set; } + public string Message { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/ListUser.cs b/Core/HyBe.Application/DTOs/User/ListUser.cs index 42c9c2f..3b89008 100644 --- a/Core/HyBe.Application/DTOs/User/ListUser.cs +++ b/Core/HyBe.Application/DTOs/User/ListUser.cs @@ -7,6 +7,10 @@ namespace HyBe.Application.DTOs.User { public class ListUser { - + public string Id { get; set; } + public string Email { get; set; } + public string NameSurname { get; set; } + public string UserName { get; set; } + public bool TwoFactorEnabled { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Domain/Enums/ActionType.cs b/Core/HyBe.Domain/Enums/ActionType.cs new file mode 100644 index 0000000..ebfc10a --- /dev/null +++ b/Core/HyBe.Domain/Enums/ActionType.cs @@ -0,0 +1,10 @@ +namespace HyBe.Domain.Enums +{ + public enum ActionType + { + Reading, + Writing, + Updating, + Deleting + } +} \ No newline at end of file From 532ad21acc8adc929b3c2e9a1b3bcad7b4c05af5 Mon Sep 17 00:00:00 2001 From: MemoLee Date: Fri, 24 Feb 2023 17:40:18 +0300 Subject: [PATCH 20/27] Exceptions updated --- .../Exceptions/AuthenticationErrorException.cs | 14 ++++++++++++-- .../Exceptions/NotFoundUserException.cs | 14 ++++++++++++-- .../Exceptions/PasswordChangeFailedException.cs | 14 ++++++++++++-- .../Exceptions/UserCreateFailedException.cs | 14 ++++++++++++-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs b/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs index 80b0228..7a6c486 100644 --- a/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs +++ b/Core/HyBe.Application/Exceptions/AuthenticationErrorException.cs @@ -5,8 +5,18 @@ namespace HyBe.Application.Exceptions { - public class AuthenticationErrorException + public class AuthenticationErrorException : Exception { - + public AuthenticationErrorException() :base("Kimlik doğrulama hatası!") + { + } + + public AuthenticationErrorException(string? message) : base(message) + { + } + + public AuthenticationErrorException(string? message, Exception? innerException) : base(message, innerException) + { + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Exceptions/NotFoundUserException.cs b/Core/HyBe.Application/Exceptions/NotFoundUserException.cs index 324cb6e..ba27c4e 100644 --- a/Core/HyBe.Application/Exceptions/NotFoundUserException.cs +++ b/Core/HyBe.Application/Exceptions/NotFoundUserException.cs @@ -5,8 +5,18 @@ namespace HyBe.Application.Exceptions { - public class NotFoundUserException + public class NotFoundUserException : Exception { - + public NotFoundUserException() : base("Kullanıcı adı veya şifre hatalı.") + { + } + + public NotFoundUserException(string? message) : base(message) + { + } + + public NotFoundUserException(string? message, Exception? innerException) : base(message, innerException) + { + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs b/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs index bffedd6..8c3375e 100644 --- a/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs +++ b/Core/HyBe.Application/Exceptions/PasswordChangeFailedException.cs @@ -5,8 +5,18 @@ namespace HyBe.Application.Exceptions { - public class PasswordChangeFailedException + public class PasswordChangeFailedException : Exception { - + public PasswordChangeFailedException() : base("Şifre güncellenirken bir sorun oluştu.") + { + } + + public PasswordChangeFailedException(string? message) : base(message) + { + } + + public PasswordChangeFailedException(string? message, Exception? innerException) : base(message, innerException) + { + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs b/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs index f089422..78a0dd7 100644 --- a/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs +++ b/Core/HyBe.Application/Exceptions/UserCreateFailedException.cs @@ -5,8 +5,18 @@ namespace HyBe.Application.Exceptions { - public class UserCreateFailedException + public class UserCreateFailedException : Exception { - + public UserCreateFailedException() : base("Kullanıcı oluşturulurken beklenmeyen bir hatayla karşılaşıldı!") + { + } + + public UserCreateFailedException(string? message) : base(message) + { + } + + public UserCreateFailedException(string? message, Exception? innerException) : base(message, innerException) + { + } } } \ No newline at end of file From 0ec6c475a61322d10cca3a3fa7eb40a745d5ce5c Mon Sep 17 00:00:00 2001 From: Memo-Lee Date: Thu, 2 Mar 2023 21:43:03 +0300 Subject: [PATCH 21/27] fix v1 --- .../Configurations/IApplicationService.cs | 1 + .../Abstractions/Services/IAuthService.cs | 1 + .../DTOs/Configuration/Menu.cs | 14 +++++++++ .../AssignRoleToUserCommandHandler.cs | 16 ++++++++-- .../AssignRoleToUserCommandRequest.cs | 10 +++--- .../AssignRoleToUserCommandResponse.cs | 4 --- .../CreateUser/CreateUserCommandHandler.cs | 31 +++++++++++++++++-- .../CreateUser/CreateUserCommandRequest.cs | 9 ++++-- .../CreateUser/CreateUserCommandResponse.cs | 3 +- .../LoginUser/LoginUserCommandHandler.cs | 23 ++++++++++++-- .../LoginUser/LoginUserCommandRequest.cs | 6 ++-- .../LoginUser/LoginUserCommandResponse.cs | 13 ++++++-- .../PasswordResetCommandHandler.cs | 17 ++++++++-- .../PasswordResetCommandRequest.cs | 5 +-- .../PasswordResetCommandResponse.cs | 5 +-- .../RefreshTokenLoginCommandHandler.cs | 20 ++++++++++-- .../RefreshTokenLoginCommandRequest.cs | 5 +-- .../RefreshTokenLoginCommandResponse.cs | 3 +- .../UpdatePasswordCommandHandler.cs | 21 +++++++++++-- .../UpdatePasswordCommandRequest.cs | 12 +++---- .../UpdatePasswordCommandResponse.cs | 4 --- .../VerifyResetTokenCommandHandler.cs | 20 ++++++++++-- .../VerifyResetTokenCommandRequest.cs | 10 +++--- .../VerifyResetTokenCommandResponse.cs | 2 +- .../GetAllUsers/GetAllUsersQueryRequest.cs | 10 +++--- .../GetRolesToUserQueryRequest.cs | 9 ++---- .../AssignRoleEndpointCommandRequest.cs | 12 +++---- .../GetRolesToEndpointQueryRequest.cs | 11 +++---- .../CreateRole/CreateRoleCommandRequest.cs | 9 ++---- .../DeleteRole/DeleteRoleCommandRequest.cs | 9 ++---- .../UpdateRole/UpdateRoleCommandRequest.cs | 10 +++--- .../GetRoleById/GetRoleByIdQueryRequest.cs | 9 ++---- .../Queries/GetRoles/GetRolesQueryRequest.cs | 10 +++--- Core/HyBe.Application/HyBe.Application.csproj | 9 +++++- .../HyBe.SharedKernel.csproj | 4 +-- .../ApplicationServicesController.cs | 15 +++++---- .../AuthorizationEndpointsController.cs | 11 +++---- .../Controllers/RolesController.cs | 15 ++++++--- .../Controllers/UsersController.cs | 17 +++++++--- Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj | 1 + 40 files changed, 280 insertions(+), 136 deletions(-) create mode 100644 Core/HyBe.Application/DTOs/Configuration/Menu.cs diff --git a/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs index 242daff..41888ad 100644 --- a/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs +++ b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Application.DTOs.Configuration; namespace HyBe.Application.Abstractions.Services.Configurations { diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs index 57b814b..bd9a0ff 100644 --- a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs @@ -8,6 +8,7 @@ namespace HyBe.Application.Abstractions.Services { public interface IAuthService : IInternalAuthentication { + Task PasswordResetAsnyc(string email); Task PasswordResetAsync(string email); Task VerifyResetTokenAsync(string resetToken, string userId); } diff --git a/Core/HyBe.Application/DTOs/Configuration/Menu.cs b/Core/HyBe.Application/DTOs/Configuration/Menu.cs new file mode 100644 index 0000000..d6f9db7 --- /dev/null +++ b/Core/HyBe.Application/DTOs/Configuration/Menu.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services.Configurations; + +namespace HyBe.Application.DTOs.Configuration +{ + public class Menu + { + public string Name { get; set; } + public List Actions { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs index 97a4d33..96a4cbb 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs @@ -1,3 +1,5 @@ +using HyBe.Application.Abstractions.Services; +using MediatR; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +7,18 @@ namespace HyBe.Application.Features.AppUser.Commands.AssignRoleToUser { - public class AssignRoleToUserCommandHandler + public class AssignRoleToUserCommandHandler : IRequestHandler { - + readonly IUserService _userService; + public AssignRoleToUserCommandHandler(IUserService userService) + { + _userService = userService; + } + + public async Task Handle(AssignRoleToUserCommandRequest request, CancellationToken cancellationToken) + { + await _userService.AssignRoleToUserAsnyc(request.UserId, request.Roles); + return new(); + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs index 71164e8..cfe4df6 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AppUser.Commands.AssignRoleToUser { - public class AssignRoleToUserCommandRequest + public class AssignRoleToUserCommandRequest : IRequest { - + public string UserId { get; set; } + public string[] Roles { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs index 1c0c60b..5163f7f 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace HyBe.Application.Features.AppUser.Commands.AssignRoleToUser { diff --git a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs index 0753be9..5dce92a 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandHandler.cs @@ -2,11 +2,38 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services; +using HyBe.Application.DTOs.User; +using MediatR; namespace HyBe.Application.Features.AppUser.Commands.CreateUser { - public class CreateUserCommandHandler + public class CreateUserCommandHandler:IRequestHandler { - + readonly IUserService _userService; + public CreateUserCommandHandler(IUserService userService) + { + _userService = userService; + } + + public async Task Handle(CreateUserCommandRequest request, CancellationToken cancellationToken) + { + CreateUserResponse response = await _userService.CreateAsync(new() + { + Email = request.Email, + NameSurname = request.NameSurname, + Password = request.Password, + PasswordConfirm = request.PasswordConfirm, + Username = request.Username, + }); + + return new() + { + Message = response.Message, + Succeeded = response.Succeeded, + }; + + //throw new UserCreateFailedException(); + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs index d93893f..5620932 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandRequest.cs @@ -1,3 +1,4 @@ +using MediatR; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +6,12 @@ namespace HyBe.Application.Features.AppUser.Commands.CreateUser { - public class CreateUserCommandRequest + public class CreateUserCommandRequest : IRequest { - + public string NameSurname { get; set; } + public string Username { get; set; } + public string Email { get; set; } + public string Password { get; set; } + public string PasswordConfirm { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs index 6e8694a..11eabca 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/CreateUser/CreateUserCommandResponse.cs @@ -7,6 +7,7 @@ namespace HyBe.Application.Features.AppUser.Commands.CreateUser { public class CreateUserCommandResponse { - + public bool Succeeded { get; set; } + public string Message { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs index d495756..6606e0a 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs @@ -1,12 +1,31 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Token; +using HyBe.Application.DTOs; +using HyBe.Application.Exceptions; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AppUser.Commands.LoginUser { - public class LoginUserCommandHandler + public class LoginUserCommandHandler : IRequestHandler { - + readonly IAuthService _authService; + public LoginUserCommandHandler(IAuthService authService) + { + _authService = authService; + } + + public async Task Handle(LoginUserCommandRequest request, CancellationToken cancellationToken) + { + var token = await _authService.LoginAsync(request.UsernameOrEmail, request.Password, 900); + return new LoginUserSuccessCommandResponse() + { + Token = token + }; + } + } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs index 8951e31..c8bdf9a 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs @@ -2,11 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AppUser.Commands.LoginUser { - public class LoginUserCommandRequest + public class LoginUserCommandRequest : IRequest { - + public string UsernameOrEmail { get; set; } + public string Password { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs index 3feebcd..de86fe5 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs @@ -2,11 +2,20 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Application.DTOs; namespace HyBe.Application.Features.AppUser.Commands.LoginUser { - public class LoginUserCommandResponse + public class LoginUserCommandResponse { - + + } + public class LoginUserSuccessCommandResponse : LoginUserCommandResponse + { + public Token Token { get; set; } + } + public class LoginUserErrorCommandResponse : LoginUserCommandResponse + { + public string Message { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs index 96b500c..2a0e72c 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs @@ -1,3 +1,5 @@ +using HyBe.Application.Abstractions.Services; +using MediatR; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +7,19 @@ namespace HyBe.Application.Features.AppUser.Commands.PasswordReset { - public class PasswordResetCommandHandler + public class PasswordResetCommandHandler: IRequestHandler { - + readonly IAuthService _authService; + + public PasswordResetCommandHandler(IAuthService authService) + { + _authService = authService; + } + + public async Task Handle(PasswordResetCommandRequest request, CancellationToken cancellationToken) + { + await _authService.PasswordResetAsnyc(request.Email); + return new(); + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs index f0f031e..4fd5628 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs @@ -2,11 +2,12 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AppUser.Commands.PasswordReset { - public class PasswordResetCommandRequest + public class PasswordResetCommandRequest: IRequest { - + public string Email { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs index 2864b93..9f03539 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using HyBe.Application.Features.AppUser.Commands.PasswordReset; namespace HyBe.Application.Features.AppUser.Commands.PasswordReset { diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs index 98a0722..b8c4f3f 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs @@ -1,3 +1,6 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.DTOs; +using MediatR; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +8,21 @@ namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin { - public class RefreshTokenLoginCommandHandler + public class RefreshTokenLoginCommandHandler: IRequestHandler { - + readonly IAuthService _authService; + public RefreshTokenLoginCommandHandler(IAuthService authService) + { + _authService = authService; + } + + public async Task Handle(RefreshTokenLoginCommandRequest request, CancellationToken cancellationToken) + { + Token token = await _authService.RefreshTokenLoginAsync(request.RefreshToken); + return new() + { + Token = token + }; + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs index b4b0212..0129333 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs @@ -1,3 +1,4 @@ +using MediatR; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +6,8 @@ namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin { - public class RefreshTokenLoginCommandRequest + public class RefreshTokenLoginCommandRequest: IRequest { - + public string RefreshToken { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs index 7b31a05..17a88d5 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs @@ -1,3 +1,4 @@ +using HyBe.Application.DTOs; using System; using System.Collections.Generic; using System.Linq; @@ -7,6 +8,6 @@ namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin { public class RefreshTokenLoginCommandResponse { - + public Token Token { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs index cb4d8f1..9579adf 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs @@ -1,3 +1,6 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.Exceptions; +using MediatR; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +8,22 @@ namespace HyBe.Application.Features.AppUser.Commands.UpdatePassword { - public class UpdatePasswordCommandHandler + public class UpdatePasswordCommandHandler: IRequestHandler { - + readonly IUserService _userService; + + public UpdatePasswordCommandHandler(IUserService userService) + { + _userService = userService; + } + + public async Task Handle(UpdatePasswordCommandRequest request, CancellationToken cancellationToken) + { + if (!request.Password.Equals(request.PasswordConfirm)) + throw new PasswordChangeFailedException("Lütfen şifreyi birebir doğrulayınız."); + + await _userService.UpdatePasswordAsync(request.UserId, request.ResetToken, request.Password); + return new(); + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs index 72bb07d..19fe47e 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AppUser.Commands.UpdatePassword { - public class UpdatePasswordCommandRequest + public class UpdatePasswordCommandRequest: IRequest { - + public string UserId { get; set; } + public string ResetToken { get; set; } + public string Password { get; set; } + public string PasswordConfirm { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs index 7053726..8971d92 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace HyBe.Application.Features.AppUser.Commands.UpdatePassword { diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs index 9baec22..127d95d 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs @@ -1,4 +1,6 @@ +using HyBe.Application.Abstractions.Services; +using MediatR; using System; using System.Collections.Generic; using System.Linq; @@ -6,8 +8,22 @@ namespace HyBe.Application.Features.AppUser.Commands.VerifyResetToken { - public class VerifyResetTokenCommandHandler + public class VerifyResetTokenCommandHandler: IRequestHandler { - + readonly IAuthService _authService; + + public VerifyResetTokenCommandHandler(IAuthService authService) + { + _authService = authService; + } + + public async Task Handle(VerifyResetTokenCommandRequest request, CancellationToken cancellationToken) + { + bool state = await _authService.VerifyResetTokenAsync(request.ResetToken, request.UserId); + return new() + { + State = state + }; + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs index 8144dd1..6f89a67 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AppUser.Commands.VerifyResetToken { - public class VerifyResetTokenCommandRequest + public class VerifyResetTokenCommandRequest: IRequest { - + public string ResetToken { get; set; } + public string UserId { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs index 5ed926e..6bb198a 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs @@ -7,6 +7,6 @@ namespace HyBe.Application.Features.AppUser.Commands.VerifyResetToken { public class VerifyResetTokenCommandResponse { - + public bool State { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs index f3985f6..bdd1581 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AppUser.Queries.GetAllUsers { - public class GetAllUsersQueryRequest + public class GetAllUsersQueryRequest : IRequest { - + public int Page { get; set; } + public int Size { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs index 4310b80..1d768bb 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AppUser.Queries.GetRolesToUser { - public class GetRolesToUserQueryRequest + public class GetRolesToUserQueryRequest : IRequest { - + public string UserId { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs index 9f16867..7502dc7 100644 --- a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs +++ b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint { - public class AssignRoleEndpointCommandRequest + public class AssignRoleEndpointCommandRequest: IRequest { - + public string[] Roles { get; set; } + public string Code { get; set; } + public string Menu { get; set; } + public Type? Type { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs index ba5a6f9..716a917 100644 --- a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs +++ b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint { - public class GetRolesToEndpointQueryRequest + public class GetRolesToEndpointQueryRequest: IRequest { - - + public string Code { get; set; } + public string Menu { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs index 428bd5a..48d5f56 100644 --- a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs +++ b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.Role.Commands.CreateRole { - public class CreateRoleCommandRequest + public class CreateRoleCommandRequest : IRequest { - + public string Name { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs index 1301410..398c361 100644 --- a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs +++ b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.Role.Commands.DeleteRole { - public class DeleteRoleCommandRequest + public class DeleteRoleCommandRequest : IRequest { - + public string Id { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs index c1b13ee..71dcdac 100644 --- a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs +++ b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.Role.Commands.UpdateRole { - public class UpdateRoleCommandRequest + public class UpdateRoleCommandRequest : IRequest { - + public string Id { get; set; } + public string Name { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs index f607ef8..e5120a9 100644 --- a/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoleById/GetRoleByIdQueryRequest.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.Role.Queries.GetRoleById { - public class GetRoleByIdQueryRequest + public class GetRoleByIdQueryRequest : IRequest { - + public string Id { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs index 310cd69..7e02c9d 100644 --- a/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs +++ b/Core/HyBe.Application/Features/Role/Queries/GetRoles/GetRolesQueryRequest.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using MediatR; namespace HyBe.Application.Features.Role.Queries.GetRoles { - public class GetRolesQueryRequest + public class GetRolesQueryRequest : IRequest { - + public int Page { get; set; } = 0; + public int Size { get; set; } = 5; } } \ No newline at end of file diff --git a/Core/HyBe.Application/HyBe.Application.csproj b/Core/HyBe.Application/HyBe.Application.csproj index 3ebf9f4..3a0b917 100644 --- a/Core/HyBe.Application/HyBe.Application.csproj +++ b/Core/HyBe.Application/HyBe.Application.csproj @@ -7,7 +7,14 @@ - + + + + + + + + diff --git a/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj b/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj index efdb172..db9aa1e 100644 --- a/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj +++ b/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj @@ -44,11 +44,11 @@ - + - + diff --git a/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs index 9d2a506..84f6b20 100644 --- a/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs @@ -2,12 +2,16 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services.Configurations; +using HyBe.Application.CustomAttributes; +using HyBe.Domain.Enums; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Mvc; namespace HyBe.WebAPI.Controllers -{ - public class ApplicationServicesController - { - [Route("api/[controller]")] +{ + [Microsoft.AspNetCore.Mvc.Route("api/[Controller]")] [ApiController] [Authorize(AuthenticationSchemes = "Admin")] public class ApplicationServicesController : ControllerBase @@ -27,5 +31,4 @@ public IActionResult GetAuthorizeDefinitionEndpoints() return Ok(datas); } } - } -} \ No newline at end of file +} diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs index fa20601..6b8c454 100644 --- a/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint; +using HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint; +using MediatR; +using Microsoft.AspNetCore.Mvc; namespace HyBe.WebAPI.Controllers { - public class AuthorizationEndpointsController - { [Route("api/[controller]")] [ApiController] public class AuthorizationEndpointsController : ControllerBase @@ -33,5 +31,4 @@ public async Task AssignRoleEndpoint(AssignRoleEndpointCommandReq return Ok(response); } } - } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/RolesController.cs b/Presentation/HyBe.WebAPI/Controllers/RolesController.cs index 4a54212..3d5b5d1 100644 --- a/Presentation/HyBe.WebAPI/Controllers/RolesController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/RolesController.cs @@ -2,12 +2,20 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Application.CustomAttributes; +using HyBe.Application.Features.Role.Commands.CreateRole; +using HyBe.Application.Features.Role.Commands.DeleteRole; +using HyBe.Application.Features.Role.Commands.UpdateRole; +using HyBe.Application.Features.Role.Queries.GetRoleById; +using HyBe.Application.Features.Role.Queries.GetRoles; +using HyBe.Domain.Enums; +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace HyBe.WebAPI.Controllers { - public class RolesController - { - [Route("api/[controller]")] + [Route("api/[controller]")] [ApiController] [Authorize(AuthenticationSchemes = "Admin")] public class RolesController : ControllerBase @@ -59,5 +67,4 @@ public async Task DeleteRole([FromRoute] DeleteRoleCommandRequest return Ok(response); } } - } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs index 053be60..9875a16 100644 --- a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs @@ -2,12 +2,22 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services; +using HyBe.Application.CustomAttributes; +using HyBe.Application.Features.AppUser.Commands.AssignRoleToUser; +using HyBe.Application.Features.AppUser.Commands.CreateUser; +using HyBe.Application.Features.AppUser.Commands.UpdatePassword; +using HyBe.Application.Features.AppUser.Queries.GetAllUsers; +using HyBe.Application.Features.AppUser.Queries.GetRolesToUser; +using HyBe.Domain.Enums; +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Mvc; namespace HyBe.WebAPI.Controllers { - public class UsersController - { - [Route("api/[controller]")] + [Microsoft.AspNetCore.Mvc.Route("api/[Controller]")] [ApiController] public class UsersController : ControllerBase { @@ -60,5 +70,4 @@ public async Task AssignRoleToUser(AssignRoleToUserCommandRequest return Ok(response); } } - } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj index ed41e21..ddd5844 100644 --- a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj +++ b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj @@ -10,6 +10,7 @@ + From c0351613022732256c92048d7dceb38ac4dec6ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20S=C3=B6nmez?= Date: Wed, 15 Mar 2023 21:30:42 +0300 Subject: [PATCH 22/27] package updated --- Core/HyBe.Application/HyBe.Application.csproj | 11 ++++------- .../PersistenceServiceRegistration.cs | 2 +- Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj | 4 +--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Core/HyBe.Application/HyBe.Application.csproj b/Core/HyBe.Application/HyBe.Application.csproj index ebb007a..45b114c 100644 --- a/Core/HyBe.Application/HyBe.Application.csproj +++ b/Core/HyBe.Application/HyBe.Application.csproj @@ -7,13 +7,13 @@ - + + @@ -31,10 +31,7 @@ - - - - + diff --git a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs index 19ef15f..baad071 100644 --- a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs +++ b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs @@ -17,7 +17,7 @@ public static IServiceCollection AddPersistenceServices(this IServiceCollection services.AddDbContext(options => options.UseNpgsql(configuration.GetConnectionString("HypanceConnectionString"))); services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>)); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj index ccd63bc..32a7f14 100644 --- a/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj +++ b/Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj @@ -9,9 +9,7 @@ - - - + From 24cd9dfb862d729ddd081164e687601a5dbc38d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20S=C3=B6nmez?= Date: Wed, 15 Mar 2023 22:17:05 +0300 Subject: [PATCH 23/27] project working --- .../Abstractions/Services/IAuthService.cs | 3 +- .../PasswordResetCommandHandler.cs | 2 +- .../PersistenceServiceRegistration.cs | 12 ++++- .../HyBe.Persistence/Services/AuthService.cs | 33 ++++++++++++-- .../Services/AuthorizationEndpointService.cs | 17 +++++-- .../HyBe.Persistence/Services/RoleService.cs | 32 ++++++++++++-- .../HyBe.Persistence/Services/UserService.cs | 44 +++++++++++++++++-- 7 files changed, 123 insertions(+), 20 deletions(-) diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs index bd9a0ff..4f2b077 100644 --- a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs @@ -7,8 +7,7 @@ namespace HyBe.Application.Abstractions.Services { public interface IAuthService : IInternalAuthentication - { - Task PasswordResetAsnyc(string email); + { Task PasswordResetAsync(string email); Task VerifyResetTokenAsync(string resetToken, string userId); } diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs index 2a0e72c..4497785 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs @@ -18,7 +18,7 @@ public PasswordResetCommandHandler(IAuthService authService) public async Task Handle(PasswordResetCommandRequest request, CancellationToken cancellationToken) { - await _authService.PasswordResetAsnyc(request.Email); + await _authService.PasswordResetAsync(request.Email); return new(); } } diff --git a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs index baad071..1ff2b49 100644 --- a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs +++ b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs @@ -1,4 +1,5 @@ using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Services.Authentications; using HyBe.Persistence.Contexts; using HyBe.Persistence.Repositories; using HyBe.Persistence.Services; @@ -28,7 +29,16 @@ public static IServiceCollection AddPersistenceServices(this IServiceCollection services.AddScoped(); services.AddScoped(); services.AddScoped(); - return services; + + + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + + return services; } } diff --git a/Infrastructure/HyBe.Persistence/Services/AuthService.cs b/Infrastructure/HyBe.Persistence/Services/AuthService.cs index 345b45f..58429d5 100644 --- a/Infrastructure/HyBe.Persistence/Services/AuthService.cs +++ b/Infrastructure/HyBe.Persistence/Services/AuthService.cs @@ -1,3 +1,5 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.DTOs; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +7,31 @@ namespace HyBe.Persistence.Services { - public class AuthService - { - - } + public class AuthService : IAuthService + { + public Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime) + { + throw new NotImplementedException(); + } + + public Task PasswordResetAsnyc(string email) + { + throw new NotImplementedException(); + } + + public Task PasswordResetAsync(string email) + { + throw new NotImplementedException(); + } + + public Task RefreshTokenLoginAsync(string refreshToken) + { + throw new NotImplementedException(); + } + + public Task VerifyResetTokenAsync(string resetToken, string userId) + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs b/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs index 3f8c265..a9767a2 100644 --- a/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs +++ b/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs @@ -1,3 +1,4 @@ +using HyBe.Application.Abstractions.Services; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +6,16 @@ namespace HyBe.Persistence.Services { - public class AuthorizationEndpointService - { - - } + public class AuthorizationEndpointService : IAuthorizationEndpointService + { + public Task AssignRoleEndpointAsync(string[] roles, string code) + { + throw new NotImplementedException(); + } + + public Task> GetRolesToEndpointAsync(string code) + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/RoleService.cs b/Infrastructure/HyBe.Persistence/Services/RoleService.cs index c559e4e..4c2996f 100644 --- a/Infrastructure/HyBe.Persistence/Services/RoleService.cs +++ b/Infrastructure/HyBe.Persistence/Services/RoleService.cs @@ -1,3 +1,4 @@ +using HyBe.Application.Abstractions.Services; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +6,31 @@ namespace HyBe.Persistence.Services { - public class RoleService - { - - } + public class RoleService : IRoleService + { + public Task CreateRole(string name) + { + throw new NotImplementedException(); + } + + public Task DeleteRole(string id) + { + throw new NotImplementedException(); + } + + public (object, int) GetAllRoles(int page, int size) + { + throw new NotImplementedException(); + } + + public Task<(string id, string name)> GetRoleById(string id) + { + throw new NotImplementedException(); + } + + public Task UpdateRole(string id, string name) + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/UserService.cs b/Infrastructure/HyBe.Persistence/Services/UserService.cs index ec5186a..6d65dfe 100644 --- a/Infrastructure/HyBe.Persistence/Services/UserService.cs +++ b/Infrastructure/HyBe.Persistence/Services/UserService.cs @@ -1,3 +1,6 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.DTOs.User; +using HyBe.Domain.Entities.Identity; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +8,41 @@ namespace HyBe.Persistence.Services { - public class UserService - { - - } + public class UserService : IUserService + { + public Task AssignRoleToUserAsnyc(string userId, string[] roles) + { + throw new NotImplementedException(); + } + + public Task CreateAsync(CreateUser model) + { + throw new NotImplementedException(); + } + + public Task> GetAllUsersAsync(int page, int size) + { + throw new NotImplementedException(); + } + + public Task GetRolesToUserAsync(string userIdOrName) + { + throw new NotImplementedException(); + } + + public Task HasRolePermissionToEndpointAsync(string name, string code) + { + throw new NotImplementedException(); + } + + public Task UpdatePasswordAsync(string userId, string resetToken, string newPassword) + { + throw new NotImplementedException(); + } + + public Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate) + { + throw new NotImplementedException(); + } + } } \ No newline at end of file From 6f8ff10f5c523e3872134c80f7f7c00eb600008a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20S=C3=B6nmez?= Date: Thu, 16 Mar 2023 21:38:33 +0300 Subject: [PATCH 24/27] mediatr bug --- .../Configurations/IApplicationService.cs | 13 --- .../Abstractions/Services/IUserService.cs | 6 +- .../DTOs/Configuration/Action.cs | 15 +++ .../DTOs/Configuration/Menu.cs | 14 --- Core/HyBe.Application/DTOs/User/CreateUser.cs | 2 +- .../GetAllUsers/GetAllUsersQueryHandler.cs | 21 ++++- .../GetAllUsers/GetAllUsersQueryResponse.cs | 3 +- .../GetRolesToUserQueryHandler.cs | 20 +++- .../GetRolesToUserQueryResponse.cs | 2 +- .../AssignRoleEndpointCommandHandler.cs | 12 --- .../AssignRoleEndpointCommandRequest.cs | 12 --- .../AssignRoleEndpointCommandResponse.cs | 12 --- .../GetRolesToEndpointQueryHandler.cs | 12 --- .../GetRolesToEndpointQueryRequest.cs | 10 -- .../GetRolesToEndpointQueryResponse.cs | 12 --- .../CreateRole/CreateRoleCommandHandler.cs | 20 +++- .../CreateRole/CreateRoleCommandResponse.cs | 2 +- .../Helpers/CustomEncoders.cs | 23 +++++ Core/HyBe.Domain/Entities/Identity/AppRole.cs | 6 +- Core/HyBe.Domain/Entities/Identity/AppUser.cs | 11 ++- Core/HyBe.Domain/HyBe.Domain.csproj | 9 +- .../HyBe.SharedKernel.csproj | 7 +- .../HyBe.Infrastructure.csproj | 4 +- .../InfrastructureServiceRegistration.cs | 7 ++ .../Services/MailService.cs | 22 ++++- .../Services/Token/TokenHandler.cs | 26 +++++- .../HyBe.Persistence/HyBe.Persistence.csproj | 9 +- .../PersistenceServiceRegistration.cs | 11 ++- .../HyBe.Persistence/Services/AuthService.cs | 93 ++++++++++++++++--- .../Services/AuthorizationEndpointService.cs | 21 ----- .../HyBe.Persistence/Services/RoleService.cs | 42 +++++++-- .../HyBe.Persistence/Services/UserService.cs | 91 +++++++++++++++--- .../ApplicationServicesController.cs | 34 ------- .../AuthorizationEndpointsController.cs | 8 +- .../Controllers/UsersController.cs | 6 +- Presentation/HyBe.WebAPI/Program.cs | 36 ++++++- 36 files changed, 421 insertions(+), 233 deletions(-) delete mode 100644 Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs create mode 100644 Core/HyBe.Application/DTOs/Configuration/Action.cs delete mode 100644 Core/HyBe.Application/DTOs/Configuration/Menu.cs delete mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandHandler.cs delete mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs delete mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandResponse.cs delete mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryHandler.cs delete mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs delete mode 100644 Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryResponse.cs create mode 100644 Core/HyBe.Application/Helpers/CustomEncoders.cs delete mode 100644 Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs delete mode 100644 Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs diff --git a/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs deleted file mode 100644 index 41888ad..0000000 --- a/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using HyBe.Application.DTOs.Configuration; - -namespace HyBe.Application.Abstractions.Services.Configurations -{ - public interface IApplicationService - { - List GetAuthorizeDefinitionEndpoints(Type type); - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IUserService.cs b/Core/HyBe.Application/Abstractions/Services/IUserService.cs index 242ca51..9bac5ef 100644 --- a/Core/HyBe.Application/Abstractions/Services/IUserService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IUserService.cs @@ -9,9 +9,11 @@ public interface IUserService Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate); Task UpdatePasswordAsync(string userId, string resetToken, string newPassword); Task> GetAllUsersAsync(int page, int size); - Task AssignRoleToUserAsnyc(string userId, string[] roles); + int TotalUsersCount { get; } + Task AssignRoleToUserAsnyc(string userId, string[] roles); Task GetRolesToUserAsync(string userIdOrName); - Task HasRolePermissionToEndpointAsync(string name, string code); + + // Task HasRolePermissionToEndpointAsync(string name, string code); } diff --git a/Core/HyBe.Application/DTOs/Configuration/Action.cs b/Core/HyBe.Application/DTOs/Configuration/Action.cs new file mode 100644 index 0000000..e558c37 --- /dev/null +++ b/Core/HyBe.Application/DTOs/Configuration/Action.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HyBe.Application.DTOs.Configuration +{ + public class Action + { + public string ActionType { get; set; } + public string HttpType { get; set; } + public string Definition { get; set; } + public string Code { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/Configuration/Menu.cs b/Core/HyBe.Application/DTOs/Configuration/Menu.cs deleted file mode 100644 index d6f9db7..0000000 --- a/Core/HyBe.Application/DTOs/Configuration/Menu.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using HyBe.Application.Abstractions.Services.Configurations; - -namespace HyBe.Application.DTOs.Configuration -{ - public class Menu - { - public string Name { get; set; } - public List Actions { get; set; } = new(); - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/CreateUser.cs b/Core/HyBe.Application/DTOs/User/CreateUser.cs index d517f03..d461955 100644 --- a/Core/HyBe.Application/DTOs/User/CreateUser.cs +++ b/Core/HyBe.Application/DTOs/User/CreateUser.cs @@ -7,7 +7,7 @@ namespace HyBe.Application.DTOs.User { public class CreateUser { - public string NameSurname { get; set; } + public string NameSurname { get; set; } public string Username { get; set; } public string Email { get; set; } public string Password { get; set; } diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs index 5090a0e..dec8f66 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs @@ -2,11 +2,28 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services; +using MediatR; namespace HyBe.Application.Features.AppUser.Queries.GetAllUsers { - public class GetAllUsersQueryHandler + public class GetAllUsersQueryHandler : IRequestHandler { - + readonly IUserService _userService; + + public GetAllUsersQueryHandler(IUserService userService) + { + _userService = userService; + } + + public async Task Handle(GetAllUsersQueryRequest request, CancellationToken cancellationToken) + { + var users = await _userService.GetAllUsersAsync(request.Page, request.Size); + return new() + { + Users = users, + TotalUsersCount = _userService.TotalUsersCount + }; + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs index f4e4c32..d73efdc 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs @@ -7,6 +7,7 @@ namespace HyBe.Application.Features.AppUser.Queries.GetAllUsers { public class GetAllUsersQueryResponse { - + public object Users { get; set; } + public int TotalUsersCount { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs index e41df61..47660df 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs @@ -2,11 +2,27 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services; +using MediatR; namespace HyBe.Application.Features.AppUser.Queries.GetRolesToUser { - public class GetRolesToUserQueryHandler + public class GetRolesToUserQueryHandler : IRequestHandler { - + readonly IUserService _userService; + + public GetRolesToUserQueryHandler(IUserService userService) + { + _userService = userService; + } + + public async Task Handle(GetRolesToUserQueryRequest request, CancellationToken cancellationToken) + { + var userRoles = await _userService.GetRolesToUserAsync(request.UserId); + return new() + { + UserRoles = userRoles + }; + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs index b58f8a0..d4451f5 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs @@ -7,6 +7,6 @@ namespace HyBe.Application.Features.AppUser.Queries.GetRolesToUser { public class GetRolesToUserQueryResponse { - + public string[] UserRoles { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandHandler.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandHandler.cs deleted file mode 100644 index dce1e49..0000000 --- a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandHandler.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint -{ - public class AssignRoleEndpointCommandHandler - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs deleted file mode 100644 index 7502dc7..0000000 --- a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint -{ - public class AssignRoleEndpointCommandRequest: IRequest - { - public string[] Roles { get; set; } - public string Code { get; set; } - public string Menu { get; set; } - public Type? Type { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandResponse.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandResponse.cs deleted file mode 100644 index 70bd9fb..0000000 --- a/Core/HyBe.Application/Features/AuthorizationEndpoint/Commands/AssignRoleEndpoint/AssignRoleEndpointCommandResponse.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint -{ - public class AssignRoleEndpointCommandResponse - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryHandler.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryHandler.cs deleted file mode 100644 index c269b60..0000000 --- a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryHandler.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint -{ - public class GetRolesToEndpointQueryHandler - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs deleted file mode 100644 index 716a917..0000000 --- a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryRequest.cs +++ /dev/null @@ -1,10 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint -{ - public class GetRolesToEndpointQueryRequest: IRequest - { - public string Code { get; set; } - public string Menu { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryResponse.cs b/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryResponse.cs deleted file mode 100644 index a930f8a..0000000 --- a/Core/HyBe.Application/Features/AuthorizationEndpoint/Queries/GetRolesToEndpoint/GetRolesToEndpointQueryResponse.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint -{ - public class GetRolesToEndpointQueryResponse - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs index b7228cd..f92e3e6 100644 --- a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs +++ b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs @@ -2,11 +2,27 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services; +using MediatR; namespace HyBe.Application.Features.Role.Commands.CreateRole { - public class CreateRoleCommandHandler + public class CreateRoleCommandHandler : IRequestHandler { - + readonly IRoleService _roleService; + + public CreateRoleCommandHandler(IRoleService roleService) + { + _roleService = roleService; + } + + public async Task Handle(CreateRoleCommandRequest request, CancellationToken cancellationToken) + { + var result = await _roleService.CreateRole(request.Name); + return new() + { + Succeeded = result + }; + } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs index 9f145f5..12fbc72 100644 --- a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs +++ b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs @@ -7,6 +7,6 @@ namespace HyBe.Application.Features.Role.Commands.CreateRole { public class CreateRoleCommandResponse { - + public bool Succeeded { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Application/Helpers/CustomEncoders.cs b/Core/HyBe.Application/Helpers/CustomEncoders.cs new file mode 100644 index 0000000..c564047 --- /dev/null +++ b/Core/HyBe.Application/Helpers/CustomEncoders.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.WebUtilities; + +namespace HyBe.Application.Helpers +{ + static public class CustomEncoders + { + public static string UrlEncode(this string value) + { + byte[] bytes = Encoding.UTF8.GetBytes(value); + return WebEncoders.Base64UrlEncode(bytes); + } + public static string UrlDecode(this string value) + { + byte[] bytes = WebEncoders.Base64UrlDecode(value); + return Encoding.UTF8.GetString(bytes); + } + } +} \ No newline at end of file diff --git a/Core/HyBe.Domain/Entities/Identity/AppRole.cs b/Core/HyBe.Domain/Entities/Identity/AppRole.cs index 9cf6b9f..87a8601 100644 --- a/Core/HyBe.Domain/Entities/Identity/AppRole.cs +++ b/Core/HyBe.Domain/Entities/Identity/AppRole.cs @@ -2,11 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; namespace HyBe.Domain.Entities.Identity { - public class AppRole + public class AppRole : IdentityRole { - + public ICollection Endpoints { get; set; } } } \ No newline at end of file diff --git a/Core/HyBe.Domain/Entities/Identity/AppUser.cs b/Core/HyBe.Domain/Entities/Identity/AppUser.cs index fce2127..5de385c 100644 --- a/Core/HyBe.Domain/Entities/Identity/AppUser.cs +++ b/Core/HyBe.Domain/Entities/Identity/AppUser.cs @@ -1,3 +1,4 @@ +using Microsoft.AspNetCore.Identity; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +6,10 @@ namespace HyBe.Domain.Entities.Identity { - public class AppUser - { - - } + public class AppUser : IdentityUser + { + public string NameSurname { get; set; } + public string? RefreshToken { get; set; } + public DateTime? RefreshTokenEndDate { get; set; } + } } \ No newline at end of file diff --git a/Core/HyBe.Domain/HyBe.Domain.csproj b/Core/HyBe.Domain/HyBe.Domain.csproj index 2dabe87..95915ad 100644 --- a/Core/HyBe.Domain/HyBe.Domain.csproj +++ b/Core/HyBe.Domain/HyBe.Domain.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -29,6 +29,13 @@ + + + + + + + diff --git a/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj b/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj index 2a33b7c..16c656f 100644 --- a/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj +++ b/Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -25,6 +25,7 @@ + @@ -47,12 +48,14 @@ + - + + diff --git a/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj b/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj index aed52ba..ebf8d74 100644 --- a/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj +++ b/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -7,7 +7,7 @@ - + diff --git a/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs b/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs index 62f471c..1eb43b4 100644 --- a/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs +++ b/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs @@ -1,6 +1,10 @@ using System; using HyBe.Application.Abstractions.Infrastructure; +using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Token; +using HyBe.Infrastructure.Services; using HyBe.Infrastructure.Services.NotificationService; +using HyBe.Infrastructure.Services.Token; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -10,6 +14,9 @@ public static class InfrastructureServiceRegistration { public static IServiceCollection AddInfrastructureServices(this IServiceCollection services) { + services.AddScoped(); + services.AddScoped(); + /* services.AddScoped(); */ services.AddScoped(); return services; } diff --git a/Infrastructure/HyBe.Infrastructure/Services/MailService.cs b/Infrastructure/HyBe.Infrastructure/Services/MailService.cs index 0fffdf9..b61d7b8 100644 --- a/Infrastructure/HyBe.Infrastructure/Services/MailService.cs +++ b/Infrastructure/HyBe.Infrastructure/Services/MailService.cs @@ -1,3 +1,4 @@ +using HyBe.Application.Abstractions.Services; using System; using System.Collections.Generic; using System.Linq; @@ -5,8 +6,21 @@ namespace HyBe.Infrastructure.Services { - public class MailService - { - - } + public class MailService : IMailService + { + public Task SendMailAsync(string to, string subject, string body, bool isBodyHtml = true) + { + throw new NotImplementedException(); + } + + public Task SendMailAsync(string[] tos, string subject, string body, bool isBodyHtml = true) + { + throw new NotImplementedException(); + } + + public Task SendPasswordResetMailAsync(string to, string userId, string resetToken) + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs index c3db6ae..a7f5691 100644 --- a/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs +++ b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs @@ -1,12 +1,30 @@ +using HyBe.Application.Abstractions.Token; +using HyBe.Domain.Entities.Identity; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; using System; using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; using System.Linq; +using System.Security.Claims; +using System.Security.Cryptography; +using System.Text; using System.Threading.Tasks; +using Telegram.BotAPI.AvailableTypes; + namespace HyBe.Infrastructure.Services.Token { - public class TokenHandler - { - - } + public class TokenHandler : ITokenHandler + { + public Application.DTOs.Token CreateAccessToken(int second, AppUser appUser) + { + throw new NotImplementedException(); + } + + public string CreateRefreshToken() + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj b/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj index bdd56b4..6523c50 100644 --- a/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj +++ b/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -15,6 +15,13 @@ + + + + + + + diff --git a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs index 1ff2b49..cfd1b52 100644 --- a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs +++ b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs @@ -28,17 +28,20 @@ public static IServiceCollection AddPersistenceServices(this IServiceCollection services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + + services.AddScoped(); + + + + //services.AddScoped(); - return services; + return services; } } diff --git a/Infrastructure/HyBe.Persistence/Services/AuthService.cs b/Infrastructure/HyBe.Persistence/Services/AuthService.cs index 58429d5..bb3b24d 100644 --- a/Infrastructure/HyBe.Persistence/Services/AuthService.cs +++ b/Infrastructure/HyBe.Persistence/Services/AuthService.cs @@ -1,5 +1,12 @@ using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Token; using HyBe.Application.DTOs; +using HyBe.Application.Exceptions; +using HyBe.Application.Helpers; +using HyBe.Domain.Entities.Identity; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; using System.Linq; @@ -9,29 +16,87 @@ namespace HyBe.Persistence.Services { public class AuthService : IAuthService { - public Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime) + readonly HttpClient _httpClient; + readonly IConfiguration _configuration; + readonly UserManager _userManager; + readonly ITokenHandler _tokenHandler; + readonly SignInManager _signInManager; + readonly IUserService _userService; + readonly IMailService _mailService; + public AuthService(IHttpClientFactory httpClientFactory, + IConfiguration configuration, + UserManager userManager, + ITokenHandler tokenHandler, + SignInManager signInManager, + IUserService userService, + IMailService mailService) + { + _httpClient = httpClientFactory.CreateClient(); + _configuration = configuration; + _userManager = userManager; + _tokenHandler = tokenHandler; + _signInManager = signInManager; + _userService = userService; + _mailService = mailService; + } + public async Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime) { - throw new NotImplementedException(); - } + Domain.Entities.Identity.AppUser user = await _userManager.FindByNameAsync(usernameOrEmail); + if (user == null) + user = await _userManager.FindByEmailAsync(usernameOrEmail); - public Task PasswordResetAsnyc(string email) - { - throw new NotImplementedException(); - } + if (user == null) + throw new NotFoundUserException(); - public Task PasswordResetAsync(string email) - { - throw new NotImplementedException(); + SignInResult result = await _signInManager.CheckPasswordSignInAsync(user, password, false); + if (result.Succeeded) //Authentication başarılı! + { + Token token = _tokenHandler.CreateAccessToken(accessTokenLifeTime, user); + await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 15); + return token; + } + throw new AuthenticationErrorException(); } + public async Task PasswordResetAsync(string email) + { + AppUser user = await _userManager.FindByEmailAsync(email); + if (user != null) + { + string resetToken = await _userManager.GeneratePasswordResetTokenAsync(user); - public Task RefreshTokenLoginAsync(string refreshToken) + //byte[] tokenBytes = Encoding.UTF8.GetBytes(resetToken); + //resetToken = WebEncoders.Base64UrlEncode(tokenBytes); + resetToken = resetToken.UrlEncode(); + + await _mailService.SendPasswordResetMailAsync(email, user.Id, resetToken); + } + } + + public async Task RefreshTokenLoginAsync(string refreshToken) { - throw new NotImplementedException(); + AppUser? user = await _userManager.Users.FirstOrDefaultAsync(u => u.RefreshToken == refreshToken); + if (user != null && user?.RefreshTokenEndDate > DateTime.UtcNow) + { + Token token = _tokenHandler.CreateAccessToken(15, user); + await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 300); + return token; + } + else + throw new NotFoundUserException(); } - public Task VerifyResetTokenAsync(string resetToken, string userId) + public async Task VerifyResetTokenAsync(string resetToken, string userId) { - throw new NotImplementedException(); + AppUser user = await _userManager.FindByIdAsync(userId); + if (user != null) + { + //byte[] tokenBytes = WebEncoders.Base64UrlDecode(resetToken); + //resetToken = Encoding.UTF8.GetString(tokenBytes); + resetToken = resetToken.UrlDecode(); + + return await _userManager.VerifyUserTokenAsync(user, _userManager.Options.Tokens.PasswordResetTokenProvider, "ResetPassword", resetToken); + } + return false; } } } \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs b/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs deleted file mode 100644 index a9767a2..0000000 --- a/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs +++ /dev/null @@ -1,21 +0,0 @@ -using HyBe.Application.Abstractions.Services; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Persistence.Services -{ - public class AuthorizationEndpointService : IAuthorizationEndpointService - { - public Task AssignRoleEndpointAsync(string[] roles, string code) - { - throw new NotImplementedException(); - } - - public Task> GetRolesToEndpointAsync(string code) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/RoleService.cs b/Infrastructure/HyBe.Persistence/Services/RoleService.cs index 4c2996f..b4c5ac6 100644 --- a/Infrastructure/HyBe.Persistence/Services/RoleService.cs +++ b/Infrastructure/HyBe.Persistence/Services/RoleService.cs @@ -1,4 +1,6 @@ using HyBe.Application.Abstractions.Services; +using HyBe.Domain.Entities.Identity; +using Microsoft.AspNetCore.Identity; using System; using System.Collections.Generic; using System.Linq; @@ -8,29 +10,51 @@ namespace HyBe.Persistence.Services { public class RoleService : IRoleService { - public Task CreateRole(string name) + readonly RoleManager _roleManager; + + public RoleService(RoleManager roleManager) + { + _roleManager = roleManager; + } + public async Task CreateRole(string name) { - throw new NotImplementedException(); + IdentityResult result = await _roleManager.CreateAsync(new() { Id = Guid.NewGuid().ToString(), Name = name }); + return result.Succeeded; } - public Task DeleteRole(string id) + public async Task DeleteRole(string id) { - throw new NotImplementedException(); + AppRole appRole = await _roleManager.FindByIdAsync(id); + IdentityResult result = await _roleManager.DeleteAsync(appRole); + return result.Succeeded; } public (object, int) GetAllRoles(int page, int size) { - throw new NotImplementedException(); + var query = _roleManager.Roles; + + IQueryable rolesQuery = null; + + if (page != -1 && size != -1) + rolesQuery = query.Skip(page * size).Take(size); + else + rolesQuery = query; + + return (rolesQuery.Select(r => new { r.Id, r.Name }), query.Count()); } - public Task<(string id, string name)> GetRoleById(string id) + public async Task<(string id, string name)> GetRoleById(string id) { - throw new NotImplementedException(); + string role = await _roleManager.GetRoleIdAsync(new() { Id = id }); + return (id, role); } - public Task UpdateRole(string id, string name) + public async Task UpdateRole(string id, string name) { - throw new NotImplementedException(); + AppRole role = await _roleManager.FindByIdAsync(id); + role.Name = name; + IdentityResult result = await _roleManager.UpdateAsync(role); + return result.Succeeded; } } } \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/UserService.cs b/Infrastructure/HyBe.Persistence/Services/UserService.cs index 6d65dfe..32dd1bb 100644 --- a/Infrastructure/HyBe.Persistence/Services/UserService.cs +++ b/Infrastructure/HyBe.Persistence/Services/UserService.cs @@ -1,6 +1,11 @@ using HyBe.Application.Abstractions.Services; using HyBe.Application.DTOs.User; +using HyBe.Application.Exceptions; +using HyBe.Application.Helpers; +using HyBe.Domain.Entities; using HyBe.Domain.Entities.Identity; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -10,39 +15,97 @@ namespace HyBe.Persistence.Services { public class UserService : IUserService { - public Task AssignRoleToUserAsnyc(string userId, string[] roles) + readonly UserManager_userManager; + public UserService(UserManager userManager) { - throw new NotImplementedException(); + _userManager = userManager; } - public Task CreateAsync(CreateUser model) + public int TotalUsersCount => _userManager.Users.Count(); + + public Task AssignRoleToUserAsnyc(string userId, string[] roles) { throw new NotImplementedException(); } - public Task> GetAllUsersAsync(int page, int size) + public async Task CreateAsync(CreateUser model) { - throw new NotImplementedException(); - } + IdentityResult result = await _userManager.CreateAsync(new() + { + Id = Guid.NewGuid().ToString(), + UserName = model.Username, + Email = model.Email, + NameSurname = model.NameSurname, + }, model.Password); + + CreateUserResponse response = new() { Succeeded = result.Succeeded }; - public Task GetRolesToUserAsync(string userIdOrName) + if (result.Succeeded) + response.Message = "Kullanici basarili bir sekilde olusturulmustur!"; + else + foreach (var error in result.Errors) + response.Message += $"{error.Code} - {error.Description}\n"; + + return response; + } + public async Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate) { - throw new NotImplementedException(); + if (user != null) + { + user.RefreshToken = refreshToken; + user.RefreshTokenEndDate = accessTokenDate.AddSeconds(addOnAccessTokenDate); + await _userManager.UpdateAsync(user); + } + else + + throw new NotFoundUserException(); } - public Task HasRolePermissionToEndpointAsync(string name, string code) + public async Task UpdatePasswordAsync(string userId, string resetToken, string newPassword) { - throw new NotImplementedException(); + AppUser user = await _userManager.FindByIdAsync(userId); + if (user != null) + { + resetToken = resetToken.UrlDecode(); + IdentityResult result = await _userManager.ResetPasswordAsync(user, resetToken, newPassword); + if (result.Succeeded) + await _userManager.UpdateSecurityStampAsync(user); + else + throw new PasswordChangeFailedException(); + } } - public Task UpdatePasswordAsync(string userId, string resetToken, string newPassword) + public async Task> GetAllUsersAsync(int page, int size) { - throw new NotImplementedException(); + var users = await _userManager.Users + .Skip(page * size) + .Take(size) + .ToListAsync(); + + return users.Select(user => new ListUser + { + Id = user.Id, + Email = user.Email, + NameSurname = user.NameSurname, + TwoFactorEnabled = user.TwoFactorEnabled, + UserName = user.UserName + + }).ToList(); } - public Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate) + public async Task GetRolesToUserAsync(string userIdOrName) { - throw new NotImplementedException(); + AppUser user = await _userManager.FindByIdAsync(userIdOrName); + if (user == null) + user = await _userManager.FindByNameAsync(userIdOrName); + + if (user != null) + { + var userRoles = await _userManager.GetRolesAsync(user); + return userRoles.ToArray(); + } + return new string[] { }; } + } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs deleted file mode 100644 index 84f6b20..0000000 --- a/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using HyBe.Application.Abstractions.Services.Configurations; -using HyBe.Application.CustomAttributes; -using HyBe.Domain.Enums; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Mvc; - -namespace HyBe.WebAPI.Controllers -{ - [Microsoft.AspNetCore.Mvc.Route("api/[Controller]")] - [ApiController] - [Authorize(AuthenticationSchemes = "Admin")] - public class ApplicationServicesController : ControllerBase - { - readonly IApplicationService _applicationService; - - public ApplicationServicesController(IApplicationService applicationService) - { - _applicationService = applicationService; - } - - [HttpGet] - [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get Authorize Definition Endpoints", Menu = "Application Services")] - public IActionResult GetAuthorizeDefinitionEndpoints() - { - var datas = _applicationService.GetAuthorizeDefinitionEndpoints(typeof(Program)); - return Ok(datas); - } - } -} diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs index 6b8c454..0c11db5 100644 --- a/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/AuthorizationEndpointsController.cs @@ -1,5 +1,5 @@ -using HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint; -using HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint; +/* using HyBe.Application.Features.AuthorizationEndpoint.Commands.AssignRoleEndpoint; +using HyBe.Application.Features.AuthorizationEndpoint.Queries.GetRolesToEndpoint; */ using MediatR; using Microsoft.AspNetCore.Mvc; @@ -16,7 +16,7 @@ public AuthorizationEndpointsController(IMediator mediator) _mediator = mediator; } - [HttpPost("[action]")] + /* [HttpPost("[action]")] public async Task GetRolesToEndpoint(GetRolesToEndpointQueryRequest rolesToEndpointQueryRequest) { GetRolesToEndpointQueryResponse response = await _mediator.Send(rolesToEndpointQueryRequest); @@ -29,6 +29,6 @@ public async Task AssignRoleEndpoint(AssignRoleEndpointCommandReq assignRoleEndpointCommandRequest.Type = typeof(Program); AssignRoleEndpointCommandResponse response = await _mediator.Send(assignRoleEndpointCommandRequest); return Ok(response); - } + } */ } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs index 9875a16..9a4ced8 100644 --- a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs @@ -29,8 +29,8 @@ public UsersController(IMediator mediator, IMailService mailService) _mailService = mailService; } - [HttpPost] - public async Task CreateUser(CreateUserCommandRequest createUserCommandRequest) + [HttpPost("create-user")] + public async Task CreateUser(CreateUserCommandRequest createUserCommandRequest) { CreateUserCommandResponse response = await _mediator.Send(createUserCommandRequest); return Ok(response); @@ -43,7 +43,7 @@ public async Task UpdatePassword([FromBody] UpdatePasswordCommand return Ok(response); } - [HttpGet] + [HttpGet("get-user")] [Authorize(AuthenticationSchemes = "Admin")] [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get All Users", Menu = "Users")] public async Task GetAllUsers([FromQuery] GetAllUsersQueryRequest getAllUsersQueryRequest) diff --git a/Presentation/HyBe.WebAPI/Program.cs b/Presentation/HyBe.WebAPI/Program.cs index 543fd20..7265caa 100644 --- a/Presentation/HyBe.WebAPI/Program.cs +++ b/Presentation/HyBe.WebAPI/Program.cs @@ -1,14 +1,19 @@  -using HyBe.Application; +using HyBe.Application; using HyBe.Persistence; using HyBe.Infrastructure; using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.IdentityModel.Tokens; +using System.Text; +using System.Security.Claims; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); builder.Services.AddApplicationServices(); +//builder.Services.AddHttpContextAccessor(); builder.Services.AddPersistenceServices(builder.Configuration); builder.Services.AddInfrastructureServices(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -20,6 +25,25 @@ License = new Microsoft.OpenApi.Models.OpenApiLicense() { Name ="Hypance"} })); +builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer("Admin", options => + { + options.TokenValidationParameters = new() + { + ValidateAudience = true, //Olu�turulacak token de�erini kimlerin/hangi originlerin/sitelerin kullan�c� belirledi�imiz de�erdir. -> www.bilmemne.com + ValidateIssuer = true, //Olu�turulacak token de�erini kimin da��tt�n� ifade edece�imiz aland�r. -> www.myapi.com + ValidateLifetime = true, //Olu�turulan token de�erinin s�resini kontrol edecek olan do�rulamad�r. + ValidateIssuerSigningKey = true, //�retilecek token de�erinin uygulamam�za ait bir de�er oldu�unu ifade eden suciry key verisinin do�rulanmas�d�r. + + ValidAudience = builder.Configuration["Token:Audience"], + ValidIssuer = builder.Configuration["Token:Issuer"], + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Token:SecurityKey"])), + LifetimeValidator = (notBefore, expires, securityToken, validationParameters) => expires != null ? expires > DateTime.UtcNow : false, + + NameClaimType = ClaimTypes.Name //JWT �zerinde Name claimne kar��l�k gelen de�eri User.Identity.Name propertysinden elde edebiliriz. + }; + }); + var app = builder.Build(); // Configure the HTTP request pipeline. @@ -29,10 +53,20 @@ app.UseSwaggerUI(); } +app.UseHttpLogging(); +app.UseCors(); app.UseHttpsRedirection(); +app.UseAuthentication(); app.UseAuthorization(); +/* app.Use(async (context, next) => +{ + var username = context.User?.Identity?.IsAuthenticated != null || true ? context.User.Identity.Name : null; + LogContext.PushProperty("user_name", username); + await next(); +}); */ + app.MapControllers(); app.Run(); From 190a5f58ab87ae1f0a7909f22f1b74164c022995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20S=C3=B6nmez?= Date: Sat, 18 Mar 2023 22:55:55 +0300 Subject: [PATCH 25/27] Added user process --- .../IInternalAuthentication.cs | 13 - .../Configurations/IApplicationService.cs | 1 + .../Abstractions/Services/IAuthService.cs | 14 - .../Services/IAuthorizationEndpointService.cs | 13 - .../Abstractions/Services/IMailService.cs | 14 - .../Abstractions/Services/IRoleService.cs | 16 - .../Abstractions/Services/IUserService.cs | 17 +- .../AuthorizeDefinitionAttribute.cs | 15 - .../DTOs/Configuration/Action.cs | 15 - .../DTOs/Configuration/Menu.cs | 1 + Core/HyBe.Application/DTOs/User/CreateUser.cs | 2 +- Core/HyBe.Application/DTOs/User/ListUser.cs | 16 - .../AssignRoleToUserCommandHandler.cs | 24 - .../AssignRoleToUserCommandRequest.cs | 10 - .../AssignRoleToUserCommandResponse.cs | 8 - .../LoginUser/LoginUserCommandHandler.cs | 31 - .../LoginUser/LoginUserCommandRequest.cs | 14 - .../LoginUser/LoginUserCommandResponse.cs | 21 - .../PasswordResetCommandHandler.cs | 25 - .../PasswordResetCommandRequest.cs | 13 - .../PasswordResetCommandResponse.cs | 9 - .../RefreshTokenLoginCommandHandler.cs | 28 - .../RefreshTokenLoginCommandRequest.cs | 13 - .../RefreshTokenLoginCommandResponse.cs | 13 - .../UpdatePasswordCommandHandler.cs | 29 - .../UpdatePasswordCommandRequest.cs | 12 - .../UpdatePasswordCommandResponse.cs | 8 - .../VerifyResetTokenCommandHandler.cs | 29 - .../VerifyResetTokenCommandRequest.cs | 10 - .../VerifyResetTokenCommandResponse.cs | 12 - .../GetAllUsers/GetAllUsersQueryHandler.cs | 29 - .../GetAllUsers/GetAllUsersQueryRequest.cs | 10 - .../GetAllUsers/GetAllUsersQueryResponse.cs | 13 - .../GetRolesToUserQueryHandler.cs | 28 - .../GetRolesToUserQueryRequest.cs | 9 - .../GetRolesToUserQueryResponse.cs | 12 - .../CreateRole/CreateRoleCommandHandler.cs | 28 - .../CreateRole/CreateRoleCommandRequest.cs | 9 - .../CreateRole/CreateRoleCommandResponse.cs | 12 - .../DeleteRole/DeleteRoleCommandHandler.cs | 12 - .../DeleteRole/DeleteRoleCommandRequest.cs | 9 - .../DeleteRole/DeleteRoleCommandResponse.cs | 12 - .../UpdateRole/UpdateRoleCommandHandler.cs | 12 - .../UpdateRole/UpdateRoleCommandRequest.cs | 10 - .../UpdateRole/UpdateRoleCommandResponse.cs | 12 - Core/HyBe.Application/HyBe.Application.csproj | 7 - .../Entities/Backtests/Backtest.cs | 28 +- Core/HyBe.Domain/Entities/Identity/AppRole.cs | 12 +- Core/HyBe.Domain/Entities/Identity/AppUser.cs | 13 +- .../HyBe.Domain/Entities/Identity/Endpoint.cs | 23 + Core/HyBe.Domain/Entities/Identity/Menu.cs | 15 + Core/HyBe.Domain/HyBe.Domain.csproj | 7 +- .../HyBe.Infrastructure.csproj | 1 + .../InfrastructureServiceRegistration.cs | 10 +- .../Services/MailService.cs | 46 +- .../Services/Token/TokenHandler.cs | 69 +- .../Contexts/HypanceDbContext.cs | 4 +- .../HyBe.Persistence/HyBe.Persistence.csproj | 7 +- .../20230318141515_migration1.Designer.cs | 621 +++++++++++++++ .../Migrations/20230318141515_migration1.cs | 223 ++++++ .../20230318194141_migration2.Designer.cs | 724 ++++++++++++++++++ .../Migrations/20230318194141_migration2.cs | 127 +++ .../HypanceDbContextModelSnapshot.cs | 356 ++++++++- .../PersistenceServiceRegistration.cs | 26 +- .../HyBe.Persistence/Services/AuthService.cs | 102 --- .../Services/AuthorizationEndpointService.cs | 1 + .../HyBe.Persistence/Services/RoleService.cs | 60 -- .../HyBe.Persistence/Services/UserService.cs | 118 +-- .../ApplicationServicesController.cs | 1 + .../HyBe.WebAPI/Controllers/AuthController.cs | 52 -- .../Controllers/RolesController.cs | 70 -- .../Controllers/UsersController.cs | 48 +- Presentation/HyBe.WebAPI/Program.cs | 10 +- 73 files changed, 2261 insertions(+), 1183 deletions(-) create mode 100644 Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs create mode 100644 Core/HyBe.Application/DTOs/Configuration/Menu.cs create mode 100644 Core/HyBe.Domain/Entities/Identity/Endpoint.cs create mode 100644 Core/HyBe.Domain/Entities/Identity/Menu.cs create mode 100644 Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.Designer.cs create mode 100644 Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.cs create mode 100644 Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.Designer.cs create mode 100644 Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.cs create mode 100644 Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs create mode 100644 Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs diff --git a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs index 2aed14d..e69de29 100644 --- a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs +++ b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Abstractions.Services.Authentications -{ - public interface IInternalAuthentication - { - Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime); - Task RefreshTokenLoginAsync(string refreshToken); - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Core/HyBe.Application/Abstractions/Services/Configurations/IApplicationService.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs index 4f2b077..e69de29 100644 --- a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs @@ -1,14 +0,0 @@ -using HyBe.Application.Abstractions.Services.Authentications; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Abstractions.Services -{ - public interface IAuthService : IInternalAuthentication - { - Task PasswordResetAsync(string email); - Task VerifyResetTokenAsync(string resetToken, string userId); - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs index 354a263..e69de29 100644 --- a/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IAuthorizationEndpointService.cs @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Abstractions.Services -{ - public interface IAuthorizationEndpointService - { - public Task AssignRoleEndpointAsync(string[] roles, string code); //missign (string menu); - public Task> GetRolesToEndpointAsync(string code); - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IMailService.cs b/Core/HyBe.Application/Abstractions/Services/IMailService.cs index 6915e85..e69de29 100644 --- a/Core/HyBe.Application/Abstractions/Services/IMailService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IMailService.cs @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Abstractions.Services -{ - public interface IMailService - { - Task SendMailAsync(string to, string subject, string body, bool isBodyHtml = true); - Task SendMailAsync(string[] tos, string subject, string body, bool isBodyHtml = true); - Task SendPasswordResetMailAsync(string to, string userId, string resetToken); - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IRoleService.cs b/Core/HyBe.Application/Abstractions/Services/IRoleService.cs index e6c9888..e69de29 100644 --- a/Core/HyBe.Application/Abstractions/Services/IRoleService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IRoleService.cs @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Abstractions.Services -{ - public interface IRoleService - { - (object, int) GetAllRoles(int page, int size); - Task<(string id, string name)> GetRoleById(string id); - Task CreateRole(string name); - Task DeleteRole(string id); - Task UpdateRole(string id, string name); - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Abstractions/Services/IUserService.cs b/Core/HyBe.Application/Abstractions/Services/IUserService.cs index 9bac5ef..b28f4e7 100644 --- a/Core/HyBe.Application/Abstractions/Services/IUserService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IUserService.cs @@ -1,20 +1,9 @@ using HyBe.Application.DTOs.User; -using HyBe.Domain.Entities.Identity; namespace HyBe.Application.Abstractions.Services { - public interface IUserService - { + public interface IUserService + { Task CreateAsync(CreateUser model); - Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate); - Task UpdatePasswordAsync(string userId, string resetToken, string newPassword); - Task> GetAllUsersAsync(int page, int size); - int TotalUsersCount { get; } - Task AssignRoleToUserAsnyc(string userId, string[] roles); - Task GetRolesToUserAsync(string userIdOrName); - - // Task HasRolePermissionToEndpointAsync(string name, string code); - - - } + } } \ No newline at end of file diff --git a/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs b/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs index c4281bd..e69de29 100644 --- a/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs +++ b/Core/HyBe.Application/CustomAttributes/AuthorizeDefinitionAttribute.cs @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using HyBe.Domain.Enums; - -namespace HyBe.Application.CustomAttributes -{ - public class AuthorizeDefinitionAttribute : Attribute - { - public string Menu { get; set; } - public string Definition { get; set; } - public ActionType ActionType { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/Configuration/Action.cs b/Core/HyBe.Application/DTOs/Configuration/Action.cs index e558c37..e69de29 100644 --- a/Core/HyBe.Application/DTOs/Configuration/Action.cs +++ b/Core/HyBe.Application/DTOs/Configuration/Action.cs @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.DTOs.Configuration -{ - public class Action - { - public string ActionType { get; set; } - public string HttpType { get; set; } - public string Definition { get; set; } - public string Code { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/Configuration/Menu.cs b/Core/HyBe.Application/DTOs/Configuration/Menu.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Core/HyBe.Application/DTOs/Configuration/Menu.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Core/HyBe.Application/DTOs/User/CreateUser.cs b/Core/HyBe.Application/DTOs/User/CreateUser.cs index d461955..d517f03 100644 --- a/Core/HyBe.Application/DTOs/User/CreateUser.cs +++ b/Core/HyBe.Application/DTOs/User/CreateUser.cs @@ -7,7 +7,7 @@ namespace HyBe.Application.DTOs.User { public class CreateUser { - public string NameSurname { get; set; } + public string NameSurname { get; set; } public string Username { get; set; } public string Email { get; set; } public string Password { get; set; } diff --git a/Core/HyBe.Application/DTOs/User/ListUser.cs b/Core/HyBe.Application/DTOs/User/ListUser.cs index 3b89008..e69de29 100644 --- a/Core/HyBe.Application/DTOs/User/ListUser.cs +++ b/Core/HyBe.Application/DTOs/User/ListUser.cs @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.DTOs.User -{ - public class ListUser - { - public string Id { get; set; } - public string Email { get; set; } - public string NameSurname { get; set; } - public string UserName { get; set; } - public bool TwoFactorEnabled { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs index 96a4cbb..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandHandler.cs @@ -1,24 +0,0 @@ -using HyBe.Application.Abstractions.Services; -using MediatR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Commands.AssignRoleToUser -{ - public class AssignRoleToUserCommandHandler : IRequestHandler - { - readonly IUserService _userService; - public AssignRoleToUserCommandHandler(IUserService userService) - { - _userService = userService; - } - - public async Task Handle(AssignRoleToUserCommandRequest request, CancellationToken cancellationToken) - { - await _userService.AssignRoleToUserAsnyc(request.UserId, request.Roles); - return new(); - } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs index cfe4df6..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandRequest.cs @@ -1,10 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.AppUser.Commands.AssignRoleToUser -{ - public class AssignRoleToUserCommandRequest : IRequest - { - public string UserId { get; set; } - public string[] Roles { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs index 5163f7f..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/AssignRoleToUser/AssignRoleToUserCommandResponse.cs @@ -1,8 +0,0 @@ - -namespace HyBe.Application.Features.AppUser.Commands.AssignRoleToUser -{ - public class AssignRoleToUserCommandResponse - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs index 6606e0a..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs @@ -1,31 +0,0 @@ -using HyBe.Application.Abstractions.Services; -using HyBe.Application.Abstractions.Token; -using HyBe.Application.DTOs; -using HyBe.Application.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using MediatR; - -namespace HyBe.Application.Features.AppUser.Commands.LoginUser -{ - public class LoginUserCommandHandler : IRequestHandler - { - readonly IAuthService _authService; - public LoginUserCommandHandler(IAuthService authService) - { - _authService = authService; - } - - public async Task Handle(LoginUserCommandRequest request, CancellationToken cancellationToken) - { - var token = await _authService.LoginAsync(request.UsernameOrEmail, request.Password, 900); - return new LoginUserSuccessCommandResponse() - { - Token = token - }; - } - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs index c8bdf9a..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using MediatR; - -namespace HyBe.Application.Features.AppUser.Commands.LoginUser -{ - public class LoginUserCommandRequest : IRequest - { - public string UsernameOrEmail { get; set; } - public string Password { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs index de86fe5..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using HyBe.Application.DTOs; - -namespace HyBe.Application.Features.AppUser.Commands.LoginUser -{ - public class LoginUserCommandResponse - { - - } - public class LoginUserSuccessCommandResponse : LoginUserCommandResponse - { - public Token Token { get; set; } - } - public class LoginUserErrorCommandResponse : LoginUserCommandResponse - { - public string Message { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs index 4497785..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandHandler.cs @@ -1,25 +0,0 @@ -using HyBe.Application.Abstractions.Services; -using MediatR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Commands.PasswordReset -{ - public class PasswordResetCommandHandler: IRequestHandler - { - readonly IAuthService _authService; - - public PasswordResetCommandHandler(IAuthService authService) - { - _authService = authService; - } - - public async Task Handle(PasswordResetCommandRequest request, CancellationToken cancellationToken) - { - await _authService.PasswordResetAsync(request.Email); - return new(); - } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs index 4fd5628..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandRequest.cs @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using MediatR; - -namespace HyBe.Application.Features.AppUser.Commands.PasswordReset -{ - public class PasswordResetCommandRequest: IRequest - { - public string Email { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs index 9f03539..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/PasswordReset/PasswordResetCommandResponse.cs @@ -1,9 +0,0 @@ -using HyBe.Application.Features.AppUser.Commands.PasswordReset; - -namespace HyBe.Application.Features.AppUser.Commands.PasswordReset -{ - public class PasswordResetCommandResponse - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs index b8c4f3f..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs @@ -1,28 +0,0 @@ -using HyBe.Application.Abstractions.Services; -using HyBe.Application.DTOs; -using MediatR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin -{ - public class RefreshTokenLoginCommandHandler: IRequestHandler - { - readonly IAuthService _authService; - public RefreshTokenLoginCommandHandler(IAuthService authService) - { - _authService = authService; - } - - public async Task Handle(RefreshTokenLoginCommandRequest request, CancellationToken cancellationToken) - { - Token token = await _authService.RefreshTokenLoginAsync(request.RefreshToken); - return new() - { - Token = token - }; - } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs index 0129333..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs @@ -1,13 +0,0 @@ -using MediatR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin -{ - public class RefreshTokenLoginCommandRequest: IRequest - { - public string RefreshToken { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs index 17a88d5..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs @@ -1,13 +0,0 @@ -using HyBe.Application.DTOs; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin -{ - public class RefreshTokenLoginCommandResponse - { - public Token Token { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs index 9579adf..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandHandler.cs @@ -1,29 +0,0 @@ -using HyBe.Application.Abstractions.Services; -using HyBe.Application.Exceptions; -using MediatR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Commands.UpdatePassword -{ - public class UpdatePasswordCommandHandler: IRequestHandler - { - readonly IUserService _userService; - - public UpdatePasswordCommandHandler(IUserService userService) - { - _userService = userService; - } - - public async Task Handle(UpdatePasswordCommandRequest request, CancellationToken cancellationToken) - { - if (!request.Password.Equals(request.PasswordConfirm)) - throw new PasswordChangeFailedException("Lütfen şifreyi birebir doğrulayınız."); - - await _userService.UpdatePasswordAsync(request.UserId, request.ResetToken, request.Password); - return new(); - } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs index 19fe47e..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandRequest.cs @@ -1,12 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.AppUser.Commands.UpdatePassword -{ - public class UpdatePasswordCommandRequest: IRequest - { - public string UserId { get; set; } - public string ResetToken { get; set; } - public string Password { get; set; } - public string PasswordConfirm { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs index 8971d92..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/UpdatePassword/UpdatePasswordCommandResponse.cs @@ -1,8 +0,0 @@ - -namespace HyBe.Application.Features.AppUser.Commands.UpdatePassword -{ - public class UpdatePasswordCommandResponse - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs index 127d95d..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandHandler.cs @@ -1,29 +0,0 @@ - -using HyBe.Application.Abstractions.Services; -using MediatR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Commands.VerifyResetToken -{ - public class VerifyResetTokenCommandHandler: IRequestHandler - { - readonly IAuthService _authService; - - public VerifyResetTokenCommandHandler(IAuthService authService) - { - _authService = authService; - } - - public async Task Handle(VerifyResetTokenCommandRequest request, CancellationToken cancellationToken) - { - bool state = await _authService.VerifyResetTokenAsync(request.ResetToken, request.UserId); - return new() - { - State = state - }; - } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs index 6f89a67..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandRequest.cs @@ -1,10 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.AppUser.Commands.VerifyResetToken -{ - public class VerifyResetTokenCommandRequest: IRequest - { - public string ResetToken { get; set; } - public string UserId { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs index 6bb198a..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/VerifyResetToken/VerifyResetTokenCommandResponse.cs @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Commands.VerifyResetToken -{ - public class VerifyResetTokenCommandResponse - { - public bool State { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs index dec8f66..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryHandler.cs @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using HyBe.Application.Abstractions.Services; -using MediatR; - -namespace HyBe.Application.Features.AppUser.Queries.GetAllUsers -{ - public class GetAllUsersQueryHandler : IRequestHandler - { - readonly IUserService _userService; - - public GetAllUsersQueryHandler(IUserService userService) - { - _userService = userService; - } - - public async Task Handle(GetAllUsersQueryRequest request, CancellationToken cancellationToken) - { - var users = await _userService.GetAllUsersAsync(request.Page, request.Size); - return new() - { - Users = users, - TotalUsersCount = _userService.TotalUsersCount - }; - } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs index bdd1581..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryRequest.cs @@ -1,10 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.AppUser.Queries.GetAllUsers -{ - public class GetAllUsersQueryRequest : IRequest - { - public int Page { get; set; } - public int Size { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs index d73efdc..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetAllUsers/GetAllUsersQueryResponse.cs @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Queries.GetAllUsers -{ - public class GetAllUsersQueryResponse - { - public object Users { get; set; } - public int TotalUsersCount { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs index 47660df..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryHandler.cs @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using HyBe.Application.Abstractions.Services; -using MediatR; - -namespace HyBe.Application.Features.AppUser.Queries.GetRolesToUser -{ - public class GetRolesToUserQueryHandler : IRequestHandler - { - readonly IUserService _userService; - - public GetRolesToUserQueryHandler(IUserService userService) - { - _userService = userService; - } - - public async Task Handle(GetRolesToUserQueryRequest request, CancellationToken cancellationToken) - { - var userRoles = await _userService.GetRolesToUserAsync(request.UserId); - return new() - { - UserRoles = userRoles - }; - } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs index 1d768bb..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryRequest.cs @@ -1,9 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.AppUser.Queries.GetRolesToUser -{ - public class GetRolesToUserQueryRequest : IRequest - { - public string UserId { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs index d4451f5..e69de29 100644 --- a/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Queries/GetRolesToUser/GetRolesToUserQueryResponse.cs @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.AppUser.Queries.GetRolesToUser -{ - public class GetRolesToUserQueryResponse - { - public string[] UserRoles { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs index f92e3e6..e69de29 100644 --- a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs +++ b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandHandler.cs @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using HyBe.Application.Abstractions.Services; -using MediatR; - -namespace HyBe.Application.Features.Role.Commands.CreateRole -{ - public class CreateRoleCommandHandler : IRequestHandler - { - readonly IRoleService _roleService; - - public CreateRoleCommandHandler(IRoleService roleService) - { - _roleService = roleService; - } - - public async Task Handle(CreateRoleCommandRequest request, CancellationToken cancellationToken) - { - var result = await _roleService.CreateRole(request.Name); - return new() - { - Succeeded = result - }; - } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs index 48d5f56..e69de29 100644 --- a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs +++ b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandRequest.cs @@ -1,9 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.Role.Commands.CreateRole -{ - public class CreateRoleCommandRequest : IRequest - { - public string Name { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs index 12fbc72..e69de29 100644 --- a/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs +++ b/Core/HyBe.Application/Features/Role/Commands/CreateRole/CreateRoleCommandResponse.cs @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.Role.Commands.CreateRole -{ - public class CreateRoleCommandResponse - { - public bool Succeeded { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs index 4280a1e..e69de29 100644 --- a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs +++ b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandHandler.cs @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.Role.Commands.DeleteRole -{ - public class DeleteRoleCommandHandler - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs index 398c361..e69de29 100644 --- a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs +++ b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandRequest.cs @@ -1,9 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.Role.Commands.DeleteRole -{ - public class DeleteRoleCommandRequest : IRequest - { - public string Id { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs index f1ab9e6..e69de29 100644 --- a/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs +++ b/Core/HyBe.Application/Features/Role/Commands/DeleteRole/DeleteRoleCommandResponse.cs @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.Role.Commands.DeleteRole -{ - public class DeleteRoleCommandResponse - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs index 7dc3fc7..e69de29 100644 --- a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs +++ b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandHandler.cs @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.Role.Commands.UpdateRole -{ - public class UpdateRoleCommandHandler - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs index 71dcdac..e69de29 100644 --- a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs +++ b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandRequest.cs @@ -1,10 +0,0 @@ -using MediatR; - -namespace HyBe.Application.Features.Role.Commands.UpdateRole -{ - public class UpdateRoleCommandRequest : IRequest - { - public string Id { get; set; } - public string Name { get; set; } - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs index 1183cdc..e69de29 100644 --- a/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs +++ b/Core/HyBe.Application/Features/Role/Commands/UpdateRole/UpdateRoleCommandResponse.cs @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Application.Features.Role.Commands.UpdateRole -{ - public class UpdateRoleCommandResponse - { - - } -} \ No newline at end of file diff --git a/Core/HyBe.Application/HyBe.Application.csproj b/Core/HyBe.Application/HyBe.Application.csproj index 45b114c..6eb237b 100644 --- a/Core/HyBe.Application/HyBe.Application.csproj +++ b/Core/HyBe.Application/HyBe.Application.csproj @@ -7,12 +7,6 @@ - @@ -74,7 +68,6 @@ - diff --git a/Core/HyBe.Domain/Entities/Backtests/Backtest.cs b/Core/HyBe.Domain/Entities/Backtests/Backtest.cs index 01b1b30..f69e97f 100644 --- a/Core/HyBe.Domain/Entities/Backtests/Backtest.cs +++ b/Core/HyBe.Domain/Entities/Backtests/Backtest.cs @@ -1,16 +1,16 @@ using HyBe.Domain.Enums; -using HyBe.SharedKernel.Domain; -namespace HyBe.Domain.Entities.Backtests; -public class Backtest : BaseEntity -{ - public string Name { get; set; } - public Market Market { get; set; } - public OrderType OrderType { get; set; } - public PositionType PositionType { get; set; } - public TrendStrategy TrendStrategy { get; set; } - public int[]? Symbols { get; set; } - public int[]? Strategy { get; set; } - public int[]? Formation { get; set; } - public DateTimeOffset Start { get; set; } - public DateTimeOffset Finish { get; set; } +using HyBe.SharedKernel.Domain; +namespace HyBe.Domain.Entities.Backtests; +public class Backtest : BaseEntity +{ + public string Name { get; set; } + public Market Market { get; set; } + public OrderType OrderType { get; set; } + public PositionType PositionType { get; set; } + public TrendStrategy TrendStrategy { get; set; } + public int[]? Symbols { get; set; } + public int[]? Strategy { get; set; } + public int[]? Formation { get; set; } + public DateTimeOffset Start { get; set; } + public DateTimeOffset Finish { get; set; } } \ No newline at end of file diff --git a/Core/HyBe.Domain/Entities/Identity/AppRole.cs b/Core/HyBe.Domain/Entities/Identity/AppRole.cs index 87a8601..0a2f0e7 100644 --- a/Core/HyBe.Domain/Entities/Identity/AppRole.cs +++ b/Core/HyBe.Domain/Entities/Identity/AppRole.cs @@ -1,14 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; namespace HyBe.Domain.Entities.Identity { - public class AppRole : IdentityRole - { - public ICollection Endpoints { get; set; } - } + public class AppRole : IdentityRole + { + public ICollection Endpoints { get; set; } + } } \ No newline at end of file diff --git a/Core/HyBe.Domain/Entities/Identity/AppUser.cs b/Core/HyBe.Domain/Entities/Identity/AppUser.cs index 5de385c..778383d 100644 --- a/Core/HyBe.Domain/Entities/Identity/AppUser.cs +++ b/Core/HyBe.Domain/Entities/Identity/AppUser.cs @@ -1,15 +1,16 @@ -using Microsoft.AspNetCore.Identity; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; namespace HyBe.Domain.Entities.Identity { public class AppUser : IdentityUser - { - public string NameSurname { get; set; } - public string? RefreshToken { get; set; } - public DateTime? RefreshTokenEndDate { get; set; } - } + { + public string NameSurname { get; set; } + public string? RefreshToken { get; set; } + public DateTime? RefreshTokenEndDate { get; set; } + + } } \ No newline at end of file diff --git a/Core/HyBe.Domain/Entities/Identity/Endpoint.cs b/Core/HyBe.Domain/Entities/Identity/Endpoint.cs new file mode 100644 index 0000000..2093b1f --- /dev/null +++ b/Core/HyBe.Domain/Entities/Identity/Endpoint.cs @@ -0,0 +1,23 @@ +using HyBe.SharedKernel.Domain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Domain.Entities.Identity +{ + public class Endpoint : BaseEntity + { + public Endpoint() + { + Roles = new HashSet(); + } + public string ActionType { get; set; } + public string HttpType { get; set; } + public string Definition { get; set; } + public string Code { get; set; } + public Menu Menu { get; set; } + public ICollection Roles { get; set; } + } +} diff --git a/Core/HyBe.Domain/Entities/Identity/Menu.cs b/Core/HyBe.Domain/Entities/Identity/Menu.cs new file mode 100644 index 0000000..db07a9e --- /dev/null +++ b/Core/HyBe.Domain/Entities/Identity/Menu.cs @@ -0,0 +1,15 @@ +using HyBe.SharedKernel.Domain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Domain.Entities.Identity +{ + public class Menu : BaseEntity + { + public string Name { get; set; } + public ICollection Endpoints { get; set; } + } +} diff --git a/Core/HyBe.Domain/HyBe.Domain.csproj b/Core/HyBe.Domain/HyBe.Domain.csproj index 95915ad..5059972 100644 --- a/Core/HyBe.Domain/HyBe.Domain.csproj +++ b/Core/HyBe.Domain/HyBe.Domain.csproj @@ -30,12 +30,13 @@ - + - - + + diff --git a/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj b/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj index ebf8d74..033f5bc 100644 --- a/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj +++ b/Infrastructure/HyBe.Infrastructure/HyBe.Infrastructure.csproj @@ -7,6 +7,7 @@ + diff --git a/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs b/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs index 1eb43b4..48855ce 100644 --- a/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs +++ b/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs @@ -1,10 +1,10 @@ using System; using HyBe.Application.Abstractions.Infrastructure; using HyBe.Application.Abstractions.Services; -using HyBe.Application.Abstractions.Token; +// using HyBe.Application.Abstractions.Token; using HyBe.Infrastructure.Services; using HyBe.Infrastructure.Services.NotificationService; -using HyBe.Infrastructure.Services.Token; +// using HyBe.Infrastructure.Services.Token; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -14,9 +14,9 @@ public static class InfrastructureServiceRegistration { public static IServiceCollection AddInfrastructureServices(this IServiceCollection services) { - services.AddScoped(); - services.AddScoped(); - /* services.AddScoped(); */ + // services.AddScoped(); + // services.AddScoped(); + // services.AddScoped(); services.AddScoped(); return services; } diff --git a/Infrastructure/HyBe.Infrastructure/Services/MailService.cs b/Infrastructure/HyBe.Infrastructure/Services/MailService.cs index b61d7b8..b84ff5b 100644 --- a/Infrastructure/HyBe.Infrastructure/Services/MailService.cs +++ b/Infrastructure/HyBe.Infrastructure/Services/MailService.cs @@ -1,26 +1,26 @@ -using HyBe.Application.Abstractions.Services; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +// using HyBe.Application.Abstractions.Services; +// using System; +// using System.Collections.Generic; +// using System.Linq; +// using System.Threading.Tasks; -namespace HyBe.Infrastructure.Services -{ - public class MailService : IMailService - { - public Task SendMailAsync(string to, string subject, string body, bool isBodyHtml = true) - { - throw new NotImplementedException(); - } +// namespace HyBe.Infrastructure.Services +// { +// public class MailService : IMailService +// { +// public Task SendMailAsync(string to, string subject, string body, bool isBodyHtml = true) +// { +// throw new NotImplementedException(); +// } - public Task SendMailAsync(string[] tos, string subject, string body, bool isBodyHtml = true) - { - throw new NotImplementedException(); - } +// public Task SendMailAsync(string[] tos, string subject, string body, bool isBodyHtml = true) +// { +// throw new NotImplementedException(); +// } - public Task SendPasswordResetMailAsync(string to, string userId, string resetToken) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file +// public Task SendPasswordResetMailAsync(string to, string userId, string resetToken) +// { +// throw new NotImplementedException(); +// } +// } +// } \ No newline at end of file diff --git a/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs index a7f5691..1895af9 100644 --- a/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs +++ b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs @@ -1,7 +1,3 @@ -using HyBe.Application.Abstractions.Token; -using HyBe.Domain.Entities.Identity; -using Microsoft.Extensions.Configuration; -using Microsoft.IdentityModel.Tokens; using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; @@ -10,21 +6,58 @@ using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using Telegram.BotAPI.AvailableTypes; - +using HyBe.Application.Abstractions.Token; +using HyBe.Domain.Entities.Identity; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; namespace HyBe.Infrastructure.Services.Token { - public class TokenHandler : ITokenHandler - { - public Application.DTOs.Token CreateAccessToken(int second, AppUser appUser) - { - throw new NotImplementedException(); - } - - public string CreateRefreshToken() - { - throw new NotImplementedException(); - } - } + public class TokenHandler : ITokenHandler + { + readonly IConfiguration _configuration; + + public TokenHandler(IConfiguration configuration) + { + _configuration = configuration; + } + public Application.DTOs.Token CreateAccessToken(int second, AppUser user) + { + Application.DTOs.Token token = new(); + + //Security Key'in simetriğini alıyoruz. + SymmetricSecurityKey securityKey = new(Encoding.UTF8.GetBytes(_configuration["Token:SecurityKey"])); + + //Şifrelenmiş kimliği oluşturuyoruz. + SigningCredentials signingCredentials = new(securityKey, SecurityAlgorithms.HmacSha256); + + //Oluşturulacak token ayarlarını veriyoruz. + token.Expiration = DateTime.UtcNow.AddSeconds(second); + JwtSecurityToken securityToken = new( + audience: _configuration["Token:Audience"], + issuer: _configuration["Token:Issuer"], + expires: token.Expiration, + notBefore: DateTime.UtcNow, + signingCredentials: signingCredentials, + claims: new List { new(ClaimTypes.Name, user.UserName) } + ); + + //Token oluşturucu sınıfından bir örnek alalım. + JwtSecurityTokenHandler tokenHandler = new(); + token.AccessToken = tokenHandler.WriteToken(securityToken); + + //string refreshToken = CreateRefreshToken(); + + token.RefreshToken = CreateRefreshToken(); + return token; + } + + public string CreateRefreshToken() + { + byte[] number = new byte[32]; + using RandomNumberGenerator random = RandomNumberGenerator.Create(); + random.GetBytes(number); + return Convert.ToBase64String(number); + } + } } \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Contexts/HypanceDbContext.cs b/Infrastructure/HyBe.Persistence/Contexts/HypanceDbContext.cs index 413cb28..206a7d6 100644 --- a/Infrastructure/HyBe.Persistence/Contexts/HypanceDbContext.cs +++ b/Infrastructure/HyBe.Persistence/Contexts/HypanceDbContext.cs @@ -11,9 +11,11 @@ using HyBe.Domain.Entities.Wallets; using Microsoft.EntityFrameworkCore; using HyBe.Domain.Entities.Signals; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using HyBe.Domain.Entities.Identity; namespace HyBe.Persistence.Contexts; -public class HypanceDbContext : DbContext +public class HypanceDbContext : IdentityDbContext { #region Fields private readonly IDomainEventDispatcher _dispatcher; diff --git a/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj b/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj index 6523c50..6a34bb2 100644 --- a/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj +++ b/Infrastructure/HyBe.Persistence/HyBe.Persistence.csproj @@ -15,13 +15,16 @@ - + + + + diff --git a/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.Designer.cs b/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.Designer.cs new file mode 100644 index 0000000..6661d04 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.Designer.cs @@ -0,0 +1,621 @@ +// +using System; +using HyBe.Persistence.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HyBe.Persistence.Migrations +{ + [DbContext(typeof(HypanceDbContext))] + [Migration("20230318141515_migration1")] + partial class migration1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HyBe.Domain.Entities.Backtests.Backtest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Finish") + .HasColumnType("timestamp with time zone"); + + b.Property("Formation") + .HasColumnType("integer[]"); + + b.Property("Market") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderType") + .HasColumnType("integer"); + + b.Property("PositionType") + .HasColumnType("integer"); + + b.Property("Start") + .HasColumnType("timestamp with time zone"); + + b.Property("Strategy") + .HasColumnType("integer[]"); + + b.Property("Symbols") + .HasColumnType("integer[]"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Backtests"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Bot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AssetIds") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("BotOptions") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("FormationIds") + .HasColumnType("integer[]"); + + b.Property("Market") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderType") + .HasColumnType("integer"); + + b.Property("PositionType") + .HasColumnType("integer"); + + b.Property("PriceVolume") + .HasColumnType("numeric"); + + b.Property("StrategyIds") + .HasColumnType("integer[]"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Bots"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Formations.Formation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultPeriod") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Formations"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Formations.FormationSignal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("FormationSignalName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("Result") + .HasColumnType("boolean"); + + b.Property("SymbolName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("FormationSignals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.Indicator", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultPeriod") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Indicators"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.IndicatorSignal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IndicatorName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("Signals") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("SymbolName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("IndicatorSignals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IndicatorId") + .HasColumnType("integer"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("SignalResult") + .HasColumnType("integer"); + + b.Property("StrategyId") + .HasColumnType("uuid"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StrategyId"); + + b.ToTable("Signals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Strategies"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Symbols.Candlestick", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ClosePrice") + .HasColumnType("numeric"); + + b.Property("CloseTime") + .HasColumnType("timestamp with time zone"); + + b.Property("HighPrice") + .HasColumnType("numeric"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("LowPrice") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OpenPrice") + .HasColumnType("numeric"); + + b.Property("OpenTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Symbol") + .IsRequired() + .HasColumnType("text"); + + b.Property("Volume") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("Candlesticks"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Symbols.Symbol", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("MaxQuantity") + .HasColumnType("numeric"); + + b.Property("MinQuantity") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Symbols"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Wallets.Wallet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Balance") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("Wallets"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => + { + b.HasOne("HyBe.Domain.Entities.Strategies.Strategy", null) + .WithMany("Signals") + .HasForeignKey("StrategyId"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => + { + b.Navigation("Signals"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.cs b/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.cs new file mode 100644 index 0000000..066ca82 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Migrations/20230318141515_migration1.cs @@ -0,0 +1,223 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HyBe.Persistence.Migrations +{ + /// + public partial class migration1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "boolean", nullable: false), + PasswordHash = table.Column(type: "text", nullable: true), + SecurityStamp = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true), + PhoneNumber = table.Column(type: "text", nullable: true), + PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), + TwoFactorEnabled = table.Column(type: "boolean", nullable: false), + LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), + LockoutEnabled = table.Column(type: "boolean", nullable: false), + AccessFailedCount = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RoleId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(type: "text", nullable: false), + ProviderKey = table.Column(type: "text", nullable: false), + ProviderDisplayName = table.Column(type: "text", nullable: true), + UserId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(type: "text", nullable: false), + RoleId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(type: "text", nullable: false), + LoginProvider = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + Value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.Designer.cs b/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.Designer.cs new file mode 100644 index 0000000..f1430cf --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.Designer.cs @@ -0,0 +1,724 @@ +// +using System; +using HyBe.Persistence.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HyBe.Persistence.Migrations +{ + [DbContext(typeof(HypanceDbContext))] + [Migration("20230318194141_migration2")] + partial class migration2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("AppRoleEndpoint", b => + { + b.Property("EndpointsId") + .HasColumnType("uuid"); + + b.Property("RolesId") + .HasColumnType("text"); + + b.HasKey("EndpointsId", "RolesId"); + + b.HasIndex("RolesId"); + + b.ToTable("AppRoleEndpoint"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Backtests.Backtest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Finish") + .HasColumnType("timestamp with time zone"); + + b.Property("Formation") + .HasColumnType("integer[]"); + + b.Property("Market") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderType") + .HasColumnType("integer"); + + b.Property("PositionType") + .HasColumnType("integer"); + + b.Property("Start") + .HasColumnType("timestamp with time zone"); + + b.Property("Strategy") + .HasColumnType("integer[]"); + + b.Property("Symbols") + .HasColumnType("integer[]"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Backtests"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Bot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AssetIds") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("BotOptions") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("FormationIds") + .HasColumnType("integer[]"); + + b.Property("Market") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderType") + .HasColumnType("integer"); + + b.Property("PositionType") + .HasColumnType("integer"); + + b.Property("PriceVolume") + .HasColumnType("numeric"); + + b.Property("StrategyIds") + .HasColumnType("integer[]"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Bots"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Formations.Formation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultPeriod") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Formations"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Formations.FormationSignal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("FormationSignalName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("Result") + .HasColumnType("boolean"); + + b.Property("SymbolName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("FormationSignals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.AppRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.AppUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NameSurname") + .IsRequired() + .HasColumnType("text"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("RefreshToken") + .HasColumnType("text"); + + b.Property("RefreshTokenEndDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Endpoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ActionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("Code") + .IsRequired() + .HasColumnType("text"); + + b.Property("Definition") + .IsRequired() + .HasColumnType("text"); + + b.Property("HttpType") + .IsRequired() + .HasColumnType("text"); + + b.Property("MenuId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("MenuId"); + + b.ToTable("Endpoint"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Menu", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Menu"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.Indicator", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultPeriod") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Indicators"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.IndicatorSignal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IndicatorName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("Signals") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("SymbolName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("IndicatorSignals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IndicatorId") + .HasColumnType("integer"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Period") + .HasColumnType("integer"); + + b.Property("SignalResult") + .HasColumnType("integer"); + + b.Property("StrategyId") + .HasColumnType("uuid"); + + b.Property("TrendStrategy") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StrategyId"); + + b.ToTable("Signals"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Strategies"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Symbols.Candlestick", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ClosePrice") + .HasColumnType("numeric"); + + b.Property("CloseTime") + .HasColumnType("timestamp with time zone"); + + b.Property("HighPrice") + .HasColumnType("numeric"); + + b.Property("Interval") + .HasColumnType("integer"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("LowPrice") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OpenPrice") + .HasColumnType("numeric"); + + b.Property("OpenTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Symbol") + .IsRequired() + .HasColumnType("text"); + + b.Property("Volume") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("Candlesticks"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Symbols.Symbol", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("MaxQuantity") + .HasColumnType("numeric"); + + b.Property("MinQuantity") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Symbols"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Wallets.Wallet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Balance") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("Wallets"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("AppRoleEndpoint", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.Endpoint", null) + .WithMany() + .HasForeignKey("EndpointsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RolesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Endpoint", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.Menu", "Menu") + .WithMany("Endpoints") + .HasForeignKey("MenuId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Menu"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => + { + b.HasOne("HyBe.Domain.Entities.Strategies.Strategy", null) + .WithMany("Signals") + .HasForeignKey("StrategyId"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Menu", b => + { + b.Navigation("Endpoints"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => + { + b.Navigation("Signals"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.cs b/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.cs new file mode 100644 index 0000000..7eb26d9 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Migrations/20230318194141_migration2.cs @@ -0,0 +1,127 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace HyBe.Persistence.Migrations +{ + /// + public partial class migration2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "NameSurname", + table: "AspNetUsers", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "RefreshToken", + table: "AspNetUsers", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "RefreshTokenEndDate", + table: "AspNetUsers", + type: "timestamp with time zone", + nullable: true); + + migrationBuilder.CreateTable( + name: "Menu", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Menu", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Endpoint", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + ActionType = table.Column(type: "text", nullable: false), + HttpType = table.Column(type: "text", nullable: false), + Definition = table.Column(type: "text", nullable: false), + Code = table.Column(type: "text", nullable: false), + MenuId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Endpoint", x => x.Id); + table.ForeignKey( + name: "FK_Endpoint_Menu_MenuId", + column: x => x.MenuId, + principalTable: "Menu", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AppRoleEndpoint", + columns: table => new + { + EndpointsId = table.Column(type: "uuid", nullable: false), + RolesId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AppRoleEndpoint", x => new { x.EndpointsId, x.RolesId }); + table.ForeignKey( + name: "FK_AppRoleEndpoint_AspNetRoles_RolesId", + column: x => x.RolesId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AppRoleEndpoint_Endpoint_EndpointsId", + column: x => x.EndpointsId, + principalTable: "Endpoint", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AppRoleEndpoint_RolesId", + table: "AppRoleEndpoint", + column: "RolesId"); + + migrationBuilder.CreateIndex( + name: "IX_Endpoint_MenuId", + table: "Endpoint", + column: "MenuId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AppRoleEndpoint"); + + migrationBuilder.DropTable( + name: "Endpoint"); + + migrationBuilder.DropTable( + name: "Menu"); + + migrationBuilder.DropColumn( + name: "NameSurname", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "RefreshToken", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "RefreshTokenEndDate", + table: "AspNetUsers"); + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Migrations/HypanceDbContextModelSnapshot.cs b/Infrastructure/HyBe.Persistence/Migrations/HypanceDbContextModelSnapshot.cs index e71dd24..7f53681 100644 --- a/Infrastructure/HyBe.Persistence/Migrations/HypanceDbContextModelSnapshot.cs +++ b/Infrastructure/HyBe.Persistence/Migrations/HypanceDbContextModelSnapshot.cs @@ -17,11 +17,26 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.2") + .HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("AppRoleEndpoint", b => + { + b.Property("EndpointsId") + .HasColumnType("uuid"); + + b.Property("RolesId") + .HasColumnType("text"); + + b.HasKey("EndpointsId", "RolesId"); + + b.HasIndex("RolesId"); + + b.ToTable("AppRoleEndpoint"); + }); + modelBuilder.Entity("HyBe.Domain.Entities.Backtests.Backtest", b => { b.Property("Id") @@ -163,6 +178,153 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("FormationSignals"); }); + modelBuilder.Entity("HyBe.Domain.Entities.Identity.AppRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.AppUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NameSurname") + .IsRequired() + .HasColumnType("text"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("RefreshToken") + .HasColumnType("text"); + + b.Property("RefreshTokenEndDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Endpoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ActionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("Code") + .IsRequired() + .HasColumnType("text"); + + b.Property("Definition") + .IsRequired() + .HasColumnType("text"); + + b.Property("HttpType") + .IsRequired() + .HasColumnType("text"); + + b.Property("MenuId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("MenuId"); + + b.ToTable("Endpoint"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Menu", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Menu"); + }); + modelBuilder.Entity("HyBe.Domain.Entities.Indicators.Indicator", b => { b.Property("Id") @@ -216,7 +378,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("IndicatorSignals"); }); - modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Signal", b => + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -354,13 +516,201 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Wallets"); }); - modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Signal", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("AppRoleEndpoint", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.Endpoint", null) + .WithMany() + .HasForeignKey("EndpointsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RolesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Endpoint", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.Menu", "Menu") + .WithMany("Endpoints") + .HasForeignKey("MenuId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Menu"); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Signals.Signal", b => { b.HasOne("HyBe.Domain.Entities.Strategies.Strategy", null) .WithMany("Signals") .HasForeignKey("StrategyId"); }); + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("HyBe.Domain.Entities.Identity.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyBe.Domain.Entities.Identity.Menu", b => + { + b.Navigation("Endpoints"); + }); + modelBuilder.Entity("HyBe.Domain.Entities.Strategies.Strategy", b => { b.Navigation("Signals"); diff --git a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs index cfd1b52..0c9ef89 100644 --- a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs +++ b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs @@ -1,10 +1,12 @@ using HyBe.Application.Abstractions.Services; -using HyBe.Application.Abstractions.Services.Authentications; +using HyBe.Domain.Entities.Identity; +// using HyBe.Application.Abstractions.Services.Authentications; using HyBe.Persistence.Contexts; using HyBe.Persistence.Repositories; using HyBe.Persistence.Services; using HyBe.SharedKernel.Events; using HyBe.SharedKernel.Repositories; +using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -16,7 +18,18 @@ public static IServiceCollection AddPersistenceServices(this IServiceCollection IConfiguration configuration) { services.AddDbContext(options => options.UseNpgsql(configuration.GetConnectionString("HypanceConnectionString"))); - services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>)); + + services.AddIdentity(options => + { + options.Password.RequiredLength = 3; + options.Password.RequireNonAlphanumeric = false; + options.Password.RequireDigit = false; + options.Password.RequireLowercase = false; + options.Password.RequireUppercase = false; + }).AddEntityFrameworkStores() + .AddDefaultTokenProviders(); + + services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>)); services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -30,10 +43,11 @@ public static IServiceCollection AddPersistenceServices(this IServiceCollection services.AddScoped(); services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - + // services.AddScoped(); + // services.AddScoped(); + // services.AddScoped(); + // services.AddScoped(); + services.AddScoped(); diff --git a/Infrastructure/HyBe.Persistence/Services/AuthService.cs b/Infrastructure/HyBe.Persistence/Services/AuthService.cs index bb3b24d..e69de29 100644 --- a/Infrastructure/HyBe.Persistence/Services/AuthService.cs +++ b/Infrastructure/HyBe.Persistence/Services/AuthService.cs @@ -1,102 +0,0 @@ -using HyBe.Application.Abstractions.Services; -using HyBe.Application.Abstractions.Token; -using HyBe.Application.DTOs; -using HyBe.Application.Exceptions; -using HyBe.Application.Helpers; -using HyBe.Domain.Entities.Identity; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Persistence.Services -{ - public class AuthService : IAuthService - { - readonly HttpClient _httpClient; - readonly IConfiguration _configuration; - readonly UserManager _userManager; - readonly ITokenHandler _tokenHandler; - readonly SignInManager _signInManager; - readonly IUserService _userService; - readonly IMailService _mailService; - public AuthService(IHttpClientFactory httpClientFactory, - IConfiguration configuration, - UserManager userManager, - ITokenHandler tokenHandler, - SignInManager signInManager, - IUserService userService, - IMailService mailService) - { - _httpClient = httpClientFactory.CreateClient(); - _configuration = configuration; - _userManager = userManager; - _tokenHandler = tokenHandler; - _signInManager = signInManager; - _userService = userService; - _mailService = mailService; - } - public async Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime) - { - Domain.Entities.Identity.AppUser user = await _userManager.FindByNameAsync(usernameOrEmail); - if (user == null) - user = await _userManager.FindByEmailAsync(usernameOrEmail); - - if (user == null) - throw new NotFoundUserException(); - - SignInResult result = await _signInManager.CheckPasswordSignInAsync(user, password, false); - if (result.Succeeded) //Authentication başarılı! - { - Token token = _tokenHandler.CreateAccessToken(accessTokenLifeTime, user); - await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 15); - return token; - } - throw new AuthenticationErrorException(); - } - public async Task PasswordResetAsync(string email) - { - AppUser user = await _userManager.FindByEmailAsync(email); - if (user != null) - { - string resetToken = await _userManager.GeneratePasswordResetTokenAsync(user); - - //byte[] tokenBytes = Encoding.UTF8.GetBytes(resetToken); - //resetToken = WebEncoders.Base64UrlEncode(tokenBytes); - resetToken = resetToken.UrlEncode(); - - await _mailService.SendPasswordResetMailAsync(email, user.Id, resetToken); - } - } - - public async Task RefreshTokenLoginAsync(string refreshToken) - { - AppUser? user = await _userManager.Users.FirstOrDefaultAsync(u => u.RefreshToken == refreshToken); - if (user != null && user?.RefreshTokenEndDate > DateTime.UtcNow) - { - Token token = _tokenHandler.CreateAccessToken(15, user); - await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 300); - return token; - } - else - throw new NotFoundUserException(); - } - - public async Task VerifyResetTokenAsync(string resetToken, string userId) - { - AppUser user = await _userManager.FindByIdAsync(userId); - if (user != null) - { - //byte[] tokenBytes = WebEncoders.Base64UrlDecode(resetToken); - //resetToken = Encoding.UTF8.GetString(tokenBytes); - resetToken = resetToken.UrlDecode(); - - return await _userManager.VerifyUserTokenAsync(user, _userManager.Options.Tokens.PasswordResetTokenProvider, "ResetPassword", resetToken); - } - return false; - } - } -} \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs b/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Infrastructure/HyBe.Persistence/Services/AuthorizationEndpointService.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/RoleService.cs b/Infrastructure/HyBe.Persistence/Services/RoleService.cs index b4c5ac6..e69de29 100644 --- a/Infrastructure/HyBe.Persistence/Services/RoleService.cs +++ b/Infrastructure/HyBe.Persistence/Services/RoleService.cs @@ -1,60 +0,0 @@ -using HyBe.Application.Abstractions.Services; -using HyBe.Domain.Entities.Identity; -using Microsoft.AspNetCore.Identity; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HyBe.Persistence.Services -{ - public class RoleService : IRoleService - { - readonly RoleManager _roleManager; - - public RoleService(RoleManager roleManager) - { - _roleManager = roleManager; - } - public async Task CreateRole(string name) - { - IdentityResult result = await _roleManager.CreateAsync(new() { Id = Guid.NewGuid().ToString(), Name = name }); - return result.Succeeded; - } - - public async Task DeleteRole(string id) - { - AppRole appRole = await _roleManager.FindByIdAsync(id); - IdentityResult result = await _roleManager.DeleteAsync(appRole); - return result.Succeeded; - } - - public (object, int) GetAllRoles(int page, int size) - { - var query = _roleManager.Roles; - - IQueryable rolesQuery = null; - - if (page != -1 && size != -1) - rolesQuery = query.Skip(page * size).Take(size); - else - rolesQuery = query; - - return (rolesQuery.Select(r => new { r.Id, r.Name }), query.Count()); - } - - public async Task<(string id, string name)> GetRoleById(string id) - { - string role = await _roleManager.GetRoleIdAsync(new() { Id = id }); - return (id, role); - } - - public async Task UpdateRole(string id, string name) - { - AppRole role = await _roleManager.FindByIdAsync(id); - role.Name = name; - IdentityResult result = await _roleManager.UpdateAsync(role); - return result.Succeeded; - } - } -} \ No newline at end of file diff --git a/Infrastructure/HyBe.Persistence/Services/UserService.cs b/Infrastructure/HyBe.Persistence/Services/UserService.cs index 32dd1bb..340df51 100644 --- a/Infrastructure/HyBe.Persistence/Services/UserService.cs +++ b/Infrastructure/HyBe.Persistence/Services/UserService.cs @@ -1,11 +1,7 @@ using HyBe.Application.Abstractions.Services; using HyBe.Application.DTOs.User; -using HyBe.Application.Exceptions; -using HyBe.Application.Helpers; -using HyBe.Domain.Entities; using HyBe.Domain.Entities.Identity; using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -13,99 +9,33 @@ namespace HyBe.Persistence.Services { - public class UserService : IUserService - { - readonly UserManager_userManager; - public UserService(UserManager userManager) - { - _userManager = userManager; - } - - public int TotalUsersCount => _userManager.Users.Count(); - - public Task AssignRoleToUserAsnyc(string userId, string[] roles) - { - throw new NotImplementedException(); - } - - public async Task CreateAsync(CreateUser model) - { - IdentityResult result = await _userManager.CreateAsync(new() - { - Id = Guid.NewGuid().ToString(), - UserName = model.Username, - Email = model.Email, - NameSurname = model.NameSurname, - }, model.Password); - - CreateUserResponse response = new() { Succeeded = result.Succeeded }; - - if (result.Succeeded) - response.Message = "Kullanici basarili bir sekilde olusturulmustur!"; - else - foreach (var error in result.Errors) - response.Message += $"{error.Code} - {error.Description}\n"; - - return response; - } - public async Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate) - { - if (user != null) + public class UserService : IUserService + { + readonly UserManager _userManager; + public UserService(UserManager userManager) + { + _userManager = userManager; + } + public async Task CreateAsync(CreateUser model) + { + IdentityResult result = await _userManager.CreateAsync(new() { - user.RefreshToken = refreshToken; - user.RefreshTokenEndDate = accessTokenDate.AddSeconds(addOnAccessTokenDate); - await _userManager.UpdateAsync(user); - } - else + Id = Guid.NewGuid().ToString(), + UserName = model.Username, + Email = model.Email, + NameSurname = model.NameSurname, + }, model.Password); - throw new NotFoundUserException(); - } + CreateUserResponse response = new() { Succeeded = result.Succeeded }; - public async Task UpdatePasswordAsync(string userId, string resetToken, string newPassword) - { - AppUser user = await _userManager.FindByIdAsync(userId); - if (user != null) - { - resetToken = resetToken.UrlDecode(); - IdentityResult result = await _userManager.ResetPasswordAsync(user, resetToken, newPassword); - if (result.Succeeded) - await _userManager.UpdateSecurityStampAsync(user); - else - throw new PasswordChangeFailedException(); - } - } - - public async Task> GetAllUsersAsync(int page, int size) - { - var users = await _userManager.Users - .Skip(page * size) - .Take(size) - .ToListAsync(); - - return users.Select(user => new ListUser - { - Id = user.Id, - Email = user.Email, - NameSurname = user.NameSurname, - TwoFactorEnabled = user.TwoFactorEnabled, - UserName = user.UserName - - }).ToList(); - } - - public async Task GetRolesToUserAsync(string userIdOrName) - { - AppUser user = await _userManager.FindByIdAsync(userIdOrName); - if (user == null) - user = await _userManager.FindByNameAsync(userIdOrName); + if (result.Succeeded) + response.Message = "Kullanıcı başarıyla oluşturulmuştur."; + else + foreach (var error in result.Errors) + response.Message += $"{error.Code} - {error.Description}\n"; - if (user != null) - { - var userRoles = await _userManager.GetRolesAsync(user); - return userRoles.ToArray(); - } - return new string[] { }; - } + return response; + } - } + } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Presentation/HyBe.WebAPI/Controllers/ApplicationServicesController.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs index ea0cd11..e69de29 100644 --- a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using HyBe.Application.Features.AppUser.Commands.LoginUser; -using HyBe.Application.Features.AppUser.Commands.PasswordReset; -using HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin; -using HyBe.Application.Features.AppUser.Commands.VerifyResetToken; -using MediatR; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; - -namespace HyBe.WebAPI.Controllers -{ - [Route("api/[controller]")] - [ApiController] - public class AuthController : ControllerBase - { - readonly IMediator _mediator; - public AuthController(IMediator mediator) - { - _mediator = mediator; - } - [HttpPost("[action]")] - public async Task Login(LoginUserCommandRequest loginUserCommandRequest) - { - LoginUserCommandResponse response = await _mediator.Send(loginUserCommandRequest); - return Ok(response); - } - - [HttpPost("[action]")] - public async Task RefreshTokenLogin([FromBody] RefreshTokenLoginCommandRequest refreshTokenLoginCommandRequest) - { - RefreshTokenLoginCommandResponse response = await _mediator.Send(refreshTokenLoginCommandRequest); - return Ok(response); - } - - [HttpPost("password-reset")] - public async Task PasswordReset([FromBody] PasswordResetCommandRequest passwordResetCommandRequest) - { - PasswordResetCommandResponse response = await _mediator.Send(passwordResetCommandRequest); - return Ok(response); - } - - [HttpPost("verify-reset-token")] - public async Task VerifyResetToken([FromBody] VerifyResetTokenCommandRequest verifyResetTokenCommandRequest) - { - VerifyResetTokenCommandResponse response = await _mediator.Send(verifyResetTokenCommandRequest); - return Ok(response); - } - } -} \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/RolesController.cs b/Presentation/HyBe.WebAPI/Controllers/RolesController.cs index 3d5b5d1..e69de29 100644 --- a/Presentation/HyBe.WebAPI/Controllers/RolesController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/RolesController.cs @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using HyBe.Application.CustomAttributes; -using HyBe.Application.Features.Role.Commands.CreateRole; -using HyBe.Application.Features.Role.Commands.DeleteRole; -using HyBe.Application.Features.Role.Commands.UpdateRole; -using HyBe.Application.Features.Role.Queries.GetRoleById; -using HyBe.Application.Features.Role.Queries.GetRoles; -using HyBe.Domain.Enums; -using MediatR; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace HyBe.WebAPI.Controllers -{ - [Route("api/[controller]")] - [ApiController] - [Authorize(AuthenticationSchemes = "Admin")] - public class RolesController : ControllerBase - { - readonly IMediator _mediator; - - public RolesController(IMediator mediator) - { - _mediator = mediator; - } - - [HttpGet] - [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get Roles", Menu = "Roles")] - public async Task GetRoles([FromQuery] GetRolesQueryRequest getRolesQueryRequest) - { - GetRolesQueryResponse response = await _mediator.Send(getRolesQueryRequest); - return Ok(response); - } - - [HttpGet("{Id}")] - [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get Role By Id", Menu = "Roles")] - public async Task GetRoles([FromRoute] GetRoleByIdQueryRequest getRoleByIdQueryRequest) - { - GetRoleByIdQueryResponse response = await _mediator.Send(getRoleByIdQueryRequest); - return Ok(response); - } - - [HttpPost()] - [AuthorizeDefinition(ActionType = ActionType.Writing, Definition = "Create Role", Menu = "Roles")] - public async Task CreateRole([FromBody] CreateRoleCommandRequest createRoleCommandRequest) - { - CreateRoleCommandResponse response = await _mediator.Send(createRoleCommandRequest); - return Ok(response); - } - - [HttpPut("{Id}")] - [AuthorizeDefinition(ActionType = ActionType.Updating, Definition = "Update Role", Menu = "Roles")] - public async Task UpdateRole([FromBody, FromRoute] UpdateRoleCommandRequest updateRoleCommandRequest) - { - UpdateRoleCommandResponse response = await _mediator.Send(updateRoleCommandRequest); - return Ok(response); - } - - [HttpDelete("{Id}")] - [AuthorizeDefinition(ActionType = ActionType.Deleting, Definition = "Delete Role", Menu = "Roles")] - public async Task DeleteRole([FromRoute] DeleteRoleCommandRequest deleteRoleCommandRequest) - { - DeleteRoleCommandResponse response = await _mediator.Send(deleteRoleCommandRequest); - return Ok(response); - } - } -} \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs index 9a4ced8..5bc59e2 100644 --- a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs @@ -3,12 +3,7 @@ using System.Linq; using System.Threading.Tasks; using HyBe.Application.Abstractions.Services; -using HyBe.Application.CustomAttributes; -using HyBe.Application.Features.AppUser.Commands.AssignRoleToUser; using HyBe.Application.Features.AppUser.Commands.CreateUser; -using HyBe.Application.Features.AppUser.Commands.UpdatePassword; -using HyBe.Application.Features.AppUser.Queries.GetAllUsers; -using HyBe.Application.Features.AppUser.Queries.GetRolesToUser; using HyBe.Domain.Enums; using MediatR; using Microsoft.AspNetCore.Authorization; @@ -22,52 +17,17 @@ namespace HyBe.WebAPI.Controllers public class UsersController : ControllerBase { readonly IMediator _mediator; - readonly IMailService _mailService; - public UsersController(IMediator mediator, IMailService mailService) + public UsersController(IMediator mediator) { _mediator = mediator; - _mailService = mailService; - } - [HttpPost("create-user")] - public async Task CreateUser(CreateUserCommandRequest createUserCommandRequest) - { - CreateUserCommandResponse response = await _mediator.Send(createUserCommandRequest); - return Ok(response); } - - [HttpPost("update-password")] - public async Task UpdatePassword([FromBody] UpdatePasswordCommandRequest updatePasswordCommandRequest) - { - UpdatePasswordCommandResponse response = await _mediator.Send(updatePasswordCommandRequest); - return Ok(response); - } - - [HttpGet("get-user")] - [Authorize(AuthenticationSchemes = "Admin")] - [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get All Users", Menu = "Users")] - public async Task GetAllUsers([FromQuery] GetAllUsersQueryRequest getAllUsersQueryRequest) + [HttpPost] + public async Task CreateUser(CreateUserCommandRequest createUserCommandRequest) { - GetAllUsersQueryResponse response = await _mediator.Send(getAllUsersQueryRequest); - return Ok(response); - } - - [HttpGet("get-roles-to-user/{UserId}")] - [Authorize(AuthenticationSchemes = "Admin")] - [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get Roles To Users", Menu = "Users")] - public async Task GetRolesToUser([FromRoute]GetRolesToUserQueryRequest getRolesToUserQueryRequest) - { - GetRolesToUserQueryResponse response = await _mediator.Send(getRolesToUserQueryRequest); + CreateUserCommandResponse response = await _mediator.Send(createUserCommandRequest); return Ok(response); } - [HttpPost("assign-role-to-user")] - [Authorize(AuthenticationSchemes = "Admin")] - [AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Assign Role To User", Menu = "Users")] - public async Task AssignRoleToUser(AssignRoleToUserCommandRequest assignRoleToUserCommandRequest) - { - AssignRoleToUserCommandResponse response = await _mediator.Send(assignRoleToUserCommandRequest); - return Ok(response); - } } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Program.cs b/Presentation/HyBe.WebAPI/Program.cs index 7265caa..e49ef6a 100644 --- a/Presentation/HyBe.WebAPI/Program.cs +++ b/Presentation/HyBe.WebAPI/Program.cs @@ -13,7 +13,7 @@ // Add services to the container. builder.Services.AddControllers(); builder.Services.AddApplicationServices(); -//builder.Services.AddHttpContextAccessor(); +builder.Services.AddHttpContextAccessor(); builder.Services.AddPersistenceServices(builder.Configuration); builder.Services.AddInfrastructureServices(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -55,18 +55,12 @@ app.UseHttpLogging(); app.UseCors(); + app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); -/* app.Use(async (context, next) => -{ - var username = context.User?.Identity?.IsAuthenticated != null || true ? context.User.Identity.Name : null; - LogContext.PushProperty("user_name", username); - await next(); -}); */ - app.MapControllers(); app.Run(); From 82d1bcc944b1d05d666f54234ade922e7b9d6c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20S=C3=B6nmez?= Date: Sun, 19 Mar 2023 02:12:46 +0300 Subject: [PATCH 26/27] added authentication --- .../IInternalAuthentication.cs | 14 +++ .../Abstractions/Services/IAuthService.cs | 15 +++ .../Abstractions/Services/IUserService.cs | 4 +- .../LoginUser/LoginUserCommandHandler.cs | 24 +++++ .../LoginUser/LoginUserCommandRequest.cs | 10 ++ .../LoginUser/LoginUserCommandResponse.cs | 17 +++ .../RefreshTokenLoginCommandHandler.cs | 29 +++++ .../RefreshTokenLoginCommandRequest.cs | 14 +++ .../RefreshTokenLoginCommandResponse.cs | 14 +++ .../InfrastructureServiceRegistration.cs | 4 +- .../PersistenceServiceRegistration.cs | 5 +- .../HyBe.Persistence/Services/AuthService.cs | 101 ++++++++++++++++++ .../HyBe.Persistence/Services/UserService.cs | 12 +++ .../HyBe.WebAPI/Controllers/AuthController.cs | 30 ++++++ .../Controllers/UsersController.cs | 2 +- 15 files changed, 290 insertions(+), 5 deletions(-) diff --git a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs index e69de29..dc4067f 100644 --- a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs +++ b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Application.Abstractions.Services.Authentications +{ + public interface IInternalAuthentication + { + Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime); + Task RefreshTokenLoginAsync(string refreshToken); + } +} diff --git a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs index e69de29..295a6f5 100644 --- a/Core/HyBe.Application/Abstractions/Services/IAuthService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IAuthService.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HyBe.Application.Abstractions.Services.Authentications; + +namespace HyBe.Application.Abstractions.Services +{ + public interface IAuthService : IInternalAuthentication + { + Task PasswordResetAsnyc(string email); + Task VerifyResetTokenAsync(string resetToken, string userId); + } +} diff --git a/Core/HyBe.Application/Abstractions/Services/IUserService.cs b/Core/HyBe.Application/Abstractions/Services/IUserService.cs index b28f4e7..a81e907 100644 --- a/Core/HyBe.Application/Abstractions/Services/IUserService.cs +++ b/Core/HyBe.Application/Abstractions/Services/IUserService.cs @@ -1,9 +1,11 @@ using HyBe.Application.DTOs.User; +using HyBe.Domain.Entities.Identity; namespace HyBe.Application.Abstractions.Services { public interface IUserService { Task CreateAsync(CreateUser model); - } + Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate); + } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs index e69de29..d884a8a 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs @@ -0,0 +1,24 @@ +using HyBe.Application.Abstractions.Services; +using MediatR; + +namespace HyBe.Application.Features.AppUser.Commands.LoginUser +{ + public class LoginUserCommandHandler : IRequestHandler + { + readonly IAuthService _authService; + public LoginUserCommandHandler(IAuthService authService) + { + _authService = authService; + } + + public async Task Handle(LoginUserCommandRequest request, CancellationToken cancellationToken) + { + var token = await _authService.LoginAsync(request.UsernameOrEmail, request.Password, 900); + return new LoginUserSuccessCommandResponse() + { + Token = token + }; + } + } +} + diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs index e69de29..8696b75 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandRequest.cs @@ -0,0 +1,10 @@ +using MediatR; + +namespace HyBe.Application.Features.AppUser.Commands.LoginUser +{ + public class LoginUserCommandRequest : IRequest + { + public string UsernameOrEmail { get; set; } + public string Password { get; set; } + } +} diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs index e69de29..8aa5145 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandResponse.cs @@ -0,0 +1,17 @@ +using HyBe.Application.DTOs; + +namespace HyBe.Application.Features.AppUser.Commands.LoginUser +{ + public class LoginUserCommandResponse + { + + } + public class LoginUserSuccessCommandResponse : LoginUserCommandResponse + { + public Token Token { get; set; } + } + public class LoginUserErrorCommandResponse : LoginUserCommandResponse + { + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs index e69de29..76e31d3 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandHandler.cs @@ -0,0 +1,29 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.DTOs; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin +{ + public class RefreshTokenLoginCommandHandler : IRequestHandler + { + readonly IAuthService _authService; + public RefreshTokenLoginCommandHandler(IAuthService authService) + { + _authService = authService; + } + + public async Task Handle(RefreshTokenLoginCommandRequest request, CancellationToken cancellationToken) + { + Token token = await _authService.RefreshTokenLoginAsync(request.RefreshToken); + return new() + { + Token = token + }; + } + } +} diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs index e69de29..42cabc0 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandRequest.cs @@ -0,0 +1,14 @@ +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin +{ + public class RefreshTokenLoginCommandRequest : IRequest + { + public string RefreshToken { get; set; } + } +} \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs index e69de29..45d9a4a 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/RefreshTokenLogin/RefreshTokenLoginCommandResponse.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HyBe.Application.DTOs; + +namespace HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin +{ + public class RefreshTokenLoginCommandResponse + { + public Token Token { get; set; } + } +} diff --git a/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs b/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs index 48855ce..9de0abe 100644 --- a/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs +++ b/Infrastructure/HyBe.Infrastructure/InfrastructureServiceRegistration.cs @@ -1,9 +1,11 @@ using System; using HyBe.Application.Abstractions.Infrastructure; using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Token; // using HyBe.Application.Abstractions.Token; using HyBe.Infrastructure.Services; using HyBe.Infrastructure.Services.NotificationService; +using HyBe.Infrastructure.Services.Token; // using HyBe.Infrastructure.Services.Token; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -14,7 +16,7 @@ public static class InfrastructureServiceRegistration { public static IServiceCollection AddInfrastructureServices(this IServiceCollection services) { - // services.AddScoped(); + services.AddScoped(); // services.AddScoped(); // services.AddScoped(); services.AddScoped(); diff --git a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs index 0c9ef89..26ebb02 100644 --- a/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs +++ b/Infrastructure/HyBe.Persistence/PersistenceServiceRegistration.cs @@ -1,4 +1,5 @@ using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Services.Authentications; using HyBe.Domain.Entities.Identity; // using HyBe.Application.Abstractions.Services.Authentications; using HyBe.Persistence.Contexts; @@ -43,8 +44,8 @@ public static IServiceCollection AddPersistenceServices(this IServiceCollection services.AddScoped(); services.AddScoped(); - // services.AddScoped(); - // services.AddScoped(); + services.AddScoped(); + services.AddScoped(); // services.AddScoped(); // services.AddScoped(); diff --git a/Infrastructure/HyBe.Persistence/Services/AuthService.cs b/Infrastructure/HyBe.Persistence/Services/AuthService.cs index e69de29..95d34d9 100644 --- a/Infrastructure/HyBe.Persistence/Services/AuthService.cs +++ b/Infrastructure/HyBe.Persistence/Services/AuthService.cs @@ -0,0 +1,101 @@ +using HyBe.Application.Abstractions.Services; +using HyBe.Application.Abstractions.Token; +using HyBe.Application.DTOs; +using HyBe.Application.Exceptions; +using HyBe.Domain.Entities.Identity; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; + +namespace HyBe.Persistence.Services +{ + public class AuthService : IAuthService + { + readonly UserManager _userManager; + readonly ITokenHandler _tokenHandler; + readonly SignInManager _signInManager; + readonly IUserService _userService; + public AuthService( + UserManager userManager, + ITokenHandler tokenHandler, + SignInManager signInManager, + IUserService userService) + { + _userManager = userManager; + _tokenHandler = tokenHandler; + _signInManager = signInManager; + _userService = userService; + } + async Task CreateUserExternalAsync(AppUser user, string email, string name, UserLoginInfo info, int accessTokenLifeTime) + { + bool result = user != null; + if (user == null) + { + user = await _userManager.FindByEmailAsync(email); + if (user == null) + { + user = new() + { + Id = Guid.NewGuid().ToString(), + Email = email, + UserName = email, + NameSurname = name + }; + var identityResult = await _userManager.CreateAsync(user); + result = identityResult.Succeeded; + } + } + + if (result) + { + await _userManager.AddLoginAsync(user, info); //AspNetUserLogins + + Token token = _tokenHandler.CreateAccessToken(accessTokenLifeTime, user); + await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 15); + return token; + } + throw new Exception("Invalid external authentication."); + } + + public async Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime) + { + Domain.Entities.Identity.AppUser user = await _userManager.FindByNameAsync(usernameOrEmail); + if (user == null) + user = await _userManager.FindByEmailAsync(usernameOrEmail); + + if (user == null) + throw new NotFoundUserException(); + + SignInResult result = await _signInManager.CheckPasswordSignInAsync(user, password, false); + if (result.Succeeded) //Authentication başarılı! + { + Token token = _tokenHandler.CreateAccessToken(accessTokenLifeTime, user); + await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 15); + return token; + } + throw new AuthenticationErrorException(); + } + + public Task PasswordResetAsnyc(string email) + { + throw new NotImplementedException(); + } + + public async Task RefreshTokenLoginAsync(string refreshToken) + { + AppUser? user = await _userManager.Users.FirstOrDefaultAsync(u => u.RefreshToken == refreshToken); + if (user != null && user?.RefreshTokenEndDate > DateTime.UtcNow) + { + Token token = _tokenHandler.CreateAccessToken(15, user); + await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 300); + return token; + } + else + throw new NotFoundUserException(); + } + + public Task VerifyResetTokenAsync(string resetToken, string userId) + { + throw new NotImplementedException(); + } + } +} diff --git a/Infrastructure/HyBe.Persistence/Services/UserService.cs b/Infrastructure/HyBe.Persistence/Services/UserService.cs index 340df51..00a8280 100644 --- a/Infrastructure/HyBe.Persistence/Services/UserService.cs +++ b/Infrastructure/HyBe.Persistence/Services/UserService.cs @@ -1,5 +1,6 @@ using HyBe.Application.Abstractions.Services; using HyBe.Application.DTOs.User; +using HyBe.Application.Exceptions; using HyBe.Domain.Entities.Identity; using Microsoft.AspNetCore.Identity; using System; @@ -37,5 +38,16 @@ public async Task CreateAsync(CreateUser model) return response; } + public async Task UpdateRefreshTokenAsync(string refreshToken, AppUser user, DateTime accessTokenDate, int addOnAccessTokenDate) + { + if (user != null) + { + user.RefreshToken = refreshToken; + user.RefreshTokenEndDate = accessTokenDate.AddSeconds(addOnAccessTokenDate); + await _userManager.UpdateAsync(user); + } + else + throw new NotFoundUserException(); + } } } \ No newline at end of file diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs index e69de29..c156fb9 100644 --- a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs @@ -0,0 +1,30 @@ +using HyBe.Application.Features.AppUser.Commands.LoginUser; +using HyBe.Application.Features.AppUser.Commands.RefreshTokenLogin; +using MediatR; +using Microsoft.AspNetCore.Mvc; + +namespace HyBe.WebAPI.Controllers.v1 +{ + [Route("api/[controller]")] + [ApiController] + public class AuthController : ControllerBase + { + readonly IMediator _mediator; + public AuthController(IMediator mediator) + { + _mediator = mediator; + } + [HttpPost("[action]")] + public async Task Login(LoginUserCommandRequest loginUserCommandRequest) + { + LoginUserCommandResponse response = await _mediator.Send(loginUserCommandRequest); + return Ok(response); + } + [HttpPost("[action]")] + public async Task RefreshTokenLogin([FromBody] RefreshTokenLoginCommandRequest refreshTokenLoginCommandRequest) + { + RefreshTokenLoginCommandResponse response = await _mediator.Send(refreshTokenLoginCommandRequest); + return Ok(response); + } + } +} diff --git a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs index 5bc59e2..6168b9d 100644 --- a/Presentation/HyBe.WebAPI/Controllers/UsersController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/UsersController.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Mvc; -namespace HyBe.WebAPI.Controllers +namespace HyBe.WebAPI.Controllers.v1 { [Microsoft.AspNetCore.Mvc.Route("api/[Controller]")] [ApiController] From 719dcd2b4c84946e1062158e52c8122bab770d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCha=20Kesikba=C5=9F?= Date: Tue, 21 Mar 2023 22:06:02 +0300 Subject: [PATCH 27/27] Fixed Authantication --- .../IInternalAuthentication.cs | 2 +- .../Abstractions/Token/ITokenHandler.cs | 2 +- .../LoginUser/LoginUserCommandHandler.cs | 2 +- .../Services/Token/TokenHandler.cs | 9 +++-- .../HyBe.Persistence/Services/AuthService.cs | 8 ++--- .../HyBe.WebAPI/Controllers/AuthController.cs | 6 ++-- .../Controllers/v1/SymbolController.cs | 2 ++ Presentation/HyBe.WebAPI/Program.cs | 34 +++++++++++++++---- 8 files changed, 46 insertions(+), 19 deletions(-) diff --git a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs index dc4067f..68c60df 100644 --- a/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs +++ b/Core/HyBe.Application/Abstractions/Services/Authentications/IInternalAuthentication.cs @@ -8,7 +8,7 @@ namespace HyBe.Application.Abstractions.Services.Authentications { public interface IInternalAuthentication { - Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime); + Task LoginAsync(string usernameOrEmail, string password); Task RefreshTokenLoginAsync(string refreshToken); } } diff --git a/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs b/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs index 0d662e0..cacfeb7 100644 --- a/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs +++ b/Core/HyBe.Application/Abstractions/Token/ITokenHandler.cs @@ -4,7 +4,7 @@ namespace HyBe.Application.Abstractions.Token { public interface ITokenHandler { - DTOs.Token CreateAccessToken(int second, AppUser appUser); + DTOs.Token CreateAccessToken(AppUser appUser); string CreateRefreshToken(); } } \ No newline at end of file diff --git a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs index d884a8a..10b4195 100644 --- a/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs +++ b/Core/HyBe.Application/Features/AppUser/Commands/LoginUser/LoginUserCommandHandler.cs @@ -13,7 +13,7 @@ public LoginUserCommandHandler(IAuthService authService) public async Task Handle(LoginUserCommandRequest request, CancellationToken cancellationToken) { - var token = await _authService.LoginAsync(request.UsernameOrEmail, request.Password, 900); + var token = await _authService.LoginAsync(request.UsernameOrEmail, request.Password); return new LoginUserSuccessCommandResponse() { Token = token diff --git a/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs index 1895af9..4b731c7 100644 --- a/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs +++ b/Infrastructure/HyBe.Infrastructure/Services/Token/TokenHandler.cs @@ -21,7 +21,7 @@ public TokenHandler(IConfiguration configuration) { _configuration = configuration; } - public Application.DTOs.Token CreateAccessToken(int second, AppUser user) + public Application.DTOs.Token CreateAccessToken(AppUser user) { Application.DTOs.Token token = new(); @@ -32,14 +32,17 @@ public Application.DTOs.Token CreateAccessToken(int second, AppUser user) SigningCredentials signingCredentials = new(securityKey, SecurityAlgorithms.HmacSha256); //Oluşturulacak token ayarlarını veriyoruz. - token.Expiration = DateTime.UtcNow.AddSeconds(second); + if (!int.TryParse(_configuration["Token:AccessTokenLifeTime"], out int accessTokenLifeTime)) + return null; + + token.Expiration = DateTime.UtcNow.AddMinutes(accessTokenLifeTime); JwtSecurityToken securityToken = new( audience: _configuration["Token:Audience"], issuer: _configuration["Token:Issuer"], expires: token.Expiration, notBefore: DateTime.UtcNow, signingCredentials: signingCredentials, - claims: new List { new(ClaimTypes.Name, user.UserName) } + claims: new List { new(ClaimTypes.Name, user?.UserName) } ); //Token oluşturucu sınıfından bir örnek alalım. diff --git a/Infrastructure/HyBe.Persistence/Services/AuthService.cs b/Infrastructure/HyBe.Persistence/Services/AuthService.cs index 95d34d9..ff2695b 100644 --- a/Infrastructure/HyBe.Persistence/Services/AuthService.cs +++ b/Infrastructure/HyBe.Persistence/Services/AuthService.cs @@ -49,14 +49,14 @@ async Task CreateUserExternalAsync(AppUser user, string email, string nam { await _userManager.AddLoginAsync(user, info); //AspNetUserLogins - Token token = _tokenHandler.CreateAccessToken(accessTokenLifeTime, user); + Token token = _tokenHandler.CreateAccessToken(user); await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 15); return token; } throw new Exception("Invalid external authentication."); } - public async Task LoginAsync(string usernameOrEmail, string password, int accessTokenLifeTime) + public async Task LoginAsync(string usernameOrEmail, string password) { Domain.Entities.Identity.AppUser user = await _userManager.FindByNameAsync(usernameOrEmail); if (user == null) @@ -68,7 +68,7 @@ public async Task LoginAsync(string usernameOrEmail, string password, int SignInResult result = await _signInManager.CheckPasswordSignInAsync(user, password, false); if (result.Succeeded) //Authentication başarılı! { - Token token = _tokenHandler.CreateAccessToken(accessTokenLifeTime, user); + Token token = _tokenHandler.CreateAccessToken(user); await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 15); return token; } @@ -85,7 +85,7 @@ public async Task RefreshTokenLoginAsync(string refreshToken) AppUser? user = await _userManager.Users.FirstOrDefaultAsync(u => u.RefreshToken == refreshToken); if (user != null && user?.RefreshTokenEndDate > DateTime.UtcNow) { - Token token = _tokenHandler.CreateAccessToken(15, user); + Token token = _tokenHandler.CreateAccessToken(user); await _userService.UpdateRefreshTokenAsync(token.RefreshToken, user, token.Expiration, 300); return token; } diff --git a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs index c156fb9..19a7c0c 100644 --- a/Presentation/HyBe.WebAPI/Controllers/AuthController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/AuthController.cs @@ -5,7 +5,7 @@ namespace HyBe.WebAPI.Controllers.v1 { - [Route("api/[controller]")] + [Route("api/v1.0/[controller]/[action]")] [ApiController] public class AuthController : ControllerBase { @@ -14,13 +14,13 @@ public AuthController(IMediator mediator) { _mediator = mediator; } - [HttpPost("[action]")] + [HttpPost] public async Task Login(LoginUserCommandRequest loginUserCommandRequest) { LoginUserCommandResponse response = await _mediator.Send(loginUserCommandRequest); return Ok(response); } - [HttpPost("[action]")] + [HttpPost] public async Task RefreshTokenLogin([FromBody] RefreshTokenLoginCommandRequest refreshTokenLoginCommandRequest) { RefreshTokenLoginCommandResponse response = await _mediator.Send(refreshTokenLoginCommandRequest); diff --git a/Presentation/HyBe.WebAPI/Controllers/v1/SymbolController.cs b/Presentation/HyBe.WebAPI/Controllers/v1/SymbolController.cs index 77826e0..5078cbf 100644 --- a/Presentation/HyBe.WebAPI/Controllers/v1/SymbolController.cs +++ b/Presentation/HyBe.WebAPI/Controllers/v1/SymbolController.cs @@ -6,12 +6,14 @@ using HyBe.Application.Features.Symbols.Queries.GetListSymbol; using HyBe.Domain.Contracts.Symbols; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace HyBe.WebAPI.Controllers.v1 { [Route("api/v1.0/[controller]/[action]")] [ApiController] + [Authorize(AuthenticationSchemes = "Admin")] public class SymbolController : ControllerBase { #region Fileds diff --git a/Presentation/HyBe.WebAPI/Program.cs b/Presentation/HyBe.WebAPI/Program.cs index e49ef6a..e252f46 100644 --- a/Presentation/HyBe.WebAPI/Program.cs +++ b/Presentation/HyBe.WebAPI/Program.cs @@ -7,6 +7,7 @@ using Microsoft.IdentityModel.Tokens; using System.Text; using System.Security.Claims; +using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args); @@ -18,13 +19,34 @@ builder.Services.AddInfrastructureServices(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(m=> m.SwaggerDoc("v1",new Microsoft.OpenApi.Models.OpenApiInfo() -{ - Title = "Hypance Backend Project", - Version = "v1", - License = new Microsoft.OpenApi.Models.OpenApiLicense() { Name ="Hypance"} -})); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hypance Backend Project", Version = "v1" }); + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme() + { + Name = "Authorization", + Type = SecuritySchemeType.Http, + Scheme = "Bearer", + BearerFormat = "JWT", + In = ParameterLocation.Header, + Description = "JWT Authorization header using the Bearer scheme." + }); + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + new string[] {} + } + }); +}); builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer("Admin", options => {