Добавьте файлы проекта.
This commit is contained in:
24
PlaylistShared.PWA2123/Pages/AuthCallback.razor
Normal file
24
PlaylistShared.PWA2123/Pages/AuthCallback.razor
Normal file
@@ -0,0 +1,24 @@
|
||||
@page "/auth-callback"
|
||||
@using PlaylistShared.PWA.Services
|
||||
@inject NavigationManager Navigation
|
||||
@inject AuthStateProvider AuthProvider
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
@code {
|
||||
[Parameter] public string? Token { get; set; }
|
||||
[Parameter] public string? RefreshToken { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Token) && !string.IsNullOrEmpty(RefreshToken))
|
||||
{
|
||||
await AuthProvider.MarkUserAsAuthenticated(Token, RefreshToken);
|
||||
Navigation.NavigateTo("/");
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Ошибка аутентификации через Яндекс", Severity.Error);
|
||||
Navigation.NavigateTo("/login");
|
||||
}
|
||||
}
|
||||
}
|
||||
7
PlaylistShared.PWA2123/Pages/Authentication.razor
Normal file
7
PlaylistShared.PWA2123/Pages/Authentication.razor
Normal file
@@ -0,0 +1,7 @@
|
||||
@page "/authentication/{action}"
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
<RemoteAuthenticatorView Action="@Action" />
|
||||
|
||||
@code{
|
||||
[Parameter] public string? Action { get; set; }
|
||||
}
|
||||
18
PlaylistShared.PWA2123/Pages/Counter.razor
Normal file
18
PlaylistShared.PWA2123/Pages/Counter.razor
Normal file
@@ -0,0 +1,18 @@
|
||||
@page "/counter"
|
||||
|
||||
<PageTitle>Counter</PageTitle>
|
||||
|
||||
<MudText Typo="Typo.h3" GutterBottom="true">Counter</MudText>
|
||||
|
||||
<MudText Class="mb-4">Current count: @currentCount</MudText>
|
||||
|
||||
<MudButton Color="Color.Primary" Variant="Variant.Filled" @onclick="IncrementCount">Click me</MudButton>
|
||||
|
||||
@code {
|
||||
private int currentCount = 0;
|
||||
|
||||
private void IncrementCount()
|
||||
{
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
18
PlaylistShared.PWA2123/Pages/Home.razor
Normal file
18
PlaylistShared.PWA2123/Pages/Home.razor
Normal file
@@ -0,0 +1,18 @@
|
||||
@page "/"
|
||||
|
||||
<PageTitle>Home</PageTitle>
|
||||
|
||||
<MudText Typo="Typo.h3" GutterBottom="true">Hello, world!</MudText>
|
||||
<MudText Class="mb-8">Welcome to your new app, powered by MudBlazor and the .NET 10 Template!</MudText>
|
||||
|
||||
<MudAlert Severity="Severity.Warning" Variant="Variant.Outlined" Dense="true" Class="mb-6">
|
||||
Before authentication will function correctly, you must configure your provider details in <code>Program.cs</code>.
|
||||
</MudAlert>
|
||||
|
||||
|
||||
<MudAlert Severity="Severity.Normal" ContentAlignment="HorizontalAlignment.Start">
|
||||
You can find documentation and examples on our website here:
|
||||
<MudLink Href="https://mudblazor.com" Target="_blank" Typo="Typo.body2" Color="Color.Primary">
|
||||
<b>www.mudblazor.com</b>
|
||||
</MudLink>
|
||||
</MudAlert>
|
||||
52
PlaylistShared.PWA2123/Pages/Login.razor
Normal file
52
PlaylistShared.PWA2123/Pages/Login.razor
Normal file
@@ -0,0 +1,52 @@
|
||||
@page "/login"
|
||||
@using PlaylistShared.PWA.Services
|
||||
@inject NavigationManager Navigation
|
||||
@inject AuthStateProvider AuthProvider
|
||||
@inject ApiClient ApiClient
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.Small" Class="mt-16">
|
||||
<MudCard>
|
||||
<MudCardContent Class="text-center">
|
||||
<MudText Typo="Typo.h5" Class="mb-4">Вход в PlaylistShared</MudText>
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="LoginWithYandex" StartIcon="@Icons.Custom.Brands.Yandex" FullWidth="true">
|
||||
Войти через Яндекс
|
||||
</MudButton>
|
||||
|
||||
<MudDivider Class="my-4">или</MudDivider>
|
||||
|
||||
<MudTextField Label="Логин" @bind-Value="_username" Variant="Variant.Outlined" FullWidth="true" />
|
||||
<MudTextField Label="Пароль" @bind-Value="_password" InputType="InputType.Password" Variant="Variant.Outlined" FullWidth="true" />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Secondary" OnClick="LoginWithPassword" FullWidth="true">Войти по паролю</MudButton>
|
||||
|
||||
<MudText Class="mt-4">
|
||||
Нет аккаунта? <MudLink Href="/register">Зарегистрироваться</MudLink>
|
||||
</MudText>
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
private string _username = "";
|
||||
private string _password = "";
|
||||
|
||||
private void LoginWithYandex()
|
||||
{
|
||||
Navigation.NavigateTo("https://localhost:5001/api/externalauth/login-yandex", true);
|
||||
}
|
||||
|
||||
private async Task LoginWithPassword()
|
||||
{
|
||||
var result = await ApiClient.LoginAsync(_username, _password);
|
||||
if (result != null)
|
||||
{
|
||||
await AuthProvider.MarkUserAsAuthenticated(result.Token, result.RefreshToken);
|
||||
Navigation.NavigateTo("/");
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Неверный логин или пароль", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
PlaylistShared.PWA2123/Pages/LoginDisplay.razor
Normal file
11
PlaylistShared.PWA2123/Pages/LoginDisplay.razor
Normal file
@@ -0,0 +1,11 @@
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<MudText Typo="Typo.body2" Class="d-inline mr-2">Hello, @context.User.Identity?.Name!</MudText>
|
||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="() => Navigation.NavigateTo("/logout")">Log out</MudButton>
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<MudLink Href="/login" Color="Color.Inherit" Underline="Underline.Hover" Typo="Typo.body2">Log in</MudLink>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
12
PlaylistShared.PWA2123/Pages/Logout.razor
Normal file
12
PlaylistShared.PWA2123/Pages/Logout.razor
Normal file
@@ -0,0 +1,12 @@
|
||||
@page "/logout"
|
||||
@using PlaylistShared.PWA.Services
|
||||
@inject AuthStateProvider AuthProvider
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
@code {
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await AuthProvider.MarkUserAsLoggedOut();
|
||||
Navigation.NavigateTo("/");
|
||||
}
|
||||
}
|
||||
9
PlaylistShared.PWA2123/Pages/NotFound.razor
Normal file
9
PlaylistShared.PWA2123/Pages/NotFound.razor
Normal file
@@ -0,0 +1,9 @@
|
||||
@page "/not-found"
|
||||
@layout MainLayout
|
||||
|
||||
<PageTitle>Not Found</PageTitle>
|
||||
|
||||
<MudText Typo="Typo.h3" GutterBottom="true">404 - Page Not Found</MudText>
|
||||
<MudText Class="mb-8">Sorry, the content you are looking for does not exist.</MudText>
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Href="/">Go to Home</MudButton>
|
||||
52
PlaylistShared.PWA2123/Pages/Weather.razor
Normal file
52
PlaylistShared.PWA2123/Pages/Weather.razor
Normal file
@@ -0,0 +1,52 @@
|
||||
@page "/weather"
|
||||
@inject HttpClient Http
|
||||
|
||||
<PageTitle>Weather</PageTitle>
|
||||
|
||||
<MudText Typo="Typo.h3" GutterBottom="true">Weather forecast</MudText>
|
||||
<MudText Typo="Typo.body1" Class="mb-8">This component demonstrates fetching data from the server.</MudText>
|
||||
|
||||
@if (forecasts == null)
|
||||
{
|
||||
<MudProgressCircular Color="Color.Default" Indeterminate="true" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="forecasts" Hover="true" SortLabel="Sort By" Elevation="0" AllowUnsorted="false">
|
||||
<HeaderContent>
|
||||
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<WeatherForecast, object>(x => x.Date)">Date</MudTableSortLabel></MudTh>
|
||||
<MudTh><MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.TemperatureC)">Temp. (C)</MudTableSortLabel></MudTh>
|
||||
<MudTh><MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.TemperatureF)">Temp. (F)</MudTableSortLabel></MudTh>
|
||||
<MudTh><MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.Summary!)">Summary</MudTableSortLabel></MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Date">@context.Date</MudTd>
|
||||
<MudTd DataLabel="Temp. (C)">@context.TemperatureC</MudTd>
|
||||
<MudTd DataLabel="Temp. (F)">@context.TemperatureF</MudTd>
|
||||
<MudTd DataLabel="Summary">@context.Summary</MudTd>
|
||||
</RowTemplate>
|
||||
<PagerContent>
|
||||
<MudTablePager PageSizeOptions="new int[] { 50, 100 }" />
|
||||
</PagerContent>
|
||||
</MudTable>
|
||||
}
|
||||
|
||||
@code {
|
||||
private WeatherForecast[]? forecasts;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
|
||||
}
|
||||
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public string? Summary { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user