1. /am/... 도메인 생성 2. /am/intro 페이지 생성 3. 메인 레이아웃 상황 따라 변경 4. 로그인 정보 받아오는 로직 변경 중 4.1. 유저 정보에 대한 JSON은 받아왔으나 이를 저장하는 로직 구현 중 4.2. 로그인 정보를 받아오는 로직을 어디서 구현해야 할 지 고민 하는 중
169 lines
6.9 KiB
C#
169 lines
6.9 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using System;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using Front.Program.Services;
|
|
|
|
namespace Front.Program.Views.Project;
|
|
|
|
public partial class TopProjectNav : ComponentBase
|
|
{
|
|
[Inject] NavigationManager NavigationManager { get; set; } = default!;
|
|
[Inject] UserService UserService { get; set; } = default!;
|
|
|
|
[Inject] IJSRuntime JS { get; set; } = default!;
|
|
|
|
[Inject] HttpClient Http { get; set; } = default!;
|
|
string UserName { get; set; } = default!;
|
|
|
|
protected bool isOpen = false;
|
|
bool isLogin = false;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var (success, userData) = await UserService.GetUserData();
|
|
if (success && userData != null)
|
|
{
|
|
Console.WriteLine(userData.Name);
|
|
UserName = userData.Name;
|
|
isLogin = true;
|
|
}
|
|
// isLogin = bool.TryParse(await StorageService.GetItemAsync("IsLogin"), out var result) && result;
|
|
// // if (!isLogin && !string.IsNullOrEmpty(UserName)) return;
|
|
// if (!isLogin) return; // && !string.IsNullOrEmpty(UserName)) return;
|
|
|
|
// try
|
|
// {
|
|
// var encryptedName = await StorageService.GetItemAsync("USER");
|
|
// Console.WriteLine($"{encryptedName}");
|
|
// if (!string.IsNullOrEmpty(encryptedName))
|
|
// {
|
|
// try
|
|
// {
|
|
// UserName = await SecureService.DecryptAsync(encryptedName);
|
|
// Console.WriteLine($"세션 스토리지에서 가져온 사용자 이름: '{UserName}'");
|
|
|
|
// return;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Console.WriteLine($"이름 복호화 중 오류 발생: {ex.Message}");
|
|
// await StorageService.RemoveItemAsync("USER");
|
|
// }
|
|
// }
|
|
|
|
// // apiSender.js의 함수를 사용하여 연결 키 가져오기
|
|
// var headerValue = await StorageService.GetItemAsync("Web_AM_Connect_Key");
|
|
// Console.WriteLine($"세션 스토리지에서 가져온 헤더 값: '{headerValue}'");
|
|
|
|
// if (string.IsNullOrEmpty(headerValue))
|
|
// {
|
|
// Console.WriteLine("연결 키가 없습니다");
|
|
// return;
|
|
// }
|
|
|
|
// // apiSender.js의 함수를 사용하여 API 호출
|
|
// Console.WriteLine("세션 API 호출 시작");
|
|
// var response = await JS.InvokeAsync<JsonElement>("fetchWithHeaderAndReturnUrl",
|
|
// "/api/v1/in/user/auth/session",
|
|
// "GET",
|
|
// "Web_AM_Connect_Key",
|
|
// headerValue);
|
|
|
|
// Console.WriteLine($"세션 API 응답 타입: {response.ValueKind}");
|
|
// Console.WriteLine($"세션 API 응답 내용: {response}");
|
|
|
|
// if (response.ValueKind == JsonValueKind.Null || response.ValueKind == JsonValueKind.Undefined)
|
|
// {
|
|
// Console.WriteLine("응답이 null이거나 undefined입니다");
|
|
// return;
|
|
// }
|
|
|
|
// try
|
|
// {
|
|
// if (response.TryGetProperty("status", out var statusElement))
|
|
// {
|
|
// Console.WriteLine($"status 요소 타입: {statusElement.ValueKind}");
|
|
// if (statusElement.TryGetProperty("code", out var codeElement))
|
|
// {
|
|
// var code = codeElement.GetString();
|
|
// Console.WriteLine($"응답 코드: {code}");
|
|
|
|
// if (code == "000")
|
|
// {
|
|
// if (response.TryGetProperty("data", out var dataElement))
|
|
// {
|
|
// Console.WriteLine($"data 요소 타입: {dataElement.ValueKind}");
|
|
|
|
// // 전체 data를 JSON 문자열로 변환
|
|
// var userDataJson = dataElement.ToString();
|
|
|
|
// // 전체 데이터 암호화
|
|
// var encryptedUserData = await SecureService.EncryptAsync(userDataJson);
|
|
// await StorageService.SetItemAsync("USER_DATA", encryptedUserData);
|
|
|
|
// // 기존 name 처리 로직
|
|
// if (dataElement.TryGetProperty("name", out var nameElement))
|
|
// {
|
|
// UserName = nameElement.GetString() ?? "이름 없음";
|
|
// isLogin = true;
|
|
// Console.WriteLine($"NM: {UserName}");
|
|
// var encryptedUserName = await SecureService.EncryptAsync(UserName);
|
|
// Console.WriteLine($"NM: {encryptedUserName}");
|
|
// await StorageService.SetItemAsync("USER", encryptedUserName);
|
|
// await StorageService.SetItemAsync("Web_AM_Connect_Key", headerValue);
|
|
// Console.WriteLine($"로그인된 사용자: {UserName}");
|
|
// return;
|
|
// }
|
|
// }
|
|
// }
|
|
// else {
|
|
// if (isLogin) {
|
|
// isLogin = false;
|
|
// await StorageService.SetItemAsync("IsLogin","false");
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// Console.WriteLine("로그인되지 않은 상태");
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Console.WriteLine($"응답 처리 중 오류 발생: {ex.Message}");
|
|
// Console.WriteLine($"응답 처리 스택 트레이스: {ex.StackTrace}");
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Console.WriteLine($"세션 확인 중 오류 발생: {ex.Message}");
|
|
// Console.WriteLine($"스택 트레이스: {ex.StackTrace}");
|
|
// }
|
|
}
|
|
|
|
public void OnClickMenuDown()
|
|
{
|
|
isOpen = !isOpen;
|
|
}
|
|
|
|
public void OnClickRedirect()
|
|
{
|
|
if (isOpen) isOpen = !isOpen;
|
|
NavigationManager.NavigateTo("/about");
|
|
}
|
|
|
|
public void OnClickLogin()
|
|
{
|
|
if (isOpen) isOpen = !isOpen;
|
|
NavigationManager.NavigateTo("/auth");
|
|
}
|
|
|
|
public async Task OnClickLogout()
|
|
{
|
|
if (await UserService.ClearUserData())
|
|
{
|
|
isLogin = false;
|
|
UserName = null;
|
|
}
|
|
}
|
|
} |