Compare commits
7
Commits
mobile-app
...
6208fd3baf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6208fd3baf | ||
|
|
6e742b4029 | ||
|
|
08ca55dd6b | ||
|
|
36f1078b0a | ||
|
|
3965a8a2a1 | ||
|
|
d3a1b1cb17 | ||
|
|
abd075287c |
No files matched your search
@@ -3,8 +3,13 @@
|
|||||||
!backend/Directory.Packages.props
|
!backend/Directory.Packages.props
|
||||||
!backend/src/
|
!backend/src/
|
||||||
!db/migrations/
|
!db/migrations/
|
||||||
|
!web/Directory.Build.props
|
||||||
|
!web/Directory.Packages.props
|
||||||
|
!web/Helpdesk.Web/
|
||||||
backend/**/bin
|
backend/**/bin
|
||||||
backend/**/obj
|
backend/**/obj
|
||||||
|
web/**/bin
|
||||||
|
web/**/obj
|
||||||
**/.env
|
**/.env
|
||||||
**/*.env
|
**/*.env
|
||||||
**/*.pem
|
**/*.pem
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ Univerzitní helpdesk a portál návrhů na zlepšení – semestrální práce
|
|||||||
| [docs/navrh-aplikace.md](docs/navrh-aplikace.md) | Návrhový dokument (v1.1 – včetně zapracovaných připomínek z obhajoby) |
|
| [docs/navrh-aplikace.md](docs/navrh-aplikace.md) | Návrhový dokument (v1.1 – včetně zapracovaných připomínek z obhajoby) |
|
||||||
| [db/migrations/](db/migrations/) | Verzované SQL migrace (MariaDB 11) – schéma, číselníky a porovnávání FCM tokenů |
|
| [db/migrations/](db/migrations/) | Verzované SQL migrace (MariaDB 11) – schéma, číselníky a porovnávání FCM tokenů |
|
||||||
| [backend/](backend/) | ASP.NET Core Web API, DbUp migrator, unit testy (.NET 10) |
|
| [backend/](backend/) | ASP.NET Core Web API, DbUp migrator, unit testy (.NET 10) |
|
||||||
|
| [web/](web/) | Webová aplikace ASP.NET Core MVC – tenký klient REST API |
|
||||||
| [deploy/](deploy/) | Docker Compose, inicializace DB účtů, šablona `.env` |
|
| [deploy/](deploy/) | Docker Compose, inicializace DB účtů, šablona `.env` |
|
||||||
|
|
||||||
## Spuštění backendu (Docker)
|
## Spuštění (Docker)
|
||||||
|
|
||||||
Potřeba je jen Docker Desktop.
|
Potřeba je jen Docker Desktop.
|
||||||
|
|
||||||
@@ -23,21 +24,23 @@ Potřeba je jen Docker Desktop.
|
|||||||
cp deploy/.env.example deploy/.env
|
cp deploy/.env.example deploy/.env
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Spusťte databázi, migrace a API:
|
2. Spusťte databázi, migrace, API a web:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose -f deploy/docker-compose.yml --env-file deploy/.env up --build
|
docker compose -f deploy/docker-compose.yml --env-file deploy/.env up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Swagger UI: <http://localhost:8080/swagger> · stav a verze schématu: <http://localhost:8080/health>
|
3. Webová aplikace: <http://localhost:8081> · Swagger UI: <http://localhost:8080/swagger> · stav a verze schématu: <http://localhost:8080/health>
|
||||||
|
|
||||||
|
Lokálně bez reverse proxy nastavte `PUBLIC_BASE_URL=http://localhost:8081`, aby odkazy pro ověření e-mailu a obnovu hesla vedly na web v Dockeru.
|
||||||
|
|
||||||
Při prvním startu se vytvoří účet administrátora, pokud vyplníte `ADMIN_EMAIL` a `ADMIN_PASSWORD`. V režimu `Development` s prázdnými hodnotami `SMTP_MAILBOX` a `SMTP_PASSWORD` najdete ověřovací odkazy a odkazy pro obnovu hesla v logu služby `api`.
|
Při prvním startu se vytvoří účet administrátora, pokud vyplníte `ADMIN_EMAIL` a `ADMIN_PASSWORD`. V režimu `Development` s prázdnými hodnotami `SMTP_MAILBOX` a `SMTP_PASSWORD` najdete ověřovací odkazy a odkazy pro obnovu hesla v logu služby `api`.
|
||||||
|
|
||||||
Pro nasazení nastavte v `deploy/.env` režim `Production`, veřejnou HTTPS adresu webu v `PUBLIC_BASE_URL` a skutečné univerzitní domény v `STUDENT_EMAIL_DOMAIN` a `TEACHER_EMAIL_DOMAIN`. Pro Email Profi vyplňte `SMTP_MAILBOX` celou adresou schránky a nastavte `SMTP_PASSWORD`. API odesílá přes `smtp.seznam.cz:465` s TLS.
|
Pro nasazení nastavte v `deploy/.env` režim `Production`, veřejnou HTTPS adresu webu v `PUBLIC_BASE_URL` a skutečné univerzitní domény v `STUDENT_EMAIL_DOMAIN` a `TEACHER_EMAIL_DOMAIN`. Pro Email Profi vyplňte `SMTP_MAILBOX` celou adresou schránky a nastavte `SMTP_PASSWORD`. API odesílá přes `smtp.seznam.cz:465` s TLS.
|
||||||
|
|
||||||
Reverse proxy ukončuje HTTPS a předává požadavky přes HTTP na adresu `PROXY_UPSTREAM_BIND_ADDRESS` a port `API_HTTP_PORT`. Výchozí hodnoty `127.0.0.1` a `8080` odpovídají proxy běžící přímo na stejném hostiteli.
|
Reverse proxy ukončuje HTTPS a předává požadavky přes HTTP na adresu `PROXY_UPSTREAM_BIND_ADDRESS`: `/api/*` a `/swagger` na port `API_HTTP_PORT` (výchozí `8080`), ostatní na web na port `WEB_HTTP_PORT` (výchozí `8081`). Výchozí adresa `127.0.0.1` odpovídá proxy běžící přímo na stejném hostiteli.
|
||||||
|
|
||||||
Pro zpracování `X-Forwarded-For` a `X-Forwarded-Proto` nastavte `TRUSTED_REVERSE_PROXY_IP` na IP bezprostředního protějšku, kterou vidí API. Tato IP se může při průchodu Docker sítí lišit od adresy, na kterou je API vázáno.
|
Pro zpracování `X-Forwarded-For` a `X-Forwarded-Proto` nastavte `TRUSTED_REVERSE_PROXY_IP` na IP bezprostředního protějšku, kterou vidí API a web. Tato IP se může při průchodu Docker sítí lišit od adresy, na kterou je API vázáno.
|
||||||
|
|
||||||
S nakonfigurovaným SMTP odesílá backend i e-mailové notifikace z databázové fronty. Pro mobilní push nastavte `FIREBASE_SERVICE_ACCOUNT_JSON` na jednořádkový JSON klíče servisního účtu Firebase.
|
S nakonfigurovaným SMTP odesílá backend i e-mailové notifikace z databázové fronty. Pro mobilní push nastavte `FIREBASE_SERVICE_ACCOUNT_JSON` na jednořádkový JSON klíče servisního účtu Firebase.
|
||||||
|
|
||||||
@@ -49,6 +52,18 @@ Vyžaduje .NET SDK 10. Unit testy:
|
|||||||
dotnet run --project backend/tests/Helpdesk.UnitTests/Helpdesk.UnitTests.csproj
|
dotnet run --project backend/tests/Helpdesk.UnitTests/Helpdesk.UnitTests.csproj
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Webová aplikace proti API běžícímu v Dockeru (otevře se na <http://localhost:5080>):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dotnet run --project web/Helpdesk.Web
|
||||||
|
```
|
||||||
|
|
||||||
|
Testy webové aplikace:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dotnet test --solution web/Helpdesk.Web.sln
|
||||||
|
```
|
||||||
|
|
||||||
## Verzování databáze
|
## Verzování databáze
|
||||||
|
|
||||||
Schéma se mění výhradně novými číslovanými skripty `db/migrations/V{NNN}__{popis}.sql`. Provedený skript se nikdy neupravuje. Migrace spouští DbUp (`Helpdesk.Migrator`) před startem API a eviduje je v tabulce `schema_version`.
|
Schéma se mění výhradně novými číslovanými skripty `db/migrations/V{NNN}__{popis}.sql`. Provedený skript se nikdy neupravuje. Migrace spouští DbUp (`Helpdesk.Migrator`) před startem API a eviduje je v tabulce `schema_version`.
|
||||||
|
|||||||
+4
-1
@@ -19,10 +19,13 @@ ADMIN_PASSWORD=change-me-admin
|
|||||||
# Loopback použijte pro reverse proxy běžící přímo na stejném hostiteli.
|
# Loopback použijte pro reverse proxy běžící přímo na stejném hostiteli.
|
||||||
PROXY_UPSTREAM_BIND_ADDRESS=127.0.0.1
|
PROXY_UPSTREAM_BIND_ADDRESS=127.0.0.1
|
||||||
API_HTTP_PORT=8080
|
API_HTTP_PORT=8080
|
||||||
# Adresa reverse proxy tak, jak ji API vidí jako bezprostředního klienta.
|
# Port webové aplikace na hostiteli (stejná adresa jako API).
|
||||||
|
WEB_HTTP_PORT=8081
|
||||||
|
# Adresa reverse proxy tak, jak ji API a web vidí jako bezprostředního klienta.
|
||||||
TRUSTED_REVERSE_PROXY_IP=
|
TRUSTED_REVERSE_PROXY_IP=
|
||||||
|
|
||||||
# Veřejná HTTPS adresa webu pro odkazy v e-mailech a povolené univerzitní domény.
|
# Veřejná HTTPS adresa webu pro odkazy v e-mailech a povolené univerzitní domény.
|
||||||
|
# Lokálně bez proxy: http://localhost:8081 (odkazy z e-mailů pak vedou na web v Dockeru).
|
||||||
PUBLIC_BASE_URL= #https://helpdesk.domain.local
|
PUBLIC_BASE_URL= #https://helpdesk.domain.local
|
||||||
STUDENT_EMAIL_DOMAIN= #student.domain.local
|
STUDENT_EMAIL_DOMAIN= #student.domain.local
|
||||||
TEACHER_EMAIL_DOMAIN= #domain.local
|
TEACHER_EMAIL_DOMAIN= #domain.local
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# Vývojové spuštění backendu: docker compose -f deploy/docker-compose.yml --env-file deploy/.env up --build
|
# Vývojové spuštění: docker compose -f deploy/docker-compose.yml --env-file deploy/.env up --build
|
||||||
# Reverse proxy ukončuje HTTPS a připojuje se k API přes HTTP.
|
# Reverse proxy ukončuje HTTPS a připojuje se k webu a API přes HTTP
|
||||||
|
# (/ → web, /api/* a /swagger → api).
|
||||||
|
|
||||||
name: helpdesk
|
name: helpdesk
|
||||||
|
|
||||||
@@ -63,6 +64,24 @@ services:
|
|||||||
- "${PROXY_UPSTREAM_BIND_ADDRESS:-127.0.0.1}:${API_HTTP_PORT:-8080}:8080"
|
- "${PROXY_UPSTREAM_BIND_ADDRESS:-127.0.0.1}:${API_HTTP_PORT:-8080}:8080"
|
||||||
networks: [frontend, backend]
|
networks: [frontend, backend]
|
||||||
|
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: ..
|
||||||
|
dockerfile: web/Dockerfile
|
||||||
|
environment:
|
||||||
|
ASPNETCORE_ENVIRONMENT: ${ASPNETCORE_ENVIRONMENT:-Development}
|
||||||
|
# Web volá API uvnitř Docker sítě; do databáze přístup nemá (je jen v síti frontend).
|
||||||
|
Api__BaseUrl: http://api:8080/
|
||||||
|
ReverseProxy__TrustedIp: ${TRUSTED_REVERSE_PROXY_IP:-}
|
||||||
|
volumes:
|
||||||
|
# Klíče pro šifrování cookie – bez nich by restart kontejneru odhlásil všechny uživatele.
|
||||||
|
- web-keys:/app/keys
|
||||||
|
depends_on:
|
||||||
|
- api
|
||||||
|
ports:
|
||||||
|
- "${PROXY_UPSTREAM_BIND_ADDRESS:-127.0.0.1}:${WEB_HTTP_PORT:-8081}:8080"
|
||||||
|
networks: [frontend]
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
frontend:
|
frontend:
|
||||||
backend:
|
backend:
|
||||||
@@ -71,3 +90,4 @@ networks:
|
|||||||
volumes:
|
volumes:
|
||||||
db-data:
|
db-data:
|
||||||
uploads:
|
uploads:
|
||||||
|
web-keys:
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
|
<!-- Web zobrazuje data a čísla česky (cs-CZ), proto plná podpora kultur. -->
|
||||||
|
<InvariantGlobalization>false</InvariantGlobalization>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- Webová aplikace vystačí se sdíleným frameworkem ASP.NET Core; balíčky jsou jen pro testy. -->
|
||||||
|
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
|
||||||
|
<PackageVersion Include="xunit.v3" Version="4.0.2" />
|
||||||
|
<PackageVersion Include="xunit.runner.visualstudio" Version="4.0.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Vícefázový build webové aplikace. Kontext sestavení = kořen repozitáře.
|
||||||
|
# docker build -f web/Dockerfile .
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||||
|
WORKDIR /src
|
||||||
|
# Nejdřív jen projektové soubory – restore se cachuje, dokud se nezmění závislosti.
|
||||||
|
COPY web/Directory.Build.props web/Directory.Packages.props ./
|
||||||
|
COPY web/Helpdesk.Web/Helpdesk.Web.csproj Helpdesk.Web/
|
||||||
|
RUN dotnet restore Helpdesk.Web/Helpdesk.Web.csproj
|
||||||
|
COPY web/Helpdesk.Web/ Helpdesk.Web/
|
||||||
|
RUN dotnet publish Helpdesk.Web/Helpdesk.Web.csproj -c Release -o /out --no-restore
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:10.0
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build /out .
|
||||||
|
# Klíče Data Protection (šifrování autentizační cookie) – v Compose je tu volume web-keys.
|
||||||
|
RUN mkdir -p /app/keys && chown "$APP_UID" /app/keys
|
||||||
|
USER $APP_UID
|
||||||
|
ENV ASPNETCORE_HTTP_PORTS=8080 \
|
||||||
|
DataProtection__KeysPath=/app/keys
|
||||||
|
EXPOSE 8080
|
||||||
|
ENTRYPOINT ["dotnet", "Helpdesk.Web.dll"]
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Text;
|
||||||
|
using Helpdesk.Web.Api;
|
||||||
|
using Helpdesk.Web.Auth;
|
||||||
|
using Helpdesk.Web.Infrastructure;
|
||||||
|
using Helpdesk.Web.Models;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Tests;
|
||||||
|
|
||||||
|
public class AuthCookieTests
|
||||||
|
{
|
||||||
|
private static readonly TokenSet Tokens = new(
|
||||||
|
"access", new DateTimeOffset(2026, 12, 1, 10, 15, 0, TimeSpan.Zero),
|
||||||
|
"refresh", new DateTimeOffset(2026, 12, 15, 10, 0, 0, TimeSpan.Zero));
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Tokeny_ulozene_v_cookie_se_prectou_zpet()
|
||||||
|
{
|
||||||
|
var properties = new AuthenticationProperties();
|
||||||
|
AuthCookie.StoreTokens(properties, Tokens);
|
||||||
|
|
||||||
|
Assert.Equal(Tokens, AuthCookie.ReadTokens(properties));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Trvale_prihlaseni_plati_stejne_dlouho_jako_refresh_token()
|
||||||
|
{
|
||||||
|
var properties = new AuthenticationProperties { IsPersistent = true };
|
||||||
|
AuthCookie.StoreTokens(properties, Tokens);
|
||||||
|
|
||||||
|
Assert.Equal(Tokens.RefreshTokenExpiresAt, properties.ExpiresUtc);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Cookie_bez_tokenu_neni_platna() => Assert.Null(AuthCookie.ReadTokens(new AuthenticationProperties()));
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Identita_nese_roli_pro_IsInRole()
|
||||||
|
{
|
||||||
|
var principal = AuthCookie.CreatePrincipal(new UserDto(7, "[email protected]", "Eva", "Malá", null, UserRoles.Management, true));
|
||||||
|
|
||||||
|
Assert.True(principal.IsInRole(UserRoles.Management));
|
||||||
|
Assert.Equal("Eva Malá", principal.Identity!.Name);
|
||||||
|
Assert.Equal("7", principal.FindFirst(ClaimTypes.NameIdentifier)!.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ApiExceptionTests
|
||||||
|
{
|
||||||
|
private static HttpResponseMessage Problem(HttpStatusCode status, string json) => new(status)
|
||||||
|
{
|
||||||
|
Content = new StringContent(json, Encoding.UTF8, "application/problem+json"),
|
||||||
|
};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Validacni_chyby_z_ProblemDetails_se_nactou_podle_poli()
|
||||||
|
{
|
||||||
|
using var response = Problem(HttpStatusCode.BadRequest,
|
||||||
|
"""{"title":"Neplatná vstupní data.","status":400,"errors":{"password":["Heslo je příliš krátké."]}}""");
|
||||||
|
|
||||||
|
var error = await ApiException.FromResponseAsync(response, CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.Equal(HttpStatusCode.BadRequest, error.StatusCode);
|
||||||
|
Assert.Equal("Neplatná vstupní data.", error.UserMessage);
|
||||||
|
Assert.Equal(["Heslo je příliš krátké."], error.Errors["Password"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Odpoved_bez_tela_ma_srozumitelnou_zpravu()
|
||||||
|
{
|
||||||
|
using var response = new HttpResponseMessage(HttpStatusCode.TooManyRequests);
|
||||||
|
|
||||||
|
var error = await ApiException.FromResponseAsync(response, CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.Equal("Příliš mnoho pokusů. Zkuste to prosím za minutu.", error.UserMessage);
|
||||||
|
Assert.Empty(error.Errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Poskozeny_JSON_nezpusobi_vyjimku()
|
||||||
|
{
|
||||||
|
using var response = Problem(HttpStatusCode.InternalServerError, "{nejde o json");
|
||||||
|
|
||||||
|
var error = await ApiException.FromResponseAsync(response, CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.Equal(HttpStatusCode.InternalServerError, error.StatusCode);
|
||||||
|
Assert.Null(error.Title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ModelStateExtensionsTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Chyba_pole_z_API_patri_k_vlastnosti_formulare()
|
||||||
|
{
|
||||||
|
var modelState = new ModelStateDictionary();
|
||||||
|
var error = new ApiException(HttpStatusCode.BadRequest, "Neplatná vstupní data.",
|
||||||
|
new Dictionary<string, string[]> { ["newPassword"] = ["Heslo musí mít alespoň 8 znaků."] });
|
||||||
|
|
||||||
|
modelState.AddApiErrors(error, typeof(ResetPasswordViewModel));
|
||||||
|
|
||||||
|
Assert.Equal("Heslo musí mít alespoň 8 znaků.", modelState[nameof(ResetPasswordViewModel.NewPassword)]!.Errors.Single().ErrorMessage);
|
||||||
|
Assert.False(modelState.ContainsKey(string.Empty));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Chyba_bez_pole_jde_do_souhrnu()
|
||||||
|
{
|
||||||
|
var modelState = new ModelStateDictionary();
|
||||||
|
var error = new ApiException(HttpStatusCode.Conflict, "Účet s tímto e-mailem už existuje.", new Dictionary<string, string[]>());
|
||||||
|
|
||||||
|
modelState.AddApiErrors(error, typeof(RegisterViewModel));
|
||||||
|
|
||||||
|
Assert.Equal("Účet s tímto e-mailem už existuje.", modelState[string.Empty]!.Errors.Single().ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NavigationTests
|
||||||
|
{
|
||||||
|
private static ClaimsPrincipal UserWithRole(string role) =>
|
||||||
|
new(new ClaimsIdentity([new Claim(ClaimTypes.Role, role)], "test"));
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Neprihlaseny_uzivatel_menu_nevidi() =>
|
||||||
|
Assert.Empty(Navigation.For(new ClaimsPrincipal(new ClaimsIdentity())));
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Polozka_s_roli_je_videt_jen_te_roli()
|
||||||
|
{
|
||||||
|
var item = new NavItem("Statistiky", "Statistics", "Index", UserRoles.Management);
|
||||||
|
|
||||||
|
Assert.True(item.IsVisibleTo(UserWithRole(UserRoles.Management)));
|
||||||
|
Assert.False(item.IsVisibleTo(UserWithRole(UserRoles.Student)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Polozka_bez_roli_je_videt_vsem_prihlasenym() =>
|
||||||
|
Assert.True(new NavItem("Nástěnka", "Home", "Index").IsVisibleTo(UserWithRole(UserRoles.Student)));
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
<ProjectReference Include="..\Helpdesk.Web\Helpdesk.Web.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||||
|
<PackageReference Include="xunit.v3" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using Helpdesk.Web.Infrastructure;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Tests;
|
||||||
|
|
||||||
|
public class StatusLabelsTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData("RECEIVED", "Přijata")]
|
||||||
|
[InlineData("IN_PROGRESS", "V řešení")]
|
||||||
|
[InlineData("PENDING_VERIFICATION", "Čeká na ověření")]
|
||||||
|
[InlineData("in_progress", "V řešení")]
|
||||||
|
public void Stav_zavady_ma_cesky_nazev(string status, string label) => Assert.Equal(label, StatusLabels.For(status));
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Zamitnuti_se_sklonuje_podle_zavady_a_navrhu()
|
||||||
|
{
|
||||||
|
Assert.Equal("Zamítnuta", StatusLabels.For("REJECTED"));
|
||||||
|
Assert.Equal("Zamítnut", StatusLabels.For("REJECTED", isProposal: true));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Neznamy_kod_se_zobrazi_tak_jak_prisel() => Assert.Equal("ARCHIVED", StatusLabels.For("ARCHIVED"));
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
using Helpdesk.Web.Api;
|
||||||
|
using Helpdesk.Web.Auth;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Tests;
|
||||||
|
|
||||||
|
public class TokenRefresherTests
|
||||||
|
{
|
||||||
|
private static readonly DateTimeOffset Now = new(2026, 12, 1, 10, 0, 0, TimeSpan.Zero);
|
||||||
|
private readonly FakeClock _clock = new(Now);
|
||||||
|
|
||||||
|
private static TokenSet NewTokens(string suffix) =>
|
||||||
|
new($"access-{suffix}", Now.AddMinutes(15), $"refresh-{suffix}", Now.AddDays(14));
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Soubezne_obnovy_stejneho_tokenu_volaji_API_jen_jednou()
|
||||||
|
{
|
||||||
|
var refresher = new TokenRefresher(_clock);
|
||||||
|
var calls = 0;
|
||||||
|
var gate = new TaskCompletionSource<TokenSet?>();
|
||||||
|
|
||||||
|
Task<TokenSet?> Refresh(string _)
|
||||||
|
{
|
||||||
|
Interlocked.Increment(ref calls);
|
||||||
|
return gate.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pending = Enumerable.Range(0, 5).Select(_ => refresher.RefreshAsync("refresh-old", Refresh)).ToArray();
|
||||||
|
gate.SetResult(NewTokens("new"));
|
||||||
|
var results = await Task.WhenAll(pending);
|
||||||
|
|
||||||
|
Assert.Equal(1, calls);
|
||||||
|
Assert.All(results, r => Assert.Equal("access-new", r!.AccessToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Pozdni_pozadavek_se_starou_cookie_dostane_stejny_vysledek()
|
||||||
|
{
|
||||||
|
var refresher = new TokenRefresher(_clock);
|
||||||
|
var calls = 0;
|
||||||
|
Task<TokenSet?> Refresh(string _) { calls++; return Task.FromResult<TokenSet?>(NewTokens($"{calls}")); }
|
||||||
|
|
||||||
|
var first = await refresher.RefreshAsync("refresh-old", Refresh);
|
||||||
|
_clock.Advance(TimeSpan.FromSeconds(20));
|
||||||
|
var late = await refresher.RefreshAsync("refresh-old", Refresh);
|
||||||
|
|
||||||
|
Assert.Equal(1, calls);
|
||||||
|
Assert.Equal(first, late);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Vysledek_se_po_uplynuti_doby_zapomene()
|
||||||
|
{
|
||||||
|
var refresher = new TokenRefresher(_clock);
|
||||||
|
var calls = 0;
|
||||||
|
Task<TokenSet?> Refresh(string _) { calls++; return Task.FromResult<TokenSet?>(null); }
|
||||||
|
|
||||||
|
await refresher.RefreshAsync("refresh-old", Refresh);
|
||||||
|
_clock.Advance(TokenRefresher.ResultLifetime + TimeSpan.FromSeconds(1));
|
||||||
|
await refresher.RefreshAsync("refresh-old", Refresh);
|
||||||
|
|
||||||
|
Assert.Equal(2, calls);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Ruzne_tokeny_se_obnovuji_nezavisle()
|
||||||
|
{
|
||||||
|
var refresher = new TokenRefresher(_clock);
|
||||||
|
var calls = 0;
|
||||||
|
Task<TokenSet?> Refresh(string token) { calls++; return Task.FromResult<TokenSet?>(NewTokens(token)); }
|
||||||
|
|
||||||
|
var a = await refresher.RefreshAsync("refresh-a", Refresh);
|
||||||
|
var b = await refresher.RefreshAsync("refresh-b", Refresh);
|
||||||
|
|
||||||
|
Assert.Equal(2, calls);
|
||||||
|
Assert.NotEqual(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Docasna_chyba_se_nepamatuje()
|
||||||
|
{
|
||||||
|
var refresher = new TokenRefresher(_clock);
|
||||||
|
var calls = 0;
|
||||||
|
Task<TokenSet?> Refresh(string _) =>
|
||||||
|
++calls == 1 ? throw new HttpRequestException("API nedostupné") : Task.FromResult<TokenSet?>(NewTokens("new"));
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<HttpRequestException>(() => refresher.RefreshAsync("refresh-old", Refresh));
|
||||||
|
var retry = await refresher.RefreshAsync("refresh-old", Refresh);
|
||||||
|
|
||||||
|
Assert.Equal(2, calls);
|
||||||
|
Assert.Equal("access-new", retry!.AccessToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class FakeClock(DateTimeOffset now) : TimeProvider
|
||||||
|
{
|
||||||
|
private DateTimeOffset _now = now;
|
||||||
|
|
||||||
|
public override DateTimeOffset GetUtcNow() => _now;
|
||||||
|
|
||||||
|
public void Advance(TimeSpan by) => _now += by;
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.0.31903.59
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Helpdesk.Web", "Helpdesk.Web\Helpdesk.Web.csproj", "{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Helpdesk.Web.Tests", "Helpdesk.Web.Tests\Helpdesk.Web.Tests.csproj", "{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{25D75863-E1EF-4B3E-B5FE-CE8F7E21F2F6}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{A1D048EA-6B9C-4920-A3F2-5DB3B92404CA}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Api;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Neúspěšná odpověď API ve formátu ProblemDetails (RFC 9457). Nese stav, titulek
|
||||||
|
/// a u validačních chyb seznam chyb podle polí (klíče jsou názvy vlastností v camelCase).
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ApiException(HttpStatusCode statusCode, string? title, IReadOnlyDictionary<string, string[]> errors)
|
||||||
|
: Exception(title ?? $"API vrátilo stav {(int)statusCode}.")
|
||||||
|
{
|
||||||
|
public HttpStatusCode StatusCode { get; } = statusCode;
|
||||||
|
public string? Title { get; } = title;
|
||||||
|
public IReadOnlyDictionary<string, string[]> Errors { get; } = errors;
|
||||||
|
|
||||||
|
/// <summary>Text pro uživatele. API píše titulky chyb česky, kromě odpovědí bez těla (např. 429).</summary>
|
||||||
|
public string UserMessage => StatusCode switch
|
||||||
|
{
|
||||||
|
HttpStatusCode.TooManyRequests => "Příliš mnoho pokusů. Zkuste to prosím za minutu.",
|
||||||
|
_ when !string.IsNullOrWhiteSpace(Title) => Title,
|
||||||
|
HttpStatusCode.Forbidden => "K této akci nemáte oprávnění.",
|
||||||
|
HttpStatusCode.NotFound => "Záznam nebyl nalezen.",
|
||||||
|
_ => "Požadavek se nepodařilo zpracovat. Zkuste to prosím znovu.",
|
||||||
|
};
|
||||||
|
|
||||||
|
public static async Task<ApiException> FromResponseAsync(HttpResponseMessage response, CancellationToken ct)
|
||||||
|
{
|
||||||
|
string? title = null;
|
||||||
|
Dictionary<string, string[]> errors = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
if (response.Content.Headers.ContentType?.MediaType is { } mediaType && mediaType.Contains("json", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var problem = await response.Content.ReadFromJsonAsync<ProblemBody>(ct);
|
||||||
|
title = problem?.Title;
|
||||||
|
if (problem?.Errors is { } fieldErrors)
|
||||||
|
{
|
||||||
|
foreach (var (field, messages) in fieldErrors)
|
||||||
|
errors[field] = messages;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JsonException)
|
||||||
|
{
|
||||||
|
// Tělo není ProblemDetails – zůstane jen stavový kód.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ApiException(response.StatusCode, title, errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed record ProblemBody(string? Title, Dictionary<string, string[]>? Errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class ApiResponse
|
||||||
|
{
|
||||||
|
public static async Task EnsureSuccessAsync(HttpResponseMessage response, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
throw await ApiException.FromResponseAsync(response, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<T> ReadAsync<T>(HttpResponseMessage response, CancellationToken ct)
|
||||||
|
{
|
||||||
|
await EnsureSuccessAsync(response, ct);
|
||||||
|
return await response.Content.ReadFromJsonAsync<T>(ct)
|
||||||
|
?? throw new InvalidOperationException($"API vrátilo prázdnou odpověď místo {typeof(T).Name}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
namespace Helpdesk.Web.Api;
|
||||||
|
|
||||||
|
// Kontrakt REST API /api/v1 tak, jak ho web používá. Web je tenký klient a na projekty
|
||||||
|
// backendu nemá referenci – DTO jsou zde zrcadlem dokumentace ve Swaggeru.
|
||||||
|
|
||||||
|
public sealed record UserDto(
|
||||||
|
int Id,
|
||||||
|
string Email,
|
||||||
|
string FirstName,
|
||||||
|
string LastName,
|
||||||
|
string? Phone,
|
||||||
|
string Role,
|
||||||
|
bool EmailNotificationsEnabled)
|
||||||
|
{
|
||||||
|
public string FullName => $"{FirstName} {LastName}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed record AuthResponse(
|
||||||
|
string AccessToken,
|
||||||
|
DateTimeOffset AccessTokenExpiresAt,
|
||||||
|
string RefreshToken,
|
||||||
|
DateTimeOffset RefreshTokenExpiresAt,
|
||||||
|
UserDto User)
|
||||||
|
{
|
||||||
|
public TokenSet Tokens => new(AccessToken, AccessTokenExpiresAt, RefreshToken, RefreshTokenExpiresAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Pár tokenů uložený v autentizační cookie webu.</summary>
|
||||||
|
public sealed record TokenSet(
|
||||||
|
string AccessToken,
|
||||||
|
DateTimeOffset AccessTokenExpiresAt,
|
||||||
|
string RefreshToken,
|
||||||
|
DateTimeOffset RefreshTokenExpiresAt);
|
||||||
|
|
||||||
|
public sealed record LoginRequest(string Email, string Password);
|
||||||
|
|
||||||
|
public sealed record RegisterRequest(string Email, string Password, string FirstName, string LastName);
|
||||||
|
|
||||||
|
public sealed record RefreshTokenRequest(string RefreshToken);
|
||||||
|
|
||||||
|
public sealed record EmailTokenRequest(string Token);
|
||||||
|
|
||||||
|
public sealed record ForgotPasswordRequest(string Email);
|
||||||
|
|
||||||
|
public sealed record ResetPasswordRequest(string Token, string NewPassword);
|
||||||
|
|
||||||
|
public sealed record UpdateProfileRequest(string FirstName, string LastName, string? Phone, bool EmailNotificationsEnabled);
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Helpdesk.Web.Api;
|
||||||
|
|
||||||
|
/// <summary>Připojení k backendu (sekce <c>Api</c>). V Dockeru <c>http://api:8080/</c>.</summary>
|
||||||
|
public sealed class ApiOptions
|
||||||
|
{
|
||||||
|
public const string Section = "Api";
|
||||||
|
|
||||||
|
public string BaseUrl { get; set; } = "";
|
||||||
|
|
||||||
|
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(15);
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Api;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Anonymní endpointy <c>/api/v1/auth</c>. Záměrně bez <see cref="BearerTokenHandler"/>:
|
||||||
|
/// obnova tokenu běží uvnitř ověřování cookie a čtení tokenu z cookie by se zacyklilo.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AuthApiClient(HttpClient http)
|
||||||
|
{
|
||||||
|
public async Task<AuthResponse> LoginAsync(LoginRequest request, CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.PostAsJsonAsync("api/v1/auth/login", request, ct);
|
||||||
|
return await ApiResponse.ReadAsync<AuthResponse>(response, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Registrace. Roli (student / vyučující) určí API podle domény e-mailu.</summary>
|
||||||
|
public async Task<UserDto> RegisterAsync(RegisterRequest request, CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.PostAsJsonAsync("api/v1/auth/register", request, ct);
|
||||||
|
return await ApiResponse.ReadAsync<UserDto>(response, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ConfirmEmailAsync(string token, CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.PostAsJsonAsync("api/v1/auth/confirm-email", new EmailTokenRequest(token), ct);
|
||||||
|
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>API odpoví stejně, ať účet existuje, nebo ne – stránka tak neprozradí registrované e-maily.</summary>
|
||||||
|
public async Task ForgotPasswordAsync(string email, CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.PostAsJsonAsync("api/v1/auth/forgot-password", new ForgotPasswordRequest(email), ct);
|
||||||
|
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ResetPasswordAsync(ResetPasswordRequest request, CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.PostAsJsonAsync("api/v1/auth/reset-password", request, ct);
|
||||||
|
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Obnoví pár tokenů. Neplatný nebo už použitý refresh token → <c>null</c>.</summary>
|
||||||
|
public async Task<TokenSet?> RefreshAsync(string refreshToken, CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.PostAsJsonAsync("api/v1/auth/refresh", new RefreshTokenRequest(refreshToken), ct);
|
||||||
|
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||||
|
return null;
|
||||||
|
return (await ApiResponse.ReadAsync<AuthResponse>(response, ct)).Tokens;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
|
using Helpdesk.Web.Auth;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Api;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Přidá k požadavku na API access token přihlášeného uživatele z autentizační cookie.
|
||||||
|
/// Token je v té chvíli čerstvý – případnou obnovu už provedl <see cref="HelpdeskCookieEvents"/>.
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class BearerTokenHandler(IHttpContextAccessor accessor) : DelegatingHandler
|
||||||
|
{
|
||||||
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (accessor.HttpContext is { } httpContext &&
|
||||||
|
await httpContext.GetTokenAsync(AuthCookie.AccessToken) is { Length: > 0 } token)
|
||||||
|
{
|
||||||
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await base.SendAsync(request, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Api;
|
||||||
|
|
||||||
|
/// <summary>Endpointy API pro přihlášeného uživatele; access token přidává <see cref="BearerTokenHandler"/>.</summary>
|
||||||
|
public sealed class HelpdeskApiClient(HttpClient http)
|
||||||
|
{
|
||||||
|
public async Task<UserDto> GetMeAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.GetAsync("api/v1/users/me", ct);
|
||||||
|
return await ApiResponse.ReadAsync<UserDto>(response, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<UserDto> UpdateMeAsync(UpdateProfileRequest request, CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.PutAsJsonAsync("api/v1/users/me", request, ct);
|
||||||
|
return await ApiResponse.ReadAsync<UserDto>(response, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Odhlásí ze všech zařízení – API zneplatní všechny tokeny uživatele.</summary>
|
||||||
|
public async Task LogoutAllAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.PostAsync("api/v1/auth/logout-all", content: null, ct);
|
||||||
|
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Odhlásí toto zařízení – API zneplatní aktuální access token i předaný refresh token.</summary>
|
||||||
|
public async Task LogoutAsync(string refreshToken, CancellationToken ct)
|
||||||
|
{
|
||||||
|
using var response = await http.PostAsJsonAsync("api/v1/auth/logout", new RefreshTokenRequest(refreshToken), ct);
|
||||||
|
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using Helpdesk.Web.Api;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Auth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Autentizační cookie webu (kap. 9.4): identita uživatele pro Razor a tokeny pro volání API.
|
||||||
|
/// Cookie je HttpOnly a šifrovaná přes Data Protection – tokeny nejsou dostupné JavaScriptu.
|
||||||
|
/// </summary>
|
||||||
|
public static class AuthCookie
|
||||||
|
{
|
||||||
|
public const string Name = "ntbug.auth";
|
||||||
|
public const string AccessToken = "access_token";
|
||||||
|
public const string AccessTokenExpiresAt = "access_token_expires_at";
|
||||||
|
public const string RefreshToken = "refresh_token";
|
||||||
|
public const string RefreshTokenExpiresAt = "refresh_token_expires_at";
|
||||||
|
|
||||||
|
public static async Task SignInAsync(HttpContext httpContext, AuthResponse auth, bool persistent)
|
||||||
|
{
|
||||||
|
var properties = new AuthenticationProperties { IsPersistent = persistent };
|
||||||
|
StoreTokens(properties, auth.Tokens);
|
||||||
|
await httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, CreatePrincipal(auth.User), properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Přepíše identitu v cookie (např. po změně jména v profilu); tokeny zůstanou.</summary>
|
||||||
|
public static async Task UpdateUserAsync(HttpContext httpContext, UserDto user)
|
||||||
|
{
|
||||||
|
var result = await httpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
if (result.Succeeded)
|
||||||
|
await httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, CreatePrincipal(user), result.Properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClaimsPrincipal CreatePrincipal(UserDto user)
|
||||||
|
{
|
||||||
|
var identity = new ClaimsIdentity(
|
||||||
|
[
|
||||||
|
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(CultureInfo.InvariantCulture)),
|
||||||
|
new Claim(ClaimTypes.Name, user.FullName),
|
||||||
|
new Claim(ClaimTypes.Email, user.Email),
|
||||||
|
new Claim(ClaimTypes.Role, user.Role),
|
||||||
|
],
|
||||||
|
CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
return new ClaimsPrincipal(identity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StoreTokens(AuthenticationProperties properties, TokenSet tokens)
|
||||||
|
{
|
||||||
|
properties.StoreTokens(
|
||||||
|
[
|
||||||
|
new AuthenticationToken { Name = AccessToken, Value = tokens.AccessToken },
|
||||||
|
new AuthenticationToken { Name = AccessTokenExpiresAt, Value = tokens.AccessTokenExpiresAt.ToString("O", CultureInfo.InvariantCulture) },
|
||||||
|
new AuthenticationToken { Name = RefreshToken, Value = tokens.RefreshToken },
|
||||||
|
new AuthenticationToken { Name = RefreshTokenExpiresAt, Value = tokens.RefreshTokenExpiresAt.ToString("O", CultureInfo.InvariantCulture) },
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Trvalé přihlášení („zůstat přihlášen“) platí stejně dlouho jako refresh token.
|
||||||
|
if (properties.IsPersistent)
|
||||||
|
properties.ExpiresUtc = tokens.RefreshTokenExpiresAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TokenSet? ReadTokens(AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
var access = properties.GetTokenValue(AccessToken);
|
||||||
|
var refresh = properties.GetTokenValue(RefreshToken);
|
||||||
|
if (string.IsNullOrEmpty(access) || string.IsNullOrEmpty(refresh) ||
|
||||||
|
!TryParse(properties.GetTokenValue(AccessTokenExpiresAt), out var accessExpires) ||
|
||||||
|
!TryParse(properties.GetTokenValue(RefreshTokenExpiresAt), out var refreshExpires))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TokenSet(access, accessExpires, refresh, refreshExpires);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TryParse(string? value, out DateTimeOffset result) =>
|
||||||
|
DateTimeOffset.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out result);
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using Helpdesk.Web.Api;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Auth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Při každém požadavku zkontroluje tokeny v cookie. Access token (15 min) obnoví chvíli před
|
||||||
|
/// vypršením, takže volání API během požadavku už má platný token. Když API refresh token
|
||||||
|
/// odmítne (odhlášení jinde, změna role, změna hesla), uživatele odhlásí.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class HelpdeskCookieEvents(
|
||||||
|
TokenRefresher refresher,
|
||||||
|
AuthApiClient authApi,
|
||||||
|
TimeProvider clock,
|
||||||
|
ILogger<HelpdeskCookieEvents> logger) : CookieAuthenticationEvents
|
||||||
|
{
|
||||||
|
/// <summary>Jak dlouho před vypršením se access token obnoví.</summary>
|
||||||
|
internal static readonly TimeSpan RefreshMargin = TimeSpan.FromMinutes(1);
|
||||||
|
|
||||||
|
public override async Task ValidatePrincipal(CookieValidatePrincipalContext context)
|
||||||
|
{
|
||||||
|
var tokens = context.Properties is { } properties ? AuthCookie.ReadTokens(properties) : null;
|
||||||
|
var now = clock.GetUtcNow();
|
||||||
|
|
||||||
|
if (tokens is null || tokens.RefreshTokenExpiresAt <= now)
|
||||||
|
{
|
||||||
|
await RejectAsync(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokens.AccessTokenExpiresAt - now > RefreshMargin)
|
||||||
|
return;
|
||||||
|
|
||||||
|
TokenSet? renewed;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Sdílené volání nesmí zrušit odpojení prvního klienta – ostatní na výsledek čekají také.
|
||||||
|
renewed = await refresher.RefreshAsync(tokens.RefreshToken, token => authApi.RefreshAsync(token, CancellationToken.None));
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException or ApiException)
|
||||||
|
{
|
||||||
|
// API je dočasně nedostupné. Uživatele kvůli výpadku neodhlašujeme; požadavek
|
||||||
|
// dopadne chybovou stránkou a příští pokus obnovu zopakuje.
|
||||||
|
LogRefreshFailed(ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (renewed is null)
|
||||||
|
{
|
||||||
|
await RejectAsync(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthCookie.StoreTokens(context.Properties!, renewed);
|
||||||
|
context.ShouldRenew = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task RejectAsync(CookieValidatePrincipalContext context)
|
||||||
|
{
|
||||||
|
context.RejectPrincipal();
|
||||||
|
await context.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
[LoggerMessage(Level = LogLevel.Warning, Message = "Obnova access tokenu selhala, API je nedostupné.")]
|
||||||
|
private partial void LogRefreshFailed(Exception ex);
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using Helpdesk.Web.Api;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Auth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sloučí souběžné obnovy téhož refresh tokenu do jednoho volání API.
|
||||||
|
/// <para>
|
||||||
|
/// Refresh token jde použít jen jednou a druhé použití API vyhodnotí jako krádež – zneplatní
|
||||||
|
/// všechny tokeny uživatele (kap. 10.1). Prohlížeč přitom běžně pošle několik požadavků naráz
|
||||||
|
/// se stejnou cookie. Všechny proto čekají na jedno volání a dostanou stejný nový pár tokenů;
|
||||||
|
/// výsledek se drží ještě chvíli pro požadavky, které dorazí se starou cookie o něco později.
|
||||||
|
/// </para>
|
||||||
|
/// Platí pro jednu instanci webu; při více instancích by se evidence přesunula do sdílené cache.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class TokenRefresher(TimeProvider clock)
|
||||||
|
{
|
||||||
|
internal static readonly TimeSpan ResultLifetime = TimeSpan.FromMinutes(1);
|
||||||
|
|
||||||
|
private readonly ConcurrentDictionary<string, Entry> _refreshes = new();
|
||||||
|
|
||||||
|
/// <param name="refreshToken">Refresh token z cookie.</param>
|
||||||
|
/// <param name="refresh">Skutečné volání API; spustí se nejvýše jednou pro daný token.</param>
|
||||||
|
/// <returns>Nový pár tokenů, nebo <c>null</c>, když API token odmítlo.</returns>
|
||||||
|
public async Task<TokenSet?> RefreshAsync(string refreshToken, Func<string, Task<TokenSet?>> refresh)
|
||||||
|
{
|
||||||
|
RemoveExpired();
|
||||||
|
|
||||||
|
var key = Hash(refreshToken);
|
||||||
|
var entry = _refreshes.GetOrAdd(key, _ => new Entry(
|
||||||
|
new Lazy<Task<TokenSet?>>(() => refresh(refreshToken)),
|
||||||
|
clock.GetUtcNow()));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await entry.Result.Value;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Dočasná chyba (API nedostupné) se nepamatuje – další požadavek to zkusí znovu.
|
||||||
|
_refreshes.TryRemove(new KeyValuePair<string, Entry>(key, entry));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveExpired()
|
||||||
|
{
|
||||||
|
var threshold = clock.GetUtcNow() - ResultLifetime;
|
||||||
|
foreach (var (key, entry) in _refreshes)
|
||||||
|
{
|
||||||
|
if (entry.CreatedAt < threshold && entry.Result.IsValueCreated && entry.Result.Value.IsCompleted)
|
||||||
|
_refreshes.TryRemove(new KeyValuePair<string, Entry>(key, entry));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Klíčem je hash, aby se refresh tokeny nedržely v paměti jako klíče slovníku.
|
||||||
|
private static string Hash(string token) => Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(token)));
|
||||||
|
|
||||||
|
private sealed record Entry(Lazy<Task<TokenSet?>> Result, DateTimeOffset CreatedAt);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
namespace Helpdesk.Web.Auth;
|
||||||
|
|
||||||
|
/// <summary>Kódy rolí z API (claim <c>role</c>) a jejich české názvy pro rozhraní.</summary>
|
||||||
|
public static class UserRoles
|
||||||
|
{
|
||||||
|
public const string Student = "STUDENT";
|
||||||
|
public const string Teacher = "TEACHER";
|
||||||
|
public const string FacilityManager = "FACILITY_MANAGER";
|
||||||
|
public const string Management = "MANAGEMENT";
|
||||||
|
public const string Admin = "ADMIN";
|
||||||
|
|
||||||
|
public static string DisplayName(string? role) => role switch
|
||||||
|
{
|
||||||
|
Student => "Student",
|
||||||
|
Teacher => "Vyučující",
|
||||||
|
FacilityManager => "Správce budov",
|
||||||
|
Management => "Vedení školy",
|
||||||
|
Admin => "Administrátor",
|
||||||
|
_ => "Uživatel",
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Helpdesk.Web.Api;
|
||||||
|
using Helpdesk.Web.Auth;
|
||||||
|
using Helpdesk.Web.Infrastructure;
|
||||||
|
using Helpdesk.Web.Models;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Přihlášení, registrace, ověření e-mailu a obnova hesla (FR-01 – FR-03).
|
||||||
|
/// Stránky pro nepřihlášené jsou označené <see cref="AllowAnonymousAttribute"/>.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AccountController(AuthApiClient authApi, HelpdeskApiClient api) : Controller
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("login")]
|
||||||
|
public IActionResult Login(string? returnUrl)
|
||||||
|
{
|
||||||
|
if (User.Identity?.IsAuthenticated == true)
|
||||||
|
return LocalRedirect(SafeReturnUrl(returnUrl));
|
||||||
|
|
||||||
|
ViewData["ReturnUrl"] = returnUrl;
|
||||||
|
return View(new LoginViewModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpPost("login")]
|
||||||
|
public async Task<IActionResult> Login(LoginViewModel model, string? returnUrl, CancellationToken ct)
|
||||||
|
{
|
||||||
|
ViewData["ReturnUrl"] = returnUrl;
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return View(model);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var auth = await authApi.LoginAsync(new LoginRequest(model.Email.Trim(), model.Password), ct);
|
||||||
|
await AuthCookie.SignInAsync(HttpContext, auth, model.RememberMe);
|
||||||
|
return LocalRedirect(SafeReturnUrl(returnUrl));
|
||||||
|
}
|
||||||
|
catch (ApiException ex) when (ex.StatusCode is HttpStatusCode.BadRequest or HttpStatusCode.Unauthorized
|
||||||
|
or HttpStatusCode.Forbidden or HttpStatusCode.TooManyRequests)
|
||||||
|
{
|
||||||
|
// 401 špatné heslo / zamčený účet, 403 neověřený e-mail nebo deaktivovaný účet – API vrací český text.
|
||||||
|
ModelState.AddApiErrors(ex, typeof(LoginViewModel));
|
||||||
|
model.Password = "";
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("register")]
|
||||||
|
public IActionResult Register() =>
|
||||||
|
User.Identity?.IsAuthenticated == true ? RedirectToAction("Index", "Home") : View(new RegisterViewModel());
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpPost("register")]
|
||||||
|
public async Task<IActionResult> Register(RegisterViewModel model, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return View(model);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var user = await authApi.RegisterAsync(
|
||||||
|
new RegisterRequest(model.Email.Trim(), model.Password, model.FirstName.Trim(), model.LastName.Trim()), ct);
|
||||||
|
return View("RegisterDone", user.Email);
|
||||||
|
}
|
||||||
|
catch (ApiException ex) when (ex.StatusCode is HttpStatusCode.BadRequest or HttpStatusCode.Conflict or HttpStatusCode.TooManyRequests)
|
||||||
|
{
|
||||||
|
// 400 cizí doména nebo validace, 409 účet už existuje.
|
||||||
|
ModelState.AddApiErrors(ex, typeof(RegisterViewModel));
|
||||||
|
model.Password = model.ConfirmPassword = "";
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Odkaz z registračního e-mailu. Token se spotřebuje až tlačítkem, ne samotným otevřením odkazu.</summary>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("confirm-email")]
|
||||||
|
public IActionResult ConfirmEmail(string? token) => View(new EmailTokenViewModel { Token = token ?? "" });
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpPost("confirm-email")]
|
||||||
|
public async Task<IActionResult> ConfirmEmail(EmailTokenViewModel model, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return View(model);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await authApi.ConfirmEmailAsync(model.Token, ct);
|
||||||
|
TempData.SetSuccess("E-mail je ověřený. Teď se můžete přihlásit.");
|
||||||
|
return RedirectToAction(nameof(Login));
|
||||||
|
}
|
||||||
|
catch (ApiException ex) when (ex.StatusCode is HttpStatusCode.BadRequest or HttpStatusCode.TooManyRequests)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, ex.UserMessage);
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("forgot-password")]
|
||||||
|
public IActionResult ForgotPassword() => View(new ForgotPasswordViewModel());
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpPost("forgot-password")]
|
||||||
|
public async Task<IActionResult> ForgotPassword(ForgotPasswordViewModel model, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return View(model);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await authApi.ForgotPasswordAsync(model.Email.Trim(), ct);
|
||||||
|
return View("ForgotPasswordDone", model.Email.Trim());
|
||||||
|
}
|
||||||
|
catch (ApiException ex) when (ex.StatusCode is HttpStatusCode.BadRequest or HttpStatusCode.TooManyRequests)
|
||||||
|
{
|
||||||
|
ModelState.AddApiErrors(ex, typeof(ForgotPasswordViewModel));
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("reset-password")]
|
||||||
|
public IActionResult ResetPassword(string? token) => View(new ResetPasswordViewModel { Token = token ?? "" });
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpPost("reset-password")]
|
||||||
|
public async Task<IActionResult> ResetPassword(ResetPasswordViewModel model, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
model.NewPassword = model.ConfirmPassword = "";
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await authApi.ResetPasswordAsync(new ResetPasswordRequest(model.Token, model.NewPassword), ct);
|
||||||
|
}
|
||||||
|
catch (ApiException ex) when (ex.StatusCode is HttpStatusCode.BadRequest or HttpStatusCode.TooManyRequests)
|
||||||
|
{
|
||||||
|
ModelState.AddApiErrors(ex, typeof(ResetPasswordViewModel));
|
||||||
|
model.NewPassword = model.ConfirmPassword = "";
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
// API po změně hesla zneplatnilo všechna přihlášení – i to v tomto prohlížeči.
|
||||||
|
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
TempData.SetSuccess("Heslo je změněné. Přihlaste se novým heslem.");
|
||||||
|
return RedirectToAction(nameof(Login));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("logout")]
|
||||||
|
public async Task<IActionResult> Logout(CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (await HttpContext.GetTokenAsync(AuthCookie.RefreshToken) is { Length: > 0 } refreshToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await api.LogoutAsync(refreshToken, ct);
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is ApiException or HttpRequestException)
|
||||||
|
{
|
||||||
|
// I když API zrovna nejde (nebo jsou tokeny už neplatné), lokální cookie smažeme.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
TempData.SetSuccess("Byli jste odhlášeni.");
|
||||||
|
return RedirectToAction(nameof(Login));
|
||||||
|
}
|
||||||
|
|
||||||
|
private string SafeReturnUrl(string? returnUrl) =>
|
||||||
|
!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl) ? returnUrl : "/";
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Controllers;
|
||||||
|
|
||||||
|
public sealed class HomeController : Controller
|
||||||
|
{
|
||||||
|
/// <summary>Nástěnka.</summary>
|
||||||
|
public IActionResult Index() => View();
|
||||||
|
|
||||||
|
/// <summary>Chybová stránka pro neošetřené výjimky a stavové kódy (404, 403, …).</summary>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[Route("error/{statusCode:int?}")]
|
||||||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
|
public IActionResult Error(int? statusCode)
|
||||||
|
{
|
||||||
|
var code = statusCode ?? StatusCodes.Status500InternalServerError;
|
||||||
|
Response.StatusCode = code;
|
||||||
|
return View(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Helpdesk.Web.Api;
|
||||||
|
using Helpdesk.Web.Auth;
|
||||||
|
using Helpdesk.Web.Infrastructure;
|
||||||
|
using Helpdesk.Web.Models;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Controllers;
|
||||||
|
|
||||||
|
/// <summary>Profil přihlášeného uživatele a nastavení notifikací (FR-05).</summary>
|
||||||
|
[Route("profile")]
|
||||||
|
public sealed class ProfileController(HelpdeskApiClient api) : Controller
|
||||||
|
{
|
||||||
|
[HttpGet("")]
|
||||||
|
public async Task<IActionResult> Index(CancellationToken ct) =>
|
||||||
|
View(ProfileViewModel.From(await api.GetMeAsync(ct)));
|
||||||
|
|
||||||
|
[HttpPost("")]
|
||||||
|
public async Task<IActionResult> Index(ProfileViewModel model, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return View(await WithReadOnlyFieldsAsync(model, ct));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var user = await api.UpdateMeAsync(
|
||||||
|
new UpdateProfileRequest(model.FirstName.Trim(), model.LastName.Trim(), model.Phone, model.EmailNotificationsEnabled), ct);
|
||||||
|
// Jméno je i v cookie (menu, pozdrav na nástěnce) – přepíšeme ho.
|
||||||
|
await AuthCookie.UpdateUserAsync(HttpContext, user);
|
||||||
|
TempData.SetSuccess("Profil je uložený.");
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
catch (ApiException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)
|
||||||
|
{
|
||||||
|
ModelState.AddApiErrors(ex, typeof(ProfileViewModel));
|
||||||
|
return View(await WithReadOnlyFieldsAsync(model, ct));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Odhlášení ze všech zařízení – zneplatní tokeny i v mobilní aplikaci.</summary>
|
||||||
|
[HttpPost("logout-all")]
|
||||||
|
public async Task<IActionResult> LogoutAll(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await api.LogoutAllAsync(ct);
|
||||||
|
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
TempData.SetSuccess("Byli jste odhlášeni ze všech zařízení.");
|
||||||
|
return RedirectToAction("Login", "Account");
|
||||||
|
}
|
||||||
|
|
||||||
|
// E-mail a role se formulářem neposílají; při opakovaném zobrazení je doplníme z API.
|
||||||
|
private async Task<ProfileViewModel> WithReadOnlyFieldsAsync(ProfileViewModel model, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var user = await api.GetMeAsync(ct);
|
||||||
|
model.Email = user.Email;
|
||||||
|
model.Role = user.Role;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<InternalsVisibleTo Include="Helpdesk.Web.Tests" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Helpdesk.Web.Api;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Infrastructure;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Společné zpracování chyb API, které kontroler sám neošetřil (validaci formulářů řeší kontrolery):
|
||||||
|
/// 401 → odhlásit a poslat na přihlášení, 403/404 → chybová stránka, nedostupné API → 503.
|
||||||
|
/// </summary>
|
||||||
|
internal sealed partial class ApiExceptionFilter(
|
||||||
|
ITempDataDictionaryFactory tempDataFactory,
|
||||||
|
ILogger<ApiExceptionFilter> logger) : IAsyncExceptionFilter
|
||||||
|
{
|
||||||
|
public async Task OnExceptionAsync(ExceptionContext context)
|
||||||
|
{
|
||||||
|
var http = context.HttpContext;
|
||||||
|
|
||||||
|
switch (context.Exception)
|
||||||
|
{
|
||||||
|
case ApiException { StatusCode: HttpStatusCode.Unauthorized }:
|
||||||
|
// Tokeny byly zneplatněny (odhlášení ze všech zařízení, změna role…).
|
||||||
|
await http.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
tempDataFactory.GetTempData(http).SetError("Přihlášení vypršelo. Přihlaste se prosím znovu.");
|
||||||
|
var returnUrl = HttpMethods.IsGet(http.Request.Method) ? http.Request.Path + http.Request.QueryString : "/";
|
||||||
|
context.Result = new RedirectToActionResult("Login", "Account", new { returnUrl });
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ApiException { StatusCode: HttpStatusCode.Forbidden or HttpStatusCode.NotFound or HttpStatusCode.TooManyRequests } api:
|
||||||
|
context.Result = ErrorView((int)api.StatusCode);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HttpRequestException or TaskCanceledException when !http.RequestAborted.IsCancellationRequested:
|
||||||
|
LogApiUnavailable(context.Exception);
|
||||||
|
context.Result = ErrorView(StatusCodes.Status503ServiceUnavailable);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return; // ostatní chyby zpracuje globální exception handler (500)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.ExceptionHandled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ViewResult ErrorView(int statusCode) => new()
|
||||||
|
{
|
||||||
|
ViewName = "~/Views/Home/Error.cshtml",
|
||||||
|
StatusCode = statusCode,
|
||||||
|
ViewData = new ViewDataDictionary<int>(new Microsoft.AspNetCore.Mvc.ModelBinding.EmptyModelMetadataProvider(), new()) { Model = statusCode },
|
||||||
|
};
|
||||||
|
|
||||||
|
[LoggerMessage(Level = LogLevel.Error, Message = "Backend API je nedostupné.")]
|
||||||
|
private partial void LogApiUnavailable(Exception ex);
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Infrastructure;
|
||||||
|
|
||||||
|
/// <summary>Jednorázové zprávy přes přesměrování (vzor Post/Redirect/Get).</summary>
|
||||||
|
public static class Flash
|
||||||
|
{
|
||||||
|
public const string Success = "Flash.Success";
|
||||||
|
public const string Error = "Flash.Error";
|
||||||
|
|
||||||
|
public static void SetSuccess(this ITempDataDictionary tempData, string message) => tempData[Success] = message;
|
||||||
|
|
||||||
|
public static void SetError(this ITempDataDictionary tempData, string message) => tempData[Error] = message;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using Helpdesk.Web.Api;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Infrastructure;
|
||||||
|
|
||||||
|
public static class ModelStateExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Přenese chyby z API do formuláře: chyby polí k odpovídajícím vlastnostem view modelu
|
||||||
|
/// (API vrací názvy v camelCase), ostatní do souhrnu nad formulářem.
|
||||||
|
/// </summary>
|
||||||
|
public static void AddApiErrors(this ModelStateDictionary modelState, ApiException error, Type viewModelType)
|
||||||
|
{
|
||||||
|
var properties = viewModelType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||||
|
.ToDictionary(p => p.Name, p => p.Name, StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
var anyFieldError = false;
|
||||||
|
foreach (var (field, messages) in error.Errors)
|
||||||
|
{
|
||||||
|
var key = properties.TryGetValue(field, out var property) ? property : string.Empty;
|
||||||
|
anyFieldError |= key.Length > 0;
|
||||||
|
foreach (var message in messages)
|
||||||
|
modelState.AddModelError(key, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!anyFieldError)
|
||||||
|
modelState.AddModelError(string.Empty, error.UserMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Helpdesk.Web.Auth;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Infrastructure;
|
||||||
|
|
||||||
|
/// <summary>Položka hlavního menu. Bez rolí ji vidí každý přihlášený uživatel.</summary>
|
||||||
|
public sealed record NavItem(string Text, string Controller, string Action, params string[] Roles)
|
||||||
|
{
|
||||||
|
public bool IsVisibleTo(ClaimsPrincipal user) =>
|
||||||
|
user.Identity?.IsAuthenticated == true && (Roles.Length == 0 || Roles.Any(user.IsInRole));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hlavní menu na jednom místě. Viditelnost podle role je jen pohodlí pro uživatele –
|
||||||
|
/// oprávnění skutečně kontroluje API (kap. 9.3 návrhu).
|
||||||
|
/// </summary>
|
||||||
|
public static class Navigation
|
||||||
|
{
|
||||||
|
public static readonly IReadOnlyList<NavItem> Items =
|
||||||
|
[
|
||||||
|
new("Nástěnka", "Home", "Index"),
|
||||||
|
];
|
||||||
|
|
||||||
|
public static IEnumerable<NavItem> For(ClaimsPrincipal user) => Items.Where(i => i.IsVisibleTo(user));
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
namespace Helpdesk.Web.Infrastructure;
|
||||||
|
|
||||||
|
/// <summary>Bezpečnostní hlavičky pro všechny odpovědi webu.</summary>
|
||||||
|
public static class SecurityHeaders
|
||||||
|
{
|
||||||
|
// Všechny skripty a styly jsou ze stejného původu (wwwroot), takže CSP nepotřebuje žádné výjimky.
|
||||||
|
private const string ContentSecurityPolicy =
|
||||||
|
"default-src 'self'; img-src 'self' data: blob:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'";
|
||||||
|
|
||||||
|
public static IApplicationBuilder UseSecurityHeaders(this IApplicationBuilder app) =>
|
||||||
|
app.Use(async (context, next) =>
|
||||||
|
{
|
||||||
|
var headers = context.Response.Headers;
|
||||||
|
headers.ContentSecurityPolicy = ContentSecurityPolicy;
|
||||||
|
headers.XContentTypeOptions = "nosniff";
|
||||||
|
headers.XFrameOptions = "DENY";
|
||||||
|
// Odkazy z e-mailů nesou token v URL – nesmí uniknout v hlavičce Referer.
|
||||||
|
headers["Referrer-Policy"] = "no-referrer";
|
||||||
|
await next();
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
namespace Helpdesk.Web.Infrastructure;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// České názvy stavů závad a návrhů podle návrhového dokumentu (kap. 6 a 7).
|
||||||
|
/// API vrací kódy (<c>IN_PROGRESS</c>); CSS třída štítku je <c>status-{kód}</c>.
|
||||||
|
/// </summary>
|
||||||
|
public static class StatusLabels
|
||||||
|
{
|
||||||
|
public static string For(string? status, bool isProposal = false) => status?.ToUpperInvariant() switch
|
||||||
|
{
|
||||||
|
// závady
|
||||||
|
"RECEIVED" => "Přijata",
|
||||||
|
"ASSIGNED" => "Přiřazena",
|
||||||
|
"IN_PROGRESS" => "V řešení",
|
||||||
|
"PENDING_VERIFICATION" => "Čeká na ověření",
|
||||||
|
"RESOLVED" => "Vyřešena",
|
||||||
|
"REJECTED" => isProposal ? "Zamítnut" : "Zamítnuta",
|
||||||
|
// návrhy
|
||||||
|
"SUBMITTED" => "Podán",
|
||||||
|
"UNDER_REVIEW" => "V posouzení",
|
||||||
|
"ACCEPTED" => "Přijat",
|
||||||
|
"IMPLEMENTED" => "Realizován",
|
||||||
|
null or "" => "Neznámý stav",
|
||||||
|
_ => status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Model pro partial <c>_StatusBadge</c>.</summary>
|
||||||
|
public sealed record StatusBadgeModel(string Status, bool IsProposal = false);
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Models;
|
||||||
|
|
||||||
|
// Pravidla hesla odpovídají API: 8–64 znaků (BCrypt zpracuje nejvýše 72 bajtů).
|
||||||
|
internal static class PasswordRules
|
||||||
|
{
|
||||||
|
public const int MinLength = 8;
|
||||||
|
public const int MaxLength = 64;
|
||||||
|
public const string LengthMessage = "Heslo musí mít 8 až 64 znaků.";
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class LoginViewModel
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "Zadejte e-mail.")]
|
||||||
|
[EmailAddress(ErrorMessage = "Zadejte platný e-mail.")]
|
||||||
|
[Display(Name = "E-mail")]
|
||||||
|
public string Email { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Zadejte heslo.")]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Heslo")]
|
||||||
|
public string Password { get; set; } = "";
|
||||||
|
|
||||||
|
[Display(Name = "Zůstat přihlášen")]
|
||||||
|
public bool RememberMe { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RegisterViewModel
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "Zadejte univerzitní e-mail.")]
|
||||||
|
[EmailAddress(ErrorMessage = "Zadejte platný e-mail.")]
|
||||||
|
[StringLength(254)]
|
||||||
|
[Display(Name = "Univerzitní e-mail")]
|
||||||
|
public string Email { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Zadejte jméno.")]
|
||||||
|
[StringLength(100, ErrorMessage = "Jméno může mít nejvýše 100 znaků.")]
|
||||||
|
[Display(Name = "Jméno")]
|
||||||
|
public string FirstName { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Zadejte příjmení.")]
|
||||||
|
[StringLength(100, ErrorMessage = "Příjmení může mít nejvýše 100 znaků.")]
|
||||||
|
[Display(Name = "Příjmení")]
|
||||||
|
public string LastName { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Zadejte heslo.")]
|
||||||
|
[StringLength(PasswordRules.MaxLength, MinimumLength = PasswordRules.MinLength, ErrorMessage = PasswordRules.LengthMessage)]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Heslo")]
|
||||||
|
public string Password { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Zadejte heslo znovu.")]
|
||||||
|
[Compare(nameof(Password), ErrorMessage = "Hesla se neshodují.")]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Heslo znovu")]
|
||||||
|
public string ConfirmPassword { get; set; } = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Stránka z odkazu v e-mailu – token se odešle až tlačítkem.</summary>
|
||||||
|
public sealed class EmailTokenViewModel
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string Token { get; set; } = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class ForgotPasswordViewModel
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "Zadejte e-mail.")]
|
||||||
|
[EmailAddress(ErrorMessage = "Zadejte platný e-mail.")]
|
||||||
|
[Display(Name = "E-mail")]
|
||||||
|
public string Email { get; set; } = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class ResetPasswordViewModel
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string Token { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Zadejte nové heslo.")]
|
||||||
|
[StringLength(PasswordRules.MaxLength, MinimumLength = PasswordRules.MinLength, ErrorMessage = PasswordRules.LengthMessage)]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Nové heslo")]
|
||||||
|
public string NewPassword { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Zadejte nové heslo znovu.")]
|
||||||
|
[Compare(nameof(NewPassword), ErrorMessage = "Hesla se neshodují.")]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Nové heslo znovu")]
|
||||||
|
public string ConfirmPassword { get; set; } = "";
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Helpdesk.Web.Api;
|
||||||
|
|
||||||
|
namespace Helpdesk.Web.Models;
|
||||||
|
|
||||||
|
public sealed class ProfileViewModel
|
||||||
|
{
|
||||||
|
// Jen pro zobrazení – e-mail a roli uživatel sám nemění.
|
||||||
|
public string Email { get; set; } = "";
|
||||||
|
public string Role { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Zadejte jméno.")]
|
||||||
|
[StringLength(100, ErrorMessage = "Jméno může mít nejvýše 100 znaků.")]
|
||||||
|
[Display(Name = "Jméno")]
|
||||||
|
public string FirstName { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Zadejte příjmení.")]
|
||||||
|
[StringLength(100, ErrorMessage = "Příjmení může mít nejvýše 100 znaků.")]
|
||||||
|
[Display(Name = "Příjmení")]
|
||||||
|
public string LastName { get; set; } = "";
|
||||||
|
|
||||||
|
[StringLength(30, ErrorMessage = "Telefon může mít nejvýše 30 znaků.")]
|
||||||
|
[RegularExpression(@"^\+?[0-9 ]+$", ErrorMessage = "Telefon smí obsahovat jen číslice, mezery a úvodní +.")]
|
||||||
|
[Display(Name = "Telefon")]
|
||||||
|
public string? Phone { get; set; }
|
||||||
|
|
||||||
|
[Display(Name = "Posílat upozornění e-mailem")]
|
||||||
|
public bool EmailNotificationsEnabled { get; set; }
|
||||||
|
|
||||||
|
public static ProfileViewModel From(UserDto user) => new()
|
||||||
|
{
|
||||||
|
Email = user.Email,
|
||||||
|
Role = user.Role,
|
||||||
|
FirstName = user.FirstName,
|
||||||
|
LastName = user.LastName,
|
||||||
|
Phone = user.Phone,
|
||||||
|
EmailNotificationsEnabled = user.EmailNotificationsEnabled,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Net;
|
||||||
|
using Helpdesk.Web.Api;
|
||||||
|
using Helpdesk.Web.Auth;
|
||||||
|
using Helpdesk.Web.Infrastructure;
|
||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
using Microsoft.AspNetCore.Localization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
builder.Services.AddControllersWithViews(options =>
|
||||||
|
{
|
||||||
|
// Všechny stránky vyžadují přihlášení, výjimky jsou označené [AllowAnonymous].
|
||||||
|
options.Filters.Add(new AuthorizeFilter());
|
||||||
|
// Anti-forgery token u všech formulářů odesílaných metodou POST (CSRF, kap. 10).
|
||||||
|
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
|
||||||
|
options.Filters.Add<ApiExceptionFilter>();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Klient REST API. Web nemá přístup k databázi – všechna data jdou přes API (kap. 9.4).
|
||||||
|
builder.Services.AddOptions<ApiOptions>()
|
||||||
|
.BindConfiguration(ApiOptions.Section)
|
||||||
|
.Validate(o => Uri.TryCreate(o.BaseUrl, UriKind.Absolute, out _), "Nastavte Api:BaseUrl na adresu backendu, např. http://api:8080/.")
|
||||||
|
.ValidateOnStart();
|
||||||
|
|
||||||
|
static void ConfigureApiClient(IServiceProvider services, HttpClient http)
|
||||||
|
{
|
||||||
|
var options = services.GetRequiredService<IOptions<ApiOptions>>().Value;
|
||||||
|
http.BaseAddress = new Uri(options.BaseUrl.EndsWith('/') ? options.BaseUrl : options.BaseUrl + "/");
|
||||||
|
http.Timeout = options.Timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.Services.AddHttpContextAccessor();
|
||||||
|
builder.Services.AddTransient<BearerTokenHandler>();
|
||||||
|
builder.Services.AddHttpClient<AuthApiClient>(ConfigureApiClient);
|
||||||
|
builder.Services.AddHttpClient<HelpdeskApiClient>(ConfigureApiClient).AddHttpMessageHandler<BearerTokenHandler>();
|
||||||
|
|
||||||
|
// Přihlášení: tokeny API v šifrované HttpOnly cookie, obnova access tokenu při ověření cookie.
|
||||||
|
builder.Services.AddSingleton(TimeProvider.System);
|
||||||
|
builder.Services.AddSingleton<TokenRefresher>();
|
||||||
|
builder.Services.AddScoped<HelpdeskCookieEvents>();
|
||||||
|
builder.Services
|
||||||
|
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||||
|
.AddCookie(options =>
|
||||||
|
{
|
||||||
|
options.Cookie.Name = AuthCookie.Name;
|
||||||
|
options.Cookie.HttpOnly = true;
|
||||||
|
options.Cookie.SameSite = SameSiteMode.Lax;
|
||||||
|
options.Cookie.SecurePolicy = builder.Environment.IsDevelopment()
|
||||||
|
? CookieSecurePolicy.SameAsRequest
|
||||||
|
: CookieSecurePolicy.Always;
|
||||||
|
options.LoginPath = "/login";
|
||||||
|
options.LogoutPath = "/logout";
|
||||||
|
options.AccessDeniedPath = "/error/403";
|
||||||
|
// Cookie nepřežije refresh token (14 dní); po jeho vypršení se uživatel přihlásí znovu.
|
||||||
|
options.ExpireTimeSpan = TimeSpan.FromDays(14);
|
||||||
|
options.SlidingExpiration = false;
|
||||||
|
options.EventsType = typeof(HelpdeskCookieEvents);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Klíče Data Protection šifrují autentizační cookie. Bez uložení na volume by
|
||||||
|
// restart kontejneru odhlásil všechny uživatele (kap. 15.3).
|
||||||
|
var dataProtection = builder.Services.AddDataProtection().SetApplicationName("Helpdesk.Web");
|
||||||
|
var keysPath = builder.Configuration["DataProtection:KeysPath"];
|
||||||
|
if (!string.IsNullOrWhiteSpace(keysPath))
|
||||||
|
dataProtection.PersistKeysToFileSystem(new DirectoryInfo(keysPath));
|
||||||
|
|
||||||
|
var trustedProxy = builder.Configuration["ReverseProxy:TrustedIp"];
|
||||||
|
if (!string.IsNullOrWhiteSpace(trustedProxy))
|
||||||
|
{
|
||||||
|
if (!IPAddress.TryParse(trustedProxy, out var proxyAddress))
|
||||||
|
throw new InvalidOperationException("Nastavte platnou IP adresu důvěryhodné reverse proxy.");
|
||||||
|
|
||||||
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
|
{
|
||||||
|
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||||
|
options.KnownIPNetworks.Clear();
|
||||||
|
options.KnownProxies.Clear();
|
||||||
|
options.KnownProxies.Add(proxyAddress);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(trustedProxy))
|
||||||
|
app.UseForwardedHeaders();
|
||||||
|
|
||||||
|
if (!app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseExceptionHandler("/error");
|
||||||
|
app.UseHsts();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseStatusCodePagesWithReExecute("/error/{0}");
|
||||||
|
app.UseSecurityHeaders();
|
||||||
|
|
||||||
|
var czech = new CultureInfo("cs-CZ");
|
||||||
|
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||||
|
{
|
||||||
|
DefaultRequestCulture = new RequestCulture(czech),
|
||||||
|
SupportedCultures = [czech],
|
||||||
|
SupportedUICultures = [czech],
|
||||||
|
});
|
||||||
|
|
||||||
|
app.UseRouting();
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.MapStaticAssets();
|
||||||
|
app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}").WithStaticAssets();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
|
|
||||||
|
/// <summary>Vstupní bod – veřejný kvůli testům (WebApplicationFactory).</summary>
|
||||||
|
public partial class Program;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"applicationUrl": "http://localhost:5080",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
@model EmailTokenViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Ověření e-mailu";
|
||||||
|
var failed = !ViewData.ModelState.IsValid || string.IsNullOrEmpty(Model.Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-auth">
|
||||||
|
<h1>Ověření e-mailu</h1>
|
||||||
|
<div class="app-card">
|
||||||
|
@if (failed)
|
||||||
|
{
|
||||||
|
<partial name="_FormErrors" />
|
||||||
|
<p class="mb-0">Odkaz je neplatný, už byl použit, nebo vypršel. Pokud jste e-mail už ověřili, stačí se přihlásit.</p>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<p>Dokončete registraci potvrzením svého e-mailu.</p>
|
||||||
|
<form method="post" asp-action="ConfirmEmail">
|
||||||
|
<input type="hidden" asp-for="Token" />
|
||||||
|
<button type="submit" class="btn btn-primary w-100">Ověřit e-mail</button>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div class="app-auth-links">
|
||||||
|
<a asp-action="Login">Přejít na přihlášení</a>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
@model ForgotPasswordViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Zapomenuté heslo";
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-auth">
|
||||||
|
<h1>Zapomenuté heslo</h1>
|
||||||
|
<p class="text-body-secondary">Pošleme vám odkaz, kterým si nastavíte nové heslo.</p>
|
||||||
|
|
||||||
|
<div class="app-card">
|
||||||
|
<partial name="_FormErrors" />
|
||||||
|
<form method="post" asp-action="ForgotPassword" novalidate>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Email" class="form-label"></label>
|
||||||
|
<input asp-for="Email" class="form-control" autocomplete="email" autofocus />
|
||||||
|
<span asp-validation-for="Email" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary w-100">Poslat odkaz</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="app-auth-links">
|
||||||
|
<a asp-action="Login">Zpět na přihlášení</a>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
@model string
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Zkontrolujte e-mail";
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-auth">
|
||||||
|
<h1>Zkontrolujte e-mail</h1>
|
||||||
|
<div class="app-card">
|
||||||
|
<p>Pokud k adrese <strong>@Model</strong> existuje účet, poslali jsme na ni odkaz pro nastavení nového hesla.</p>
|
||||||
|
<p class="mb-0 text-body-secondary">Odkaz platí 1 hodinu a jde použít jen jednou.</p>
|
||||||
|
</div>
|
||||||
|
<div class="app-auth-links">
|
||||||
|
<a asp-action="Login">Zpět na přihlášení</a>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
@model LoginViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Přihlášení";
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-auth">
|
||||||
|
<h1>Přihlášení</h1>
|
||||||
|
<p class="text-body-secondary">Přihlaste se univerzitním e-mailem.</p>
|
||||||
|
|
||||||
|
<div class="app-card">
|
||||||
|
<partial name="_FormErrors" />
|
||||||
|
<form method="post" asp-action="Login" asp-route-returnUrl="@ViewData["ReturnUrl"]" novalidate>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Email" class="form-label"></label>
|
||||||
|
<input asp-for="Email" class="form-control" autocomplete="username" autofocus />
|
||||||
|
<span asp-validation-for="Email" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Password" class="form-label"></label>
|
||||||
|
<input asp-for="Password" class="form-control" autocomplete="current-password" />
|
||||||
|
<span asp-validation-for="Password" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-check mb-3">
|
||||||
|
<input asp-for="RememberMe" class="form-check-input" />
|
||||||
|
<label asp-for="RememberMe" class="form-check-label"></label>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary w-100">Přihlásit se</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="app-auth-links">
|
||||||
|
<a asp-action="ForgotPassword">Zapomenuté heslo</a>
|
||||||
|
<span>Nemáte účet? <a asp-action="Register">Zaregistrujte se</a></span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
@model RegisterViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Registrace";
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-auth">
|
||||||
|
<h1>Registrace</h1>
|
||||||
|
<p class="text-body-secondary">Studenti a vyučující se registrují univerzitním e-mailem. Roli určí doména e-mailu.</p>
|
||||||
|
|
||||||
|
<div class="app-card">
|
||||||
|
<partial name="_FormErrors" />
|
||||||
|
<form method="post" asp-action="Register" novalidate>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Email" class="form-label"></label>
|
||||||
|
<input asp-for="Email" class="form-control" autocomplete="email" autofocus />
|
||||||
|
<span asp-validation-for="Email" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<div class="row g-3 mb-3">
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<label asp-for="FirstName" class="form-label"></label>
|
||||||
|
<input asp-for="FirstName" class="form-control" autocomplete="given-name" />
|
||||||
|
<span asp-validation-for="FirstName" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<label asp-for="LastName" class="form-label"></label>
|
||||||
|
<input asp-for="LastName" class="form-control" autocomplete="family-name" />
|
||||||
|
<span asp-validation-for="LastName" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Password" class="form-label"></label>
|
||||||
|
<input asp-for="Password" class="form-control" autocomplete="new-password" aria-describedby="passwordHelp" />
|
||||||
|
<div id="passwordHelp" class="form-text">8 až 64 znaků.</div>
|
||||||
|
<span asp-validation-for="Password" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-4">
|
||||||
|
<label asp-for="ConfirmPassword" class="form-label"></label>
|
||||||
|
<input asp-for="ConfirmPassword" class="form-control" autocomplete="new-password" />
|
||||||
|
<span asp-validation-for="ConfirmPassword" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary w-100">Zaregistrovat se</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="app-auth-links">
|
||||||
|
<span>Už máte účet? <a asp-action="Login">Přihlaste se</a></span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
@model string
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Ověřte e-mail";
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-auth">
|
||||||
|
<h1>Ověřte svůj e-mail</h1>
|
||||||
|
<div class="app-card">
|
||||||
|
<p>Na adresu <strong>@Model</strong> jsme poslali odkaz pro ověření e-mailu. Platí 24 hodin.</p>
|
||||||
|
<p class="mb-0 text-body-secondary">Po ověření se budete moct přihlásit. Pokud e-mail nevidíte, podívejte se i do nevyžádané pošty.</p>
|
||||||
|
</div>
|
||||||
|
<div class="app-auth-links">
|
||||||
|
<a asp-action="Login">Zpět na přihlášení</a>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
@model ResetPasswordViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Nové heslo";
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-auth">
|
||||||
|
<h1>Nové heslo</h1>
|
||||||
|
|
||||||
|
<div class="app-card">
|
||||||
|
@if (string.IsNullOrEmpty(Model.Token))
|
||||||
|
{
|
||||||
|
<p class="mb-0">Odkaz je neúplný. Otevřete ho prosím znovu z e-mailu, nebo si <a asp-action="ForgotPassword">pošlete nový</a>.</p>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<partial name="_FormErrors" />
|
||||||
|
<form method="post" asp-action="ResetPassword" novalidate>
|
||||||
|
<input type="hidden" asp-for="Token" />
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="NewPassword" class="form-label"></label>
|
||||||
|
<input asp-for="NewPassword" class="form-control" autocomplete="new-password" autofocus aria-describedby="passwordHelp" />
|
||||||
|
<div id="passwordHelp" class="form-text">8 až 64 znaků. Po změně budete odhlášeni na všech zařízeních.</div>
|
||||||
|
<span asp-validation-for="NewPassword" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-4">
|
||||||
|
<label asp-for="ConfirmPassword" class="form-label"></label>
|
||||||
|
<input asp-for="ConfirmPassword" class="form-control" autocomplete="new-password" />
|
||||||
|
<span asp-validation-for="ConfirmPassword" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary w-100">Nastavit heslo</button>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="app-auth-links">
|
||||||
|
<a asp-action="ForgotPassword">Poslat nový odkaz</a>
|
||||||
|
<a asp-action="Login">Přihlášení</a>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
@model int
|
||||||
|
@{
|
||||||
|
var (title, text) = Model switch
|
||||||
|
{
|
||||||
|
404 => ("Stránka nenalezena", "Stránka neexistuje, nebo byla přesunuta. Zkontrolujte adresu."),
|
||||||
|
403 => ("Přístup odepřen", "K této stránce nemáte oprávnění. Pokud si myslíte, že byste je mít měli, obraťte se na administrátora."),
|
||||||
|
429 => ("Příliš mnoho požadavků", "Během krátké doby jste odeslali příliš mnoho požadavků. Zkuste to prosím za minutu."),
|
||||||
|
503 => ("Služba je dočasně nedostupná", "Nepodařilo se spojit se serverem helpdesku. Zkuste to prosím za chvíli znovu."),
|
||||||
|
_ => ("Něco se pokazilo", "Požadavek se nepodařilo zpracovat. Zkuste to prosím za chvíli znovu."),
|
||||||
|
};
|
||||||
|
ViewData["Title"] = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-empty">
|
||||||
|
<p class="app-empty-code">@Model</p>
|
||||||
|
<h1 class="h3">@title</h1>
|
||||||
|
<p class="text-body-secondary">@text</p>
|
||||||
|
<a class="btn btn-primary" asp-controller="Home" asp-action="Index">Zpět na nástěnku</a>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Nástěnka";
|
||||||
|
var firstName = User.Identity?.Name?.Split(' ')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-page-head">
|
||||||
|
<h1>Dobrý den, @firstName</h1>
|
||||||
|
<p class="lead text-body-secondary">Nahlaste závadu v budově, na vybavení nebo ve službách a sledujte, jak se řeší. Podejte návrh na zlepšení univerzity a hlasujte pro návrhy ostatních.</p>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
@model ProfileViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Můj profil";
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="app-page-head">
|
||||||
|
<h1>Můj profil</h1>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div class="row g-4">
|
||||||
|
<div class="col-lg-7">
|
||||||
|
<div class="app-card">
|
||||||
|
<dl class="app-facts">
|
||||||
|
<dt>E-mail</dt>
|
||||||
|
<dd>@Model.Email</dd>
|
||||||
|
<dt>Role</dt>
|
||||||
|
<dd>@UserRoles.DisplayName(Model.Role)</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<partial name="_FormErrors" />
|
||||||
|
<form method="post" asp-action="Index" novalidate>
|
||||||
|
<div class="row g-3 mb-3">
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<label asp-for="FirstName" class="form-label"></label>
|
||||||
|
<input asp-for="FirstName" class="form-control" autocomplete="given-name" />
|
||||||
|
<span asp-validation-for="FirstName" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<label asp-for="LastName" class="form-label"></label>
|
||||||
|
<input asp-for="LastName" class="form-control" autocomplete="family-name" />
|
||||||
|
<span asp-validation-for="LastName" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Phone" class="form-label"></label>
|
||||||
|
<input asp-for="Phone" class="form-control" type="tel" autocomplete="tel" aria-describedby="phoneHelp" />
|
||||||
|
<div id="phoneHelp" class="form-text">Nepovinné. Na serveru se ukládá šifrovaně.</div>
|
||||||
|
<span asp-validation-for="Phone" class="invalid-feedback d-block"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-check mb-4">
|
||||||
|
<input asp-for="EmailNotificationsEnabled" class="form-check-input" />
|
||||||
|
<label asp-for="EmailNotificationsEnabled" class="form-check-label"></label>
|
||||||
|
<div class="form-text">Upozornění v aplikaci dostáváte vždy.</div>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Uložit změny</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-5">
|
||||||
|
<div class="app-card">
|
||||||
|
<h2 class="h6 fw-bold">Přihlášená zařízení</h2>
|
||||||
|
<p class="text-body-secondary">Odhlásí vás ve všech prohlížečích i v mobilní aplikaci. Hodí se, když jste se přihlásili na cizím počítači.</p>
|
||||||
|
<form method="post" asp-action="LogoutAll">
|
||||||
|
<button type="submit" class="btn btn-outline-danger">Odhlásit ze všech zařízení</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
@* Krátká zpráva po přesměrování (např. „Profil uložen“). Nastavuje se přes TempData.Success / TempData.Error. *@
|
||||||
|
@if (TempData[Flash.Success] is string success)
|
||||||
|
{
|
||||||
|
<div class="alert alert-success alert-dismissible fade show" role="status">
|
||||||
|
@success
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Zavřít"></button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if (TempData[Flash.Error] is string error)
|
||||||
|
{
|
||||||
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||||
|
@error
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Zavřít"></button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
@* Chyby, které nepatří ke konkrétnímu poli (např. „Neplatný e-mail nebo heslo.“). *@
|
||||||
|
@{
|
||||||
|
var errors = ViewData.ModelState.TryGetValue(string.Empty, out var entry) ? entry.Errors : null;
|
||||||
|
}
|
||||||
|
@if (errors is { Count: > 0 })
|
||||||
|
{
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
@if (errors.Count == 1)
|
||||||
|
{
|
||||||
|
@errors[0].ErrorMessage
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<ul class="mb-0 ps-3">
|
||||||
|
@foreach (var error in errors)
|
||||||
|
{
|
||||||
|
<li>@error.ErrorMessage</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="cs">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>@(ViewData["Title"] is string title ? $"{title} · NTBug" : "NTBug")</title>
|
||||||
|
<link rel="icon" href="~/favicon.svg" type="image/svg+xml" />
|
||||||
|
<link rel="stylesheet" href="~/lib/bootstrap/css/bootstrap.min.css" />
|
||||||
|
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a class="visually-hidden-focusable skip-link" href="#main">Přeskočit na obsah</a>
|
||||||
|
|
||||||
|
<header class="app-header border-bottom">
|
||||||
|
<nav class="navbar navbar-expand-lg container-xl" aria-label="Hlavní menu">
|
||||||
|
<a class="navbar-brand app-brand" asp-controller="Home" asp-action="Index">
|
||||||
|
<img class="app-brand-mark" src="~/favicon.svg" alt="" width="32" height="32" />
|
||||||
|
<span>NTBug <span class="app-brand-sub">helpdesk</span></span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
@if (User.Identity?.IsAuthenticated == true)
|
||||||
|
{
|
||||||
|
var controller = ViewContext.RouteData.Values["controller"] as string;
|
||||||
|
var action = ViewContext.RouteData.Values["action"] as string;
|
||||||
|
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainNav"
|
||||||
|
aria-controls="mainNav" aria-expanded="false" aria-label="Zobrazit menu">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="mainNav">
|
||||||
|
<ul class="navbar-nav me-auto">
|
||||||
|
@foreach (var item in Navigation.For(User))
|
||||||
|
{
|
||||||
|
var active = item.Controller == controller && item.Action == action;
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link @(active ? "active" : "")" aria-current="@(active ? "page" : null)"
|
||||||
|
asp-controller="@item.Controller" asp-action="@item.Action">@item.Text</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
@await Html.PartialAsync("_UserMenu")
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main id="main" class="container-xl app-main">
|
||||||
|
@await Html.PartialAsync("_Alerts")
|
||||||
|
@RenderBody()
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="app-footer container-xl">
|
||||||
|
Univerzitní helpdesk a portál návrhů na zlepšení · NNPRO
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="~/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||||
|
@await RenderSectionAsync("Scripts", required: false)
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
@model StatusBadgeModel
|
||||||
|
@* Použití: <partial name="_StatusBadge" model="new StatusBadgeModel(issue.Status)" /> *@
|
||||||
|
<span class="status-badge [email protected]()">@StatusLabels.For(Model.Status, Model.IsProposal)</span>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
@{
|
||||||
|
var role = User.FindFirst(ClaimTypes.Role)?.Value;
|
||||||
|
}
|
||||||
|
<div class="dropdown">
|
||||||
|
<button class="btn btn-link app-user-toggle dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
<span class="fw-semibold">@User.Identity?.Name</span>
|
||||||
|
<span class="badge app-role-badge ms-1">@UserRoles.DisplayName(role)</span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-end">
|
||||||
|
<li><span class="dropdown-item-text small text-body-secondary">@User.FindFirst(ClaimTypes.Email)?.Value</span></li>
|
||||||
|
<li><a class="dropdown-item" asp-controller="Profile" asp-action="Index">Můj profil</a></li>
|
||||||
|
<li><hr class="dropdown-divider" /></li>
|
||||||
|
<li>
|
||||||
|
<form method="post" asp-controller="Account" asp-action="Logout">
|
||||||
|
<button type="submit" class="dropdown-item">Odhlásit se</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
@using System.Security.Claims
|
||||||
|
@using Helpdesk.Web
|
||||||
|
@using Helpdesk.Web.Auth
|
||||||
|
@using Helpdesk.Web.Infrastructure
|
||||||
|
@using Helpdesk.Web.Models
|
||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
@{
|
||||||
|
Layout = "_Layout";
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning",
|
||||||
|
"System.Net.Http.HttpClient": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"Api": {
|
||||||
|
"BaseUrl": "http://localhost:8080/"
|
||||||
|
},
|
||||||
|
"DataProtection": {
|
||||||
|
"KeysPath": ""
|
||||||
|
},
|
||||||
|
"ReverseProxy": {
|
||||||
|
"TrustedIp": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
/* Vzhled NTBug nad Bootstrapem 5. Barvy, zaoblení a štítky stavů převzaté z tématu
|
||||||
|
mobilní aplikace (mobile/…/ui/Theme.kt a ui/features/Components.kt), aby web
|
||||||
|
i mobil vypadaly jako jedna aplikace. Při změně tématu upravte obě místa. */
|
||||||
|
:root {
|
||||||
|
/* Material 3 schéma z mobilu (světlé) */
|
||||||
|
--app-accent: #006b5c; /* primary */
|
||||||
|
--app-accent-hover: #00574b;
|
||||||
|
--app-accent-rgb: 0, 107, 92;
|
||||||
|
--app-accent-soft: #d4f5e9; /* primaryContainer */
|
||||||
|
--app-on-accent-soft: #00382e; /* onPrimaryContainer */
|
||||||
|
--app-ink: #142e38; /* onBackground, onSurface */
|
||||||
|
--app-muted: #53666f; /* onSurfaceVariant */
|
||||||
|
--app-surface: #f5f7f9; /* background */
|
||||||
|
--app-line: #d9e3e7; /* outlineVariant */
|
||||||
|
--app-radius-card: 1.25rem; /* karty v mobilu: 20 dp */
|
||||||
|
--app-radius-badge: .5rem; /* štítky stavů: 8 dp */
|
||||||
|
|
||||||
|
/* Barvy stavů závad a návrhů (StatusBadge v mobilu) */
|
||||||
|
--status-neutral: var(--app-muted); /* Přijata, Podán */
|
||||||
|
--status-assigned: #3267a0; /* Přiřazena */
|
||||||
|
--status-in-progress: #986015; /* V řešení */
|
||||||
|
--status-review: #7953a5; /* Čeká na ověření, V posouzení */
|
||||||
|
--status-done: #25725b; /* Vyřešena, Přijat, Realizován */
|
||||||
|
--status-rejected: #ac3e42; /* Zamítnuta / Zamítnut */
|
||||||
|
|
||||||
|
--bs-primary: var(--app-accent);
|
||||||
|
--bs-primary-rgb: var(--app-accent-rgb);
|
||||||
|
--bs-link-color: var(--app-accent);
|
||||||
|
--bs-link-color-rgb: var(--app-accent-rgb);
|
||||||
|
--bs-link-hover-color: var(--app-accent-hover);
|
||||||
|
--bs-link-hover-color-rgb: 0, 87, 75;
|
||||||
|
--bs-body-bg: var(--app-surface);
|
||||||
|
--bs-body-color: var(--app-ink);
|
||||||
|
--bs-emphasis-color: var(--app-ink);
|
||||||
|
--bs-secondary-color: var(--app-muted);
|
||||||
|
--bs-border-color: var(--app-line);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tlačítka jsou jako v Material 3 plně zaoblená. */
|
||||||
|
.btn { --bs-btn-border-radius: 999px; --bs-btn-padding-x: 1.1rem; --bs-btn-font-weight: 600; }
|
||||||
|
.btn-primary {
|
||||||
|
--bs-btn-bg: var(--app-accent);
|
||||||
|
--bs-btn-border-color: var(--app-accent);
|
||||||
|
--bs-btn-hover-bg: var(--app-accent-hover);
|
||||||
|
--bs-btn-hover-border-color: var(--app-accent-hover);
|
||||||
|
--bs-btn-active-bg: var(--app-accent-hover);
|
||||||
|
--bs-btn-active-border-color: var(--app-accent-hover);
|
||||||
|
--bs-btn-disabled-bg: var(--app-accent);
|
||||||
|
--bs-btn-disabled-border-color: var(--app-accent);
|
||||||
|
}
|
||||||
|
.btn-outline-primary {
|
||||||
|
--bs-btn-color: var(--app-accent);
|
||||||
|
--bs-btn-border-color: var(--app-accent);
|
||||||
|
--bs-btn-hover-bg: var(--app-accent);
|
||||||
|
--bs-btn-hover-border-color: var(--app-accent);
|
||||||
|
--bs-btn-active-bg: var(--app-accent-hover);
|
||||||
|
--bs-btn-active-border-color: var(--app-accent-hover);
|
||||||
|
}
|
||||||
|
/* Bootstrap bere pozadí polí z --bs-body-bg (šedé pozadí stránky); pole na kartách mají být bílá. */
|
||||||
|
.form-control, .form-select { background-color: #fff; }
|
||||||
|
.form-control:focus, .form-select:focus, .form-check-input:focus {
|
||||||
|
border-color: var(--app-accent);
|
||||||
|
box-shadow: 0 0 0 .2rem rgba(var(--app-accent-rgb), .2);
|
||||||
|
}
|
||||||
|
.form-check-input:checked { background-color: var(--app-accent); border-color: var(--app-accent); }
|
||||||
|
.form-label { font-weight: 600; }
|
||||||
|
|
||||||
|
body { min-height: 100vh; display: flex; flex-direction: column; }
|
||||||
|
|
||||||
|
.skip-link { position: absolute; left: 1rem; top: .5rem; z-index: 1100; background: #fff; padding: .5rem .75rem; border-radius: .375rem; }
|
||||||
|
|
||||||
|
/* hlavička – jako horní lišta v mobilu má barvu pozadí stránky */
|
||||||
|
.app-header { background: var(--app-surface); }
|
||||||
|
.app-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; color: inherit; }
|
||||||
|
.app-brand-mark { width: 2rem; height: 2rem; border-radius: .5rem; }
|
||||||
|
.app-brand-sub { font-weight: 400; color: var(--app-muted); }
|
||||||
|
.navbar .nav-link { font-weight: 500; }
|
||||||
|
.navbar .nav-link.active { color: var(--app-accent); font-weight: 700; }
|
||||||
|
.app-user-toggle { color: inherit; text-decoration: none; }
|
||||||
|
.app-role-badge { background: var(--app-accent-soft); color: var(--app-on-accent-soft); font-weight: 600; }
|
||||||
|
|
||||||
|
/* obsah */
|
||||||
|
.app-main { flex: 1; padding-block: 2rem 3rem; }
|
||||||
|
.app-page-head { margin-bottom: 1.5rem; }
|
||||||
|
.app-page-head h1 { font-size: 1.75rem; font-weight: 700; text-wrap: balance; }
|
||||||
|
.app-page-head .lead { max-width: 65ch; }
|
||||||
|
|
||||||
|
/* karta = OutlinedCard z mobilu */
|
||||||
|
.app-card { background: #fff; border: 1px solid var(--app-line); border-radius: var(--app-radius-card); padding: 1.5rem; }
|
||||||
|
|
||||||
|
.app-facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin-bottom: 1.5rem; }
|
||||||
|
.app-facts dt { font-weight: 600; color: var(--app-muted); }
|
||||||
|
.app-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
|
||||||
|
|
||||||
|
.alert { border-radius: 1rem; }
|
||||||
|
|
||||||
|
/* přihlášení, registrace a další jednoduché formuláře */
|
||||||
|
.app-auth { max-width: 26rem; margin: 1rem auto 0; }
|
||||||
|
.app-auth h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: .25rem; }
|
||||||
|
.app-auth .app-card { padding: 1.75rem; }
|
||||||
|
.input-validation-error { border-color: var(--bs-form-invalid-border-color); }
|
||||||
|
.app-auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; margin-top: 1rem; font-size: .925rem; }
|
||||||
|
|
||||||
|
/* prázdné a chybové stavy */
|
||||||
|
.app-empty { max-width: 32rem; margin: 3rem auto; text-align: center; }
|
||||||
|
.app-empty-code { font-size: 3rem; font-weight: 700; color: var(--app-accent); margin-bottom: 0; font-variant-numeric: tabular-nums; }
|
||||||
|
|
||||||
|
.app-footer { padding-block: 1.25rem; color: var(--app-muted); font-size: .875rem; border-top: 1px solid var(--app-line); }
|
||||||
|
|
||||||
|
/* Štítek stavu jako StatusBadge v mobilu: tečka a text v barvě stavu na pozadí s 11 % té barvy. */
|
||||||
|
.status-badge {
|
||||||
|
--status-color: var(--status-neutral);
|
||||||
|
display: inline-flex; align-items: center; gap: .4rem;
|
||||||
|
padding: .3rem .6rem; border-radius: var(--app-radius-badge);
|
||||||
|
font-size: .8rem; font-weight: 600; line-height: 1.2; white-space: nowrap;
|
||||||
|
color: var(--status-color);
|
||||||
|
background: color-mix(in srgb, var(--status-color) 11%, transparent);
|
||||||
|
}
|
||||||
|
.status-badge::before { content: ""; width: .35rem; height: .35rem; border-radius: 50%; background: currentColor; flex: none; }
|
||||||
|
.status-ASSIGNED { --status-color: var(--status-assigned); }
|
||||||
|
.status-IN_PROGRESS { --status-color: var(--status-in-progress); }
|
||||||
|
.status-PENDING_VERIFICATION, .status-UNDER_REVIEW { --status-color: var(--status-review); }
|
||||||
|
.status-RESOLVED, .status-ACCEPTED, .status-IMPLEMENTED { --status-color: var(--status-done); }
|
||||||
|
.status-REJECTED { --status-color: var(--status-rejected); }
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.fade, .collapsing { transition: none !important; }
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><!-- stejný tvar jako ikona mobilní aplikace (res/drawable/ic_ntbug.xml) --><rect width="48" height="48" rx="10" fill="#102c36"/><path fill="#57dfc5" d="M12,12h6l12,17v-17h6v24h-6l-12,-17v17h-6z"/></svg>
|
||||||
|
After Width: | Height: | Size: 266 B |
@@ -0,0 +1,22 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2011-2021 Twitter, Inc.
|
||||||
|
Copyright (c) 2011-2021 The Bootstrap Authors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
@charset "UTF-8";/*!
|
||||||
|
* Bootstrap v5.3.3 (https://getbootstrap.com/)
|
||||||
|
* Copyright 2011-2024 The Bootstrap Authors
|
||||||
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||||
|
*/:root,[data-bs-theme=light]{--bs-blue:#0d6efd;--bs-indigo:#6610f2;--bs-purple:#6f42c1;--bs-pink:#d63384;--bs-red:#dc3545;--bs-orange:#fd7e14;--bs-yellow:#ffc107;--bs-green:#198754;--bs-teal:#20c997;--bs-cyan:#0dcaf0;--bs-black:#000;--bs-white:#fff;--bs-gray:#6c757d;--bs-gray-dark:#343a40;--bs-gray-100:#f8f9fa;--bs-gray-200:#e9ecef;--bs-gray-300:#dee2e6;--bs-gray-400:#ced4da;--bs-gray-500:#adb5bd;--bs-gray-600:#6c757d;--bs-gray-700:#495057;--bs-gray-800:#343a40;--bs-gray-900:#212529;--bs-primary:#0d6efd;--bs-secondary:#6c757d;--bs-success:#198754;--bs-info:#0dcaf0;--bs-warning:#ffc107;--bs-danger:#dc3545;--bs-light:#f8f9fa;--bs-dark:#212529;--bs-primary-rgb:13,110,253;--bs-secondary-rgb:108,117,125;--bs-success-rgb:25,135,84;--bs-info-rgb:13,202,240;--bs-warning-rgb:255,193,7;--bs-danger-rgb:220,53,69;--bs-light-rgb:248,249,250;--bs-dark-rgb:33,37,41;--bs-primary-text-emphasis:#052c65;--bs-secondary-text-emphasis:#2b2f32;--bs-success-text-emphasis:#0a3622;--bs-info-text-emphasis:#055160;--bs-warning-text-emphasis:#664d03;--bs-danger-text-emphasis:#58151c;--bs-light-text-emphasis:#495057;--bs-dark-text-emphasis:#495057;--bs-primary-bg-subtle:#cfe2ff;--bs-secondary-bg-subtle:#e2e3e5;--bs-success-bg-subtle:#d1e7dd;--bs-info-bg-subtle:#cff4fc;--bs-warning-bg-subtle:#fff3cd;--bs-danger-bg-subtle:#f8d7da;--bs-light-bg-subtle:#fcfcfd;--bs-dark-bg-subtle:#ced4da;--bs-primary-border-subtle:#9ec5fe;--bs-secondary-border-subtle:#c4c8cb;--bs-success-border-subtle:#a3cfbb;--bs-info-border-subtle:#9eeaf9;--bs-warning-border-subtle:#ffe69c;--bs-danger-border-subtle:#f1aeb5;--bs-light-border-subtle:#e9ecef;--bs-dark-border-subtle:#adb5bd;--bs-white-rgb:255,255,255;--bs-black-rgb:0,0,0;--bs-font-sans-serif:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--bs-font-monospace:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--bs-gradient:linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));--bs-body-font-family:var(--bs-font-sans-serif);--bs-body-font-size:1rem;--bs-body-font-weight:400;--bs-body-line-height:1.5;--bs-body-color:#212529;--bs-body-color-rgb:33,37,41;--bs-body-bg:#fff;--bs-body-bg-rgb:255,255,255;--bs-emphasis-color:#000;--bs-emphasis-color-rgb:0,0,0;--bs-secondary-color:rgba(33, 37, 41, 0.75);--bs-secondary-color-rgb:33,37,41;--bs-secondary-bg:#e9ecef;--bs-secondary-bg-rgb:233,236,239;--bs-tertiary-color:rgba(33, 37, 41, 0.5);--bs-tertiary-color-rgb:33,37,41;--bs-tertiary-bg:#f8f9fa;--bs-tertiary-bg-rgb:248,249,250;--bs-heading-color:inherit;--bs-link-color:#0d6efd;--bs-link-color-rgb:13,110,253;--bs-link-decoration:underline;--bs-link-hover-color:#0a58ca;--bs-link-hover-color-rgb:10,88,202;--bs-code-color:#d63384;--bs-highlight-color:#212529;--bs-highlight-bg:#fff3cd;--bs-border-width:1px;--bs-border-style:solid;--bs-border-color:#dee2e6;--bs-border-color-translucent:rgba(0, 0, 0, 0.175);--bs-border-radius:0.375rem;--bs-border-radius-sm:0.25rem;--bs-border-radius-lg:0.5rem;--bs-border-radius-xl:1rem;--bs-border-radius-xxl:2rem;--bs-border-radius-2xl:var(--bs-border-radius-xxl);--bs-border-radius-pill:50rem;--bs-box-shadow:0 0.5rem 1rem rgba(0, 0, 0, 0.15);--bs-box-shadow-sm:0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);--bs-box-shadow-lg:0 1rem 3rem rgba(0, 0, 0, 0.175);--bs-box-shadow-inset:inset 0 1px 2px rgba(0, 0, 0, 0.075);--bs-focus-ring-width:0.25rem;--bs-focus-ring-opacity:0.25;--bs-focus-ring-color:rgba(13, 110, 253, 0.25);--bs-form-valid-color:#198754;--bs-form-valid-border-color:#198754;--bs-form-invalid-color:#dc3545;--bs-form-invalid-border-color:#dc3545}[data-bs-theme=dark]{color-scheme:dark;--bs-body-color:#dee2e6;--bs-body-color-rgb:222,226,230;--bs-body-bg:#212529;--bs-body-bg-rgb:33,37,41;--bs-emphasis-color:#fff;--bs-emphasis-color-rgb:255,255,255;--bs-secondary-color:rgba(222, 226, 230, 0.75);--bs-secondary-color-rgb:222,226,230;--bs-secondary-bg:#343a40;--bs-secondary-bg-rgb:52,58,64;--bs-tertiary-color:rgba(222, 226, 230, 0.5);--bs-tertiary-color-rgb:222,226,230;--bs-tertiary-bg:#2b3035;--bs-tertiary-bg-rgb:43,48,53;--bs-primary-text-emphasis:#6ea8fe;--bs-secondary-text-emphasis:#a7acb1;--bs-success-text-emphasis:#75b798;--bs-info-text-emphasis:#6edff6;--bs-warning-text-emphasis:#ffda6a;--bs-danger-text-emphasis:#ea868f;--bs-light-text-emphasis:#f8f9fa;--bs-dark-text-emphasis:#dee2e6;--bs-primary-bg-subtle:#031633;--bs-secondary-bg-subtle:#161719;--bs-success-bg-subtle:#051b11;--bs-info-bg-subtle:#032830;--bs-warning-bg-subtle:#332701;--bs-danger-bg-subtle:#2c0b0e;--bs-light-bg-subtle:#343a40;--bs-dark-bg-subtle:#1a1d20;--bs-primary-border-subtle:#084298;--bs-secondary-border-subtle:#41464b;--bs-success-border-subtle:#0f5132;--bs-info-border-subtle:#087990;--bs-warning-border-subtle:#997404;--bs-danger-border-subtle:#842029;--bs-light-border-subtle:#495057;--bs-dark-border-subtle:#343a40;--bs-heading-color:inherLine truncated
|
||||||
|
/*# sourceMappingURL=bootstrap.min.css.map */
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
/*!
|
||||||
|
* Bootstrap v5.3.3 (https://getbootstrap.com/)
|
||||||
|
* Copyright 2011-2024 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
||||||
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||||
|
*/
|
||||||
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).bootstrap=e()}(this,(function(){"use strict";const t=new Map,e={set(e,i,n){t.has(e)||t.set(e,new Map);const s=t.get(e);s.has(i)||0===s.size?s.set(i,n):console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(s.keys())[0]}.`)},get:(e,i)=>t.has(e)&&t.get(e).get(i)||null,remove(e,i){if(!t.has(e))return;const n=t.get(e);n.delete(i),0===n.size&&t.delete(e)}},i="transitionend",n=t=>(t&&window.CSS&&window.CSS.escape&&(t=t.replace(/#([^\s"#']+)/g,((t,e)=>`#${CSS.escape(e)}`))),t),s=t=>{t.dispatchEvent(new Event(i))},o=t=>!(!t||"object"!=typeof t)&&(void 0!==t.jquery&&(t=t[0]),void 0!==t.nodeType),r=t=>o(t)?t.jquery?t[0]:t:"string"==typeof t&&t.length>0?document.querySelector(n(t)):null,a=t=>{if(!o(t)||0===t.getClientRects().length)return!1;const e="visible"===getComputedStyle(t).getPropertyValue("visibility"),i=t.closest("details:not([open])");if(!i)return e;if(i!==t){const e=t.closest("summary");if(e&&e.parentNode!==i)return!1;if(null===e)return!1}return e},l=t=>!t||t.nodeType!==Node.ELEMENT_NODE||!!t.classList.contains("disabled")||(void 0!==t.disabled?t.disabled:t.hasAttribute("disabled")&&"false"!==t.getAttribute("disabled")),c=t=>{if(!document.documentElement.attachShadow)return null;if("function"==typeof t.getRootNode){const e=t.getRootNode();return e instanceof ShadowRoot?e:null}return t instanceof ShadowRoot?t:t.parentNode?c(t.parentNode):null},h=()=>{},d=t=>{t.offsetHeight},u=()=>window.jQuery&&!document.body.hasAttribute("data-bs-no-jquery")?window.jQuery:null,f=[],p=()=>"rtl"===document.documentElement.dir,m=t=>{var e;e=()=>{const e=u();if(e){const i=t.NAME,n=e.fn[i];e.fn[i]=t.jQueryInterface,e.fn[i].Constructor=t,e.fn[i].noConflict=()=>(e.fn[i]=n,t.jQueryInterface)}},"loading"===document.readyState?(f.length||document.addEventListener("DOMContentLoaded",(()=>{for(const t of f)t()})),f.push(e)):e()},g=(t,e=[],i=t)=>"function"==typeof t?t(...e):i,_=(t,e,n=!0)=>{if(!n)return void g(t);const o=(t=>{if(!t)return 0;let{transitionDuration:e,transitionDelay:i}=window.getComputedStyle(t);const n=Number.parseFloat(e),s=Number.parseFloat(i);return n||s?(e=e.split(",")[0],i=i.split(",")[0],1e3*(Number.parseFloat(e)+Number.parseFloat(i))):0})(e)+5;let r=!1;const a=({target:n})=>{n===e&&(r=!0,e.removeEventListener(i,a),g(t))};e.addEventListener(i,a),setTimeout((()=>{r||s(e)}),o)},b=(t,e,i,n)=>{const s=t.length;let o=t.indexOf(e);return-1===o?!i&&n?t[s-1]:t[0]:(o+=i?1:-1,n&&(o=(o+s)%s),t[Math.max(0,Math.min(o,s-1))])},v=/[^.]*(?=\..*)\.|.*/,y=/\..*/,w=/::\d+$/,A={};let E=1;const T={mouseenter:"mouseover",mouseleave:"mouseout"},C=new Set(["click","dblclick","mouseup","mousedown","contextmenu","mousewheel","DOMMouseScroll","mouseover","mouseout","mousemove","selectstart","selectend","keydown","keypress","keyup","orientationchange","touchstart","touchmove","touchend","touchcancel","pointerdown","pointermove","pointerup","pointerleave","pointercancel","gesturestart","gesturechange","gestureend","focus","blur","change","reset","select","submit","focusin","focusout","load","unload","beforeunload","resize","move","DOMContentLoaded","readystatechange","error","abort","scroll"]);function O(t,e){return e&&`${e}::${E++}`||t.uidEvent||E++}function x(t){const e=O(t);return t.uidEvent=e,A[e]=A[e]||{},A[e]}function k(t,e,i=null){return Object.values(t).find((t=>t.callable===e&&t.delegationSelector===i))}function L(t,e,i){const n="string"==typeof e,s=n?i:e||i;let o=I(t);return C.has(o)||(o=t),[n,s,o]}function S(t,e,i,n,s){if("string"!=typeof e||!t)return;let[o,r,a]=L(e,i,n);if(e in T){const t=t=>function(e){if(!e.relatedTarget||e.relatedTarget!==e.delegateTarget&&!e.delegateTarget.contains(e.relatedTarget))return t.call(this,e)};r=t(r)}const l=x(t),c=l[a]||(l[a]={}),h=k(c,r,o?i:null);if(h)return void(h.oneOff=h.oneOff&&s);const d=O(r,e.replace(v,"")),u=o?function(t,e,i){return function n(s){const o=t.querySelectorAll(e);for(let{target:r}=s;r&&r!==this;r=r.parentNode)for(const a of o)if(a===r)return P(s,{delegateTarget:r}),n.oneOff&&N.off(t,s.type,e,i),i.apply(r,[s])}}(t,i,r):function(t,e){return function i(n){return P(n,{delegateTarget:t}),i.oneOff&&N.off(t,n.type,e),e.apply(t,[n])}}(t,r);u.delegationSelector=o?i:null,u.callable=r,u.oneOff=s,u.uidEvent=d,c[d]=u,t.addEventListener(a,u,o)}function D(t,e,i,n,s){const o=k(e[i],n,s);o&&(t.removeEventListener(i,o,Boolean(s)),delete e[i][o.uidEvent])}function $(t,e,i,n){const s=e[i]||{};for(const[o,r]of Object.entries(s))o.includes(n)&&D(t,e,i,r.callable,r.delegationSelector)}function I(t){return t=t.replace(y,""),T[t]||t}const N={on(t,e,i,n){S(t,e,i,n,!1)},one(t,e,i,n){S(t,e,i,n,!0)},off(t,e,i,n){if("string"!=typeof e||!t)return;const[s,o,r]=L(e,i,n),a=r!==e,l=x(t),c=l[r]||{},h=e.startsWith(".");if(void 0===o){if(h)for(const i of Object.keys(l))$(t,l,i,e.slLine truncated
|
||||||
|
//# sourceMappingURL=bootstrap.bundle.min.js.map
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"test": {
|
||||||
|
"runner": "Microsoft.Testing.Platform"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user