forked from AcaMate/AcaMate_Web
1. 쿠키만 사용하던 저장 동작을 다른 저장소도 사용하게 변경 1.1. 쿠키 대신 세션 레포지토리를 기본적으로 사용하게 Service 코드 구현 2. 로그인 되었을 경우 화면 표기 변경 2.1. 시작하기 버튼 hidden 처리 2.2. 사용자 이름 불러오기 2.3. 로그인 동작 관련 변수 스토리지 저장 2.4. 서버에서 직접적인 크라이언트 쿠키 저장이 아닌 서버는 뒤의 값으로 간섭하게 변경
97 lines
3.0 KiB
JavaScript
97 lines
3.0 KiB
JavaScript
window.postWithHeader = function(url, method, headerKey, headerValue) {
|
|
fetch(url, {
|
|
method: method,
|
|
headers: {
|
|
[headerKey] : headerValue
|
|
}
|
|
}).then(res => {
|
|
if (res.redirected) {
|
|
window.location.href = res.url;
|
|
}
|
|
});
|
|
};
|
|
|
|
window.fetchWithHeaderAndReturnUrl = async function(url, method, headerKey, headerValue) {
|
|
try {
|
|
const response = await fetch(url, {
|
|
method: method,
|
|
headers: {
|
|
[headerKey]: headerValue
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
console.error('API 호출 실패:', response.status, response.statusText);
|
|
return null;
|
|
}
|
|
|
|
const data = await response.json();
|
|
console.log('API 응답 데이터:', data);
|
|
return data;
|
|
} catch (error) {
|
|
console.error('API 호출 중 오류 발생:', error);
|
|
return null;
|
|
}
|
|
};
|
|
|
|
window.loadConfig = async function(configFile) {
|
|
try {
|
|
console.log('설정 파일 로드 시도:', configFile);
|
|
const response = await fetch(configFile);
|
|
if (!response.ok) {
|
|
console.error('설정 파일 로드 실패:', response.status, response.statusText);
|
|
return null;
|
|
}
|
|
const config = await response.json();
|
|
console.log('설정 파일 로드 성공:', configFile);
|
|
return config;
|
|
} catch (error) {
|
|
console.error('설정 파일 로드 중 오류 발생:', error);
|
|
return null;
|
|
}
|
|
};
|
|
|
|
window.encryptText = async function(text, key, iv) {
|
|
try {
|
|
// XOR 암호화 구현
|
|
let result = '';
|
|
for (let i = 0; i < text.length; i++) {
|
|
const charCode = text.charCodeAt(i) ^ key.charCodeAt(i % key.length);
|
|
result += String.fromCharCode(charCode);
|
|
}
|
|
|
|
// UTF-8로 인코딩 후 Base64로 변환
|
|
const utf8Encoder = new TextEncoder();
|
|
const bytes = utf8Encoder.encode(result);
|
|
const base64 = btoa(String.fromCharCode.apply(null, bytes));
|
|
return base64;
|
|
} catch (error) {
|
|
console.error('암호화 중 오류 발생:', error);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
window.decryptText = async function(encryptedText, key, iv) {
|
|
try {
|
|
// Base64 디코딩 후 UTF-8 디코딩
|
|
const binary = atob(encryptedText);
|
|
const bytes = new Uint8Array(binary.length);
|
|
for (let i = 0; i < binary.length; i++) {
|
|
bytes[i] = binary.charCodeAt(i);
|
|
}
|
|
const utf8Decoder = new TextDecoder();
|
|
const text = utf8Decoder.decode(bytes);
|
|
|
|
// XOR 복호화
|
|
let result = '';
|
|
for (let i = 0; i < text.length; i++) {
|
|
const charCode = text.charCodeAt(i) ^ key.charCodeAt(i % key.length);
|
|
result += String.fromCharCode(charCode);
|
|
}
|
|
return result;
|
|
} catch (error) {
|
|
console.error('복호화 중 오류 발생:', error);
|
|
throw error;
|
|
}
|
|
};
|