From 107b7b1dfeeefbdb26a52e7e931db97baa26c1f2 Mon Sep 17 00:00:00 2001 From: yyechan0602 Date: Fri, 25 Aug 2023 16:24:35 +0900 Subject: [PATCH 1/3] add Register function --- hello.txt | 2 +- package-lock.json | 29 ++ package.json | 1 + src/views/authentication/auth/AuthRegister.js | 334 +++++++++++------- src/views/dashboard/components/Blog.js | 1 + 5 files changed, 241 insertions(+), 126 deletions(-) diff --git a/hello.txt b/hello.txt index 62e4000..8ad0355 100644 --- a/hello.txt +++ b/hello.txt @@ -1,2 +1,2 @@ ia -a22 \ No newline at end of file +a223 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8f87e17..ec3160d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@testing-library/react": "^13.3.0", "@testing-library/user-event": "^13.5.0", "apexcharts": "^3.23.1", + "axios": "^1.4.0", "chance": "^1.1.9", "lodash": "^4.17.21", "prop-types": "^15.7.2", @@ -5563,6 +5564,29 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/axobject-query": { "version": "3.2.1", "license": "Apache-2.0", @@ -14171,6 +14195,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/psl": { "version": "1.9.0", "license": "MIT" diff --git a/package.json b/package.json index 0bbdba4..f27b757 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@testing-library/react": "^13.3.0", "@testing-library/user-event": "^13.5.0", "apexcharts": "^3.23.1", + "axios": "^1.4.0", "chance": "^1.1.9", "lodash": "^4.17.21", "prop-types": "^15.7.2", diff --git a/src/views/authentication/auth/AuthRegister.js b/src/views/authentication/auth/AuthRegister.js index d9067a9..45d4d52 100644 --- a/src/views/authentication/auth/AuthRegister.js +++ b/src/views/authentication/auth/AuthRegister.js @@ -1,13 +1,20 @@ import React, {useState} from 'react'; -import { Box, Typography, Button } from '@mui/material'; -import { Link } from 'react-router-dom'; +import {Box, Typography, Button} from '@mui/material'; +import {Link} from 'react-router-dom'; import CustomTextField from '../../../components/forms/theme-elements/CustomTextField'; -import { Stack } from '@mui/system'; +import {Stack} from '@mui/system'; -const AuthRegister = ({ title, subtitle, subtext }) => { +const AuthRegister = ({title, subtitle, subtext}) => { const [selectedRole, setSelectedRole] = useState(''); const [selectedGender, setSelectedGender] = useState(''); + const [userId, setUserId] = useState(''); + const [name, setName] = useState(''); + const [team, setTeam] = useState(''); + const [birth, setBirth] = useState(''); + const [email, setEmail] = useState(''); + const [phone, setPhone] = useState(''); + const [address, setAddress] = useState(''); const handleRoleChange = (event) => { setSelectedRole(event.target.value); @@ -15,6 +22,34 @@ const AuthRegister = ({ title, subtitle, subtext }) => { const handleGenderChange = (event) => { setSelectedGender(event.target.value); }; + + const handleUserIdChange = (event) => { + setUserId(event.target.value); + }; + + const handleNameChange = (event) => { + setName(event.target.value); + }; + + const handleTeamChange = (event) => { + setTeam(event.target.value); + }; + const handleBirthChange = (event) => { + setBirth(event.target.value); + }; + + const handleEmailChange = (event) => { + setEmail(event.target.value); + }; + + const handlePhoneChange = (event) => { + setPhone(event.target.value); + }; + + const handleAddressChange = (event) => { + setAddress(event.target.value); + }; + const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [passwordsMatch, setPasswordsMatch] = useState(true); @@ -33,6 +68,38 @@ const AuthRegister = ({ title, subtitle, subtext }) => { if (passwordsMatch) { // 비밀번호와 비밀번호 재확인이 일치하므로 회원 가입 처리 가능 console.log('회원 가입 정보 전송'); + + // 회원 가입 API 호출 + const signupData = { + userid: userId, + password: password, + team: team, + name: name, + birth: birth, + gender: selectedGender, + email: email, + phone: phone, + address: address, + role: selectedRole, + }; + + fetch('http://localhost:8080/auth/signup', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(signupData), + mode: 'cors' + }) + .then(response => response.json()) + .then(data => { + console.log('회원 가입 성공', data); + // 회원 가입 성공 시 필요한 처리 수행 + }) + .catch(error => { + console.error('회원 가입 실패', error); + // 회원 가입 실패 시 필요한 처리 수행 + }); } else { // 비밀번호가 일치하지 않을 때의 처리 console.log('비밀번호가 일치하지 않습니다.'); @@ -41,129 +108,146 @@ const AuthRegister = ({ title, subtitle, subtext }) => { return ( <> - {title ? ( - - {title} - - ) : null} - - {subtext} - - - - 아이디 - - - 비밀번호 - - - 비밀번호 확인 - - - {!passwordsMatch && ( - - 비밀번호가 일치하지 않습니다. - - )} - - 소속 - - - 이름 - - - 생년월일 - - - 성별 -
- - - -
- - 이메일 - - - - 직무 -
- - - -
- - 휴대전화 - - - 주소 - - - 특이사항 - + {title ? ( + + {title} + + ) : null} + + {subtext} + + + + 아이디 + + + 비밀번호 + + + 비밀번호 + 확인 + + + {!passwordsMatch && ( + + 비밀번호가 일치하지 않습니다. + + )} + + 소속 + + + 이름 + + + 생년월일 + + + 성별 +
+ + + +
+ + 이메일 + + + + 직무 +
+ + + +
+ + 휴대전화 + + + 주소 +
- +
{subtitle} diff --git a/src/views/dashboard/components/Blog.js b/src/views/dashboard/components/Blog.js index 05bd1bb..4aa6110 100644 --- a/src/views/dashboard/components/Blog.js +++ b/src/views/dashboard/components/Blog.js @@ -1,4 +1,5 @@ import React from 'react'; +import React from 'react'; import { Link } from 'react-router-dom'; import { CardContent, Typography, Grid, Rating, Tooltip, Fab } from '@mui/material'; import img1 from 'src/assets/images/products/s4.jpg'; From 6f189a34da5e4c28ec25ba64ecd9bc25a533b595 Mon Sep 17 00:00:00 2001 From: yyechan0602 Date: Mon, 28 Aug 2023 14:15:04 +0900 Subject: [PATCH 2/3] fix register --- .idea/dataSources.xml | 12 ++++++++++++ src/views/authentication/auth/AuthRegister.js | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .idea/dataSources.xml diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..067a6f2 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mariadb + true + org.mariadb.jdbc.Driver + jdbc:mariadb://svc.sel3.cloudtype.app:31038/testUnity + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/src/views/authentication/auth/AuthRegister.js b/src/views/authentication/auth/AuthRegister.js index 45d4d52..89e45c4 100644 --- a/src/views/authentication/auth/AuthRegister.js +++ b/src/views/authentication/auth/AuthRegister.js @@ -93,16 +93,19 @@ const AuthRegister = ({title, subtitle, subtext}) => { }) .then(response => response.json()) .then(data => { + alert("회원 가입 성공"); console.log('회원 가입 성공', data); // 회원 가입 성공 시 필요한 처리 수행 }) .catch(error => { + alert("회원 가입 실패"); console.error('회원 가입 실패', error); // 회원 가입 실패 시 필요한 처리 수행 }); } else { - // 비밀번호가 일치하지 않을 때의 처리 + alert("비밀번호가 일치하지 않습니다."); console.log('비밀번호가 일치하지 않습니다.'); + // 비밀번호가 일치하지 않을 때의 처리 } }; From 6d3e4eb421c1a30a53cf954ff06dd3e8778667b8 Mon Sep 17 00:00:00 2001 From: yyechan0602 Date: Fri, 22 Sep 2023 20:24:47 +0900 Subject: [PATCH 3/3] fix attendcode --- .idea/dataSources.xml | 4 +- src/views/authentication/auth/AuthLogin.js | 35 ++++++++++--- src/views/icons/Icons.js | 58 ++++++++++++++++++---- 3 files changed, 80 insertions(+), 17 deletions(-) diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 067a6f2..c756a7d 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -1,11 +1,11 @@ - + mariadb true org.mariadb.jdbc.Driver - jdbc:mariadb://svc.sel3.cloudtype.app:31038/testUnity + jdbc:mariadb://svc.sel3.cloudtype.app:32707/testUnity $ProjectFileDir$ diff --git a/src/views/authentication/auth/AuthLogin.js b/src/views/authentication/auth/AuthLogin.js index a1a61b9..61ac530 100644 --- a/src/views/authentication/auth/AuthLogin.js +++ b/src/views/authentication/auth/AuthLogin.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, {useState} from 'react'; import { Box, Typography, @@ -8,11 +8,11 @@ import { Stack, Checkbox } from '@mui/material'; -import { Link, useNavigate } from 'react-router-dom'; +import {Link, useNavigate} from 'react-router-dom'; import CustomTextField from '../../../components/forms/theme-elements/CustomTextField'; -const AuthLogin = ({ title, subtitle, subtext }) => { +const AuthLogin = ({title, subtitle, subtext}) => { const [email, setEmail] = useState(''); // 변경된 부분 const [password, setPassword] = useState(''); const [rememberDevice, setRememberDevice] = useState(true); @@ -26,7 +26,7 @@ const AuthLogin = ({ title, subtitle, subtext }) => { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ email, password }), + body: JSON.stringify({email, password}), mode: 'cors' }); @@ -43,6 +43,27 @@ const AuthLogin = ({ title, subtitle, subtext }) => { }).catch(error => { console.error('JSON 파싱 오류:', error); }); + + // 추가한 API 호출 + const jwtToken = localStorage.getItem('token'); // 토큰을 로컬 스토리지에서 가져옴 + const attendResponse = await fetch('https://port-0-spring-eu1k2llldpju8v.sel3.cloudtype.app/attend/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${jwtToken}` // 토큰을 헤더에 추가 + }, + body: JSON.stringify({email, password}), + mode: 'cors' + }); + + if (attendResponse.ok) { + // Attend API 호출이 성공하면 원하는 작업을 수행하세요. + console.log('Attend API 호출 성공'); + } else { + console.error('Attend API 호출 실패'); + } + + } else { console.error('로그인 실패'); } @@ -64,7 +85,8 @@ const AuthLogin = ({ title, subtitle, subtext }) => { - {/* 변경된 부분 */} + {/* 변경된 부분 */} Email { setRememberDevice(!rememberDevice)} />} + control={ setRememberDevice(!rememberDevice)}/>} label="Remember this Device" /> diff --git a/src/views/icons/Icons.js b/src/views/icons/Icons.js index 4d17a09..2f83ad9 100644 --- a/src/views/icons/Icons.js +++ b/src/views/icons/Icons.js @@ -1,31 +1,69 @@ -import React from 'react'; +import React, { useRef, useState } from 'react'; import PageContainer from 'src/components/container/PageContainer'; import DashboardCard from '../../components/shared/DashboardCard'; -import { useRef,useState } from "react"; import './Icons.css'; const Icons = () => { - const [state, setState] = useState({ content: "" }); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + const [codeValue, setCodeValue] = useState(""); // 출석 코드를 저장할 상태 + const contentInput = useRef(); + const handleChangeState = (e) => { setState({ ...state, content: e.target.value }); }; + const handleSubmit = () => { - if (state.content.length < 1) { + const jwtToken = localStorage.getItem('token'); + if (state.content.length < 1 || codeValue.length < 1) { contentInput.current.focus(); return; } - console.log(state); - alert("출석 완료"); - setState({ - content: "", + + // 출석 코드를 codeValue에 저장 + setCodeValue(state.content); + + // POST 요청 보내기 + setLoading(true); + + fetch("https://port-0-spring-eu1k2llldpju8v.sel3.cloudtype.app/attend/attend", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${jwtToken}` + }, + body: JSON.stringify({ code: codeValue }), // codeValue 사용 + mode: 'cors' }) + .then(response => { + if (!response.ok) { + throw new Error("Network response was not ok"); + } + return response.json(); + }) + .then(data => { + console.log(data); + const code = data.code; + alert(`출석 완료. 코드: ${code}`); + }) + .catch(error => { + console.error("There was a problem with the fetch operation:", error); + setError(error); + }) + .finally(() => { + setLoading(false); + }); + + setState({ + content: "" + }); }; return ( @@ -39,10 +77,12 @@ const Icons = () => { placeholder="출석 번호를 입력하세요" /> + {loading &&

Loading...

} + {error &&

Error: {error.message}

} ); }; -export default Icons; \ No newline at end of file +export default Icons;