添加项目文件。
This commit is contained in:
62
TechHelper.Client/Pages/Manage/Class.razor.cs
Normal file
62
TechHelper.Client/Pages/Manage/Class.razor.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Entities.DTO;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using MudBlazor;
|
||||
using System.Collections.Frozen;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TechHelper.Client.HttpRepository;
|
||||
using TechHelper.Client.Services;
|
||||
|
||||
namespace TechHelper.Client.Pages.Manage
|
||||
{
|
||||
public partial class Class
|
||||
{
|
||||
private UserRegistrationToClassDto _userRegistrationToClassDto = new UserRegistrationToClassDto();
|
||||
private string? username;
|
||||
private string? phoneNumber;
|
||||
|
||||
[Inject]
|
||||
public ISnackbar Snackbar { get; set; }
|
||||
[Inject]
|
||||
public IAuthenticationClientService Authentication { get; set; }
|
||||
[Inject]
|
||||
public IClassServices ClassServices { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState> authenticationStateTask { get; set; }
|
||||
|
||||
[SupplyParameterFromForm]
|
||||
private InputModel Input { get; set; } = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
username = authenticationStateTask.Result.User.Identity.Name;
|
||||
phoneNumber = authenticationStateTask.Result.User.Identity.IsAuthenticated.ToString();
|
||||
|
||||
Input.PhoneNumber ??= phoneNumber;
|
||||
}
|
||||
|
||||
private async Task Register()
|
||||
{
|
||||
_userRegistrationToClassDto.User = authenticationStateTask.Result.User.Identity.Name?? "";
|
||||
var result = await ClassServices.UserRegister(_userRegistrationToClassDto);
|
||||
if (result.IsSuccessfulRegistration)
|
||||
{
|
||||
var token = await Authentication.RefreshTokenAsync();
|
||||
Snackbar.Add("<22>༶ע<E0BCB6><D7A2><EFBFBD>ɹ<EFBFBD>", Severity.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add(result.Errors.First(), Severity.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private sealed class InputModel
|
||||
{
|
||||
[Phone]
|
||||
[Display(Name = "Phone number")]
|
||||
public string? PhoneNumber { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user