From 68cb20c2d5f6f606bf434e7ede8ae60ab9bcc5e0 Mon Sep 17 00:00:00 2001
From: ChloeChen0423 広告募集
-
+
-
+
diff --git a/js/main.js b/js/main.js index b32c5d1..0e10a0f 100644 --- a/js/main.js +++ b/js/main.js @@ -1,13 +1,13 @@ $(function () { $.ajax({ - url: "http://192.168.1.192:8085/dogs/pet", + url: "http://localhost:8080/inuhouse", type: "GET", success: function (dogs) { const $slider = $('#sliderContainer'); const slideWidth = 270; const centerOffset = 1; - + preloadImages(dogs.map(d => d.image), () => { // $('#sliderContainer').html(dogs.map(createSlideHTML).join('')); const slidesHTML = generateCarouselHTML(dogs); @@ -24,10 +24,10 @@ $(function () { $('.right-btn').on('click', function () { if ($slider.is(':animated')) return; - + currentIndex++; animateTo(currentIndex); - + if (currentIndex === totalSlides - 1) { // animateTo(currentIndex); requestAnimationFrame(() => { @@ -37,16 +37,16 @@ $(function () { }); }); } - + }); - + $('.left-btn').on('click', function () { if ($slider.is(':animated')) return; - + currentIndex--; animateTo(currentIndex); - + if (currentIndex === 0) { @@ -58,12 +58,12 @@ $(function () { }); }); } - + }); - + }); - + $('#uploadBtn').on('click', function () { const fileInput = $('#fileInput')[0]; const file = fileInput.files[0]; @@ -99,12 +99,104 @@ $(function () { a.click(); document.body.removeChild(a); }); - - - - - + + $(function () { + + $('#goToLogin').on('click', function () { + $('#loginModal').fadeIn(); + }); + + // $('#goToRegister').on('click', function () { + // $('#registerModal').fadeIn(); + // }); + + + $('#closeLoginModal, #cancelLogin').on('click', function () { + $('#loginModal').fadeOut(); + }); + + // $('#closeRegisterModal, #cancelRegister').on('click', function () { + // $('#registerModal').fadeOut(); + // }); + + + // $('#submitRegister').on('click', function () { + // const username = $('#registerUsername').val().trim(); + // const email = $('#registerEmail').val().trim(); + // const password = $('#registerPassword').val().trim(); + // const confirmPassword = $('#registerConfirmPassword').val().trim(); + + // if (!email || !password || !confirmPassword) { + // alert('必須項目をすべて入力してください'); + // return; + // } + + // if (password !== confirmPassword) { + // alert('パスワードが一致しません'); + // return; + // } + + // const requestData = { + // username: username || null, + // email: email, + // password: password + // }; + + // $.ajax({ + // url: 'http://192.168.1.192:8085/api/user/register', + // type: 'POST', + // contentType: 'application/json', + // data: JSON.stringify(requestData), + // success: function () { + // alert('登録成功!'); + // window.location.href = 'index.html'; + // $('#registerModal').fadeOut(); + // }, + // error: function () { + // alert('登録に失敗しました: '); + // } + // }); + // }); + + $('#submitLogin').on('click', function () { + const email = $('#loginEmail').val().trim(); + const password = $('#loginPassword').val().trim(); + + if (!email || !password) { + alert('メールアドレスとパスワードを入力してください'); + return; + } + + const requestData = { + email: email, + password: password + }; + + $.ajax({ + url: 'http://192.168.1.192:8085/api/user/login', + type: 'POST', + contentType: 'application/json', + data: JSON.stringify(requestData), + success: function (response) { + const token = response.token; + localStorage.setItem('authToken', token); + alert('ログイン成功!'); + window.location.href = 'index.html'; + $('#loginModal').fadeOut(); + }, + error: function () { + alert('ログインに失敗しました'); + } + }); + }); + + + }); + + + + function preloadImages(urls, callback) { let loaded = 0; urls.forEach(src => { @@ -136,7 +228,7 @@ $(function () { } function generateCarouselHTML(dogList) { - + if (!dogList || dogList.length === 0) return ''; const redundantList = [ diff --git a/js/register.js b/js/register.js new file mode 100644 index 0000000..e2925ff --- /dev/null +++ b/js/register.js @@ -0,0 +1,38 @@ +$('#submitRegister').on('click', function () { + console.log('クリックされました') + + const username = $('#registerUsername').val().trim(); + const email = $('#registerEmail').val().trim(); + const password = $('#registerPassword').val().trim(); + const confirmPassword = $('#registerConfirmPassword').val().trim(); + + if (!email || !password || !confirmPassword) { + alert('必須項目をすべて入力してください'); + return; + } + + if (password !== confirmPassword) { + alert('パスワードが一致しません'); + return; + } + + const requestData = { + username: username || null, + email: email, + password: password + }; + + $.ajax({ + url: 'http://192.168.1.192:8085/api/user/register', + type: 'POST', + contentType: 'application/json', + data: JSON.stringify(requestData), + success: function () { + // alert('登録成功!'); + window.location.href = 'index.html'; + }, + error: function () { + alert('登録に失敗しました'); + } + }); +}); diff --git a/register.html b/register.html new file mode 100644 index 0000000..8f07cea --- /dev/null +++ b/register.html @@ -0,0 +1,112 @@ + + +
+ +
+ + + + +
+