diff --git a/src/front/src/App.jsx b/src/front/src/App.jsx index aa9c926..4bc9394 100644 --- a/src/front/src/App.jsx +++ b/src/front/src/App.jsx @@ -8,6 +8,7 @@ import Test from "./routes/Test"; import ChatBox from "./components/ChatBox"; import MyPage from "./routes/Mypage"; import UserPage from "./routes/UserPage"; +import PasswordFind from "./routes/PasswordFind"; @@ -24,6 +25,10 @@ const router = createBrowserRouter([ path: "/signup", element: }, + { + path: "/findPassword", + element: + }, { path: "/chat", element: diff --git a/src/front/src/routes/PasswordFind.jsx b/src/front/src/routes/PasswordFind.jsx index 0f64837..1be37f0 100644 --- a/src/front/src/routes/PasswordFind.jsx +++ b/src/front/src/routes/PasswordFind.jsx @@ -1,4 +1,4 @@ -import { useContext } from "react"; +import { useState, useContext, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import { GlobalContext } from ".."; import { Link } from "react-router-dom"; @@ -12,14 +12,65 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select" +import { changePassword, fetchPasswordQuestions } from "@/utils/API"; +import { getPasswordQuestionItems } from "@/utils/Items"; +import { correctRegxEmail, correctRegxPwd } from "@/utils/common"; +import { changePasswordReqParam } from "@/utils/Parameter"; +import { Label } from "@radix-ui/react-label"; const PasswordFind = () => { //라우팅 네비게이터 const nevigate = useNavigate(); + + //비밀번호 찾기 질문 Items + const [passwordQuestions, setPasswordQuestions] = useState([]); + //Email 주소 + const [email, setEmail] = useState(""); + //선택한 비밀번호 찾기 질문 + const [selectQuestion, setSelectQuestion] = useState(null); + //입력한 비밀번호 찾기 질문 응답 + const [passwordQuestionAnswer, setPasswordQuestionAnswer] = useState(""); + //새로운 비밀번호 + const [newPassword, setNewPassword] = useState(""); + + useEffect(() =>{ + fetchPasswordQuestions() + .then(resultQuestions =>{ + setPasswordQuestions(getPasswordQuestionItems(resultQuestions)); + }) + },[]); - const mainpage = () =>{ - setLogin(true); - nevigate("/login"); + const findPassword = () =>{ + if(!correctRegxEmail(email)){ + alert("이메일을 확인해주세요"); + return ; + } + + if(selectQuestion === null){ + alert("비밀번호 찾기 질문을 선택해주세요"); + return ; + } + + if(passwordQuestionAnswer === ""){ + alert("비밀번호 찾기 응답을 입력해주세요"); + return ; + } + + if(!correctRegxPwd(newPassword)){ + alert("비밀번호 형식이 올바르지 않습니다."); + return ; + } + + const reqParam = changePasswordReqParam(email, selectQuestion, passwordQuestionAnswer, newPassword); + + changePassword(reqParam) + .then((response) => { + alert(response + "\n 다시 로그인해주세요!"); + nevigate("/"); + }) + .catch((err) =>{ + alert("비밀번호 변경에 실패했습니다."); + }); } @@ -27,31 +78,32 @@ const PasswordFind = () => {

1INKED 1N

-

비밀번호 찾기

+

비밀번호 변경

- + setEmail(ev.target.value)} type="email" placeholder="Email Address"> - setSelectQuestion(val)}> - 내가 태어난 초등학교는 - 내 어릴적 별명은? - 내 첫사랑 이름은? + { + passwordQuestions + } - + setPasswordQuestionAnswer(ev.target.value)} type="input" placeholder="your answer"> + + + setNewPassword(ev.target.value)} type="password" placeholder="enter new password"> {/* 버튼은 onClick 콜백 동작 불가 */} - +
); diff --git a/src/front/src/routes/Signup.jsx b/src/front/src/routes/Signup.jsx index 57c0df1..368f978 100644 --- a/src/front/src/routes/Signup.jsx +++ b/src/front/src/routes/Signup.jsx @@ -1,4 +1,4 @@ -import { useContext, useState } from "react"; +import { useContext, useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { GlobalContext } from ".."; import { Link } from "react-router-dom"; @@ -7,8 +7,9 @@ import { Input } from "@/components/ui/input"; import { Select, SelectTrigger, SelectValue, SelectContent, SelectGroup } from "@/components/ui/select"; import LabelSection from "@/components/Layout/LabelSection"; import { correctRegxEmail, correctRegxPwd } from "@/utils/common"; -import { signup } from "@/utils/API"; +import { fetchPasswordQuestions, signup } from "@/utils/API"; import { signupReqParam } from "@/utils/Parameter"; +import { getPasswordQuestionItems } from "@/utils/Items"; const Signup = () =>{ //라우팅 네비게이터 @@ -23,6 +24,13 @@ const Signup = () =>{ const [pwdConfirm, setPwdConfirm] = useState(""); const [pwdQAnswer, setPwdQAnswer] = useState(""); + useEffect(() =>{ + fetchPasswordQuestions() + .then(resultQuestions =>{ + setPasswordQuestions(getPasswordQuestionItems(resultQuestions)); + }) + },[]); + //메서드 const doSignup = () =>{ if(!username){ @@ -57,8 +65,6 @@ const Signup = () =>{ const reqParam = signupReqParam(username, email, pwd, pwdQId, pwdQAnswer); - console.log(reqParam); - // signup API 호출 signup(reqParam) @@ -100,7 +106,7 @@ const Signup = () =>{ { - passwordQuestions.map(passwordQuestion => {passwordQuestion.passwordQuestion}) + passwordQuestions } diff --git a/src/front/src/routes/Test.jsx b/src/front/src/routes/Test.jsx index a978773..8e06be3 100644 --- a/src/front/src/routes/Test.jsx +++ b/src/front/src/routes/Test.jsx @@ -1,6 +1,7 @@ import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card"; import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; import { GenerateLiElUUID } from "@/utils/common"; import { Link } from "react-router-dom"; import ArticleDialog from "@/components/ArticleDialog"; @@ -17,9 +18,14 @@ import ChatBox from "@/components/ChatBox"; import FollowInfo from "@/components/FollowInfo"; import MyResumes from "@/components/MyResumes"; import UserPage from "./UserPage"; +import { fetchUserProfile, saveProfile, withdraw } from "@/utils/API"; +import { saveProfileReqParam, withdrawReqParam } from "@/utils/Parameter"; const Test = () => { + const email = "dlxogml11235@naver.com"; + const [file, setFile] = useState(null); + const resource = { btnText: "생성", clickCallback: () =>{ @@ -29,8 +35,35 @@ const Test = () => { initFn: () => {} } + const userProfileDemo = () =>{ + + fetchUserProfile(email) + .then((data) => {console.log(data)}); + } + + const userWithdraw = (bool) =>{ + const reqParam = withdrawReqParam("dlxogml11235@naver.com", "Dlxogml!135", bool); + + withdraw(reqParam) + .then(data => console.log(data)); + } + + const saveUserProfile = () =>{ + const reqParam = saveProfileReqParam(email, "123","서울","ㄷㅈ매럊믇ㄹ",file); + + saveProfile(reqParam) + .then(response => console.log(response)); + } + return ( - +
+ + + + + setFile(ev.target.files[0])}> + +
); }; diff --git a/src/front/src/utils/Items.jsx b/src/front/src/utils/Items.jsx new file mode 100644 index 0000000..e41d41e --- /dev/null +++ b/src/front/src/utils/Items.jsx @@ -0,0 +1,11 @@ +import { SelectItem } from "@/components/ui/select" + +/** + * + * @param {{id: String, question: String}[]} questions + * @returns + */ +export const getPasswordQuestionItems = (questions) =>{ + const questionSelectItems = questions.map(item => ({item.question})); + return questionSelectItems; +} \ No newline at end of file diff --git a/src/front/src/utils/Parameter.js b/src/front/src/utils/Parameter.js index f9f73c2..6a5c96b 100644 --- a/src/front/src/utils/Parameter.js +++ b/src/front/src/utils/Parameter.js @@ -18,8 +18,9 @@ export const signupReqParam = (realName, email, password, passwordQuestionId, pa return reqParam; } -export const changePasswordReqParam = () =>{ - const reqParam = {} +export const changePasswordReqParam = (email, passwordQuestionId, passwordQuestionAnswer, newPassword) =>{ + const reqParam = {}; + reqParam.email = email; reqParam.passwordQuestionId = passwordQuestionId; reqParam.passwordQuestionAnswer = passwordQuestionAnswer; @@ -46,7 +47,7 @@ export const saveProfileReqParam = (email, identity, location, description, file reqFormData.append('description', description); reqFormData.append('file', file); - return reqParam; + return reqFormData; } /** diff --git a/src/main/java/com/example/oneinkedoneproject/dto/SignupUserRequestDto.java b/src/main/java/com/example/oneinkedoneproject/dto/SignupUserRequestDto.java index 40ccdd4..4c92b41 100644 --- a/src/main/java/com/example/oneinkedoneproject/dto/SignupUserRequestDto.java +++ b/src/main/java/com/example/oneinkedoneproject/dto/SignupUserRequestDto.java @@ -19,13 +19,14 @@ public class SignupUserRequestDto { private String passwordQuestionId; private String passwordQuestionAnswer; - public User toEntity(PasswordQuestion pwdQuestion, String endcodePassword){ + public User toEntity(PasswordQuestion pwdQuestion, String encodePassword){ return User.builder() .id(GenerateIdUtils.generateUserId()) .realname(realName) .email(email) - .password(endcodePassword) + .password(encodePassword) .passwordQuestion(pwdQuestion) + .passwordAnswer(passwordQuestionAnswer) .grade(Grade.ROLE_BASIC) .withdraw(false) .build(); diff --git a/src/main/java/com/example/oneinkedoneproject/dto/WithdrawUserRequestDto.java b/src/main/java/com/example/oneinkedoneproject/dto/WithdrawUserRequestDto.java index ad616be..a55ec3b 100644 --- a/src/main/java/com/example/oneinkedoneproject/dto/WithdrawUserRequestDto.java +++ b/src/main/java/com/example/oneinkedoneproject/dto/WithdrawUserRequestDto.java @@ -8,5 +8,9 @@ public class WithdrawUserRequestDto { private String email; private String password; - private Boolean isWithdraw; + private boolean isWithdraw; + + public boolean getIsWithdraw(){ + return this.isWithdraw; + } }