diff --git a/TheBank/BankDatabase/DesignTimeDbContextFactory.cs b/TheBank/BankDatabase/DesignTimeDbContextFactory.cs index 2395aab..f3351f7 100644 --- a/TheBank/BankDatabase/DesignTimeDbContextFactory.cs +++ b/TheBank/BankDatabase/DesignTimeDbContextFactory.cs @@ -3,13 +3,13 @@ using Microsoft.EntityFrameworkCore.Design; namespace BankDatabase; -public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory -{ - public BankDbContext CreateDbContext(string[] args) - { - return new BankDbContext(new ConfigurationDatabase()); - } -} +//public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory +//{ +// //public BankDbContext CreateDbContext(string[] args) +// //{ +// // return new BankDbContext(new ConfigurationDatabase()); +// //} +//} internal class ConfigurationDatabase : IConfigurationDatabase { diff --git a/TheBank/BankDatabase/Models/CreditProgramCurrency.cs b/TheBank/BankDatabase/Models/CreditProgramCurrency.cs index c0f8a0f..f91465f 100644 --- a/TheBank/BankDatabase/Models/CreditProgramCurrency.cs +++ b/TheBank/BankDatabase/Models/CreditProgramCurrency.cs @@ -1,6 +1,4 @@ -using System.ComponentModel.DataAnnotations.Schema; - -namespace BankDatabase.Models; +namespace BankDatabase.Models; public class CreditProgramCurrency { diff --git a/TheBank/BankWebApi/Adapters/StorekeeperAdapter.cs b/TheBank/BankWebApi/Adapters/StorekeeperAdapter.cs index 28f168d..305dd46 100644 --- a/TheBank/BankWebApi/Adapters/StorekeeperAdapter.cs +++ b/TheBank/BankWebApi/Adapters/StorekeeperAdapter.cs @@ -194,7 +194,7 @@ public class StorekeeperAdapter : IStorekeeperAdapter token = _jwtProvider.GenerateToken(storekeeper); - return StorekeeperOperationResponse.OK(token); + return StorekeeperOperationResponse.OK(_mapper.Map(storekeeper)); } catch (Exception ex) { diff --git a/TheBank/BankWebApi/Controllers/CreditProgramsController.cs b/TheBank/BankWebApi/Controllers/CreditProgramsController.cs index ad417ec..da7ca35 100644 --- a/TheBank/BankWebApi/Controllers/CreditProgramsController.cs +++ b/TheBank/BankWebApi/Controllers/CreditProgramsController.cs @@ -18,7 +18,6 @@ public class CreditProgramsController(ICreditProgramAdapter adapter) : Controlle /// /// список кредитных программ [HttpGet] - [AllowAnonymous] public IActionResult GetAllRecords() { return _adapter.GetList().GetResponse(Request, Response); @@ -63,7 +62,6 @@ public class CreditProgramsController(ICreditProgramAdapter adapter) : Controlle /// модель от пользователя /// [HttpPost] - [AllowAnonymous] public IActionResult Register([FromBody] CreditProgramBindingModel model) { return _adapter.RegisterCreditProgram(model).GetResponse(Request, Response); diff --git a/TheBank/BankWebApi/Controllers/StorekeepersController.cs b/TheBank/BankWebApi/Controllers/StorekeepersController.cs index 2c12f7c..673b7b1 100644 --- a/TheBank/BankWebApi/Controllers/StorekeepersController.cs +++ b/TheBank/BankWebApi/Controllers/StorekeepersController.cs @@ -2,6 +2,7 @@ using BankContracts.BindingModels; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System.Security.Claims; namespace BankWebApi.Controllers; @@ -67,6 +68,10 @@ public class StorekeepersController(IStorekeeperAdapter adapter) : ControllerBas public IActionResult Login([FromBody] StorekeeperAuthBindingModel model) { var res = _adapter.Login(model, out string token); + if (string.IsNullOrEmpty(token)) + { + return NotFound("User not found"); + } Response.Cookies.Append(AuthOptions.CookieName, token, new CookieOptions { @@ -78,4 +83,32 @@ public class StorekeepersController(IStorekeeperAdapter adapter) : ControllerBas return res.GetResponse(Request, Response); } + + /// + /// Получение данных текущего кладовщика + /// + /// Данные кладовщика + [HttpGet("me")] + public IActionResult GetCurrentUser() + { + var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; + if (string.IsNullOrEmpty(userId)) + { + return Unauthorized(); + } + + var response = _adapter.GetElement(userId); + return response.GetResponse(Request, Response); + } + + /// + /// Выход кладовщика + /// + /// + [HttpPost("logout")] + public IActionResult Logout() + { + Response.Cookies.Delete(AuthOptions.CookieName); + return Ok(); + } } diff --git a/TheBank/BankWebApi/Infrastructure/JwtProvider.cs b/TheBank/BankWebApi/Infrastructure/JwtProvider.cs index a95c1f2..3a8482e 100644 --- a/TheBank/BankWebApi/Infrastructure/JwtProvider.cs +++ b/TheBank/BankWebApi/Infrastructure/JwtProvider.cs @@ -12,7 +12,7 @@ public class JwtProvider : IJwtProvider var token = new JwtSecurityToken( issuer: AuthOptions.ISSUER, audience: AuthOptions.AUDIENCE, - claims: [new("id", dataModel.Id)], + claims: [new(ClaimTypes.NameIdentifier, dataModel.Id)], expires: DateTime.UtcNow.Add(TimeSpan.FromDays(2)), signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)); diff --git a/TheBank/bankui/bun.lockb b/TheBank/bankui/bun.lockb index 1b8f071..aea057b 100644 Binary files a/TheBank/bankui/bun.lockb and b/TheBank/bankui/bun.lockb differ diff --git a/TheBank/bankui/package.json b/TheBank/bankui/package.json index b9d4ce5..e5a277a 100644 --- a/TheBank/bankui/package.json +++ b/TheBank/bankui/package.json @@ -39,7 +39,8 @@ "tailwind-merge": "^3.3.0", "tailwindcss": "^4.1.7", "tw-animate-css": "^1.3.0", - "zod": "^3.24.4" + "zod": "^3.24.4", + "zustand": "^5.0.4" }, "devDependencies": { "@eslint/js": "^9.25.0", diff --git a/TheBank/bankui/src/App.tsx b/TheBank/bankui/src/App.tsx index f719fd7..1a781d2 100644 --- a/TheBank/bankui/src/App.tsx +++ b/TheBank/bankui/src/App.tsx @@ -1,13 +1,28 @@ +import { useAuthCheck } from '@/hooks/useAuthCheck'; +import { useAuthStore } from '@/store/workerStore'; +import { Navigate, Outlet, useLocation } from 'react-router-dom'; +import { Header } from '@/components/layout/Header'; +import { Footer } from '@/components/layout/Footer'; import { Suspense } from 'react'; -import { Footer } from './components/layout/Footer'; -import { Header } from './components/layout/Header'; -import { Outlet } from 'react-router-dom'; function App() { + const user = useAuthStore((store) => store.user); + const { isLoading } = useAuthCheck(); + const location = useLocation(); + + if (isLoading) { + return
Loading...
; + } + + if (!user) { + const redirect = encodeURIComponent(location.pathname + location.search); + return ; + } + return ( <>
- loading

}> + Loading...

}>