Commit 55693856 authored by 한규민's avatar 한규민
Browse files

마이페이지

parent 87029678
import axios from "axios"; import axios from "axios";
import { baseUrl } from "../utils/baseUrl.js"; import { baseUrl } from "../utils/baseUrl.js";
import config from "../utils/clientConfig.js";
const getUser = async () => { const getUser = async () => {
const url = `${baseUrl}/api/auth/user` const url = `${baseUrl}/api/auth/user`
...@@ -38,8 +37,13 @@ const confirmMbnum = async (id, token) => { ...@@ -38,8 +37,13 @@ const confirmMbnum = async (id, token) => {
return data return data
} }
const getNickName = async (id) => { const profile = async (formData) => {
const url = `${baseUrl}/api/auth/nickname/${id}` const url = `${baseUrl}/api/auth/profile`
const { data } = await axios.post(url, formData)
return data
}
const getMember = async (id) => {
const url = `${baseUrl}/api/auth/member`
const { data } = await axios.get(url) const { data } = await axios.get(url)
return data return data
} }
...@@ -62,7 +66,8 @@ const authApi = { ...@@ -62,7 +66,8 @@ const authApi = {
signup, signup,
compareId, compareId,
confirmMbnum, confirmMbnum,
getNickName, profile,
getMember,
comparePw, comparePw,
modifyUser, modifyUser,
}; };
......
This diff is collapsed.
...@@ -28,13 +28,45 @@ width: 40%; ...@@ -28,13 +28,45 @@ width: 40%;
padding-right: 8px; padding-right: 8px;
text-align: left; text-align: left;
} }
.input_file_button{
padding: 6px 25px;
background-color:#FF6600;
border-radius: 4px;
color: white;
cursor: pointer;
}
.inputContent{ .inputContent{
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;
align-items: center; align-items: center;
margin: 1rem 0; margin: 1rem 0;
} }
.box{
width:12rem;
margin: 0px auto;
position: relative;
}
.box:hover{
display: block;
}
.hoverTxt{
display: none;
position:absolute;
top:5rem;
left:2.5rem;
color : #FEDC00;
font-size: 1.5rem;
}
.box:hover .hoverTxt{
display: block;
}
.profile{
width: 12rem;
height: 12rem;
}
.profile:hover{
opacity: 0.5;
}
.input { .input {
margin: 0.5rem 0 0 0; margin: 0.5rem 0 0 0;
padding: 0.5rem 0 0.5rem 0; padding: 0.5rem 0 0.5rem 0;
......
import styles from "./reservation-details.module.scss";
const ReservationDetails = () => {
return(
<div className={`${styles.width}`}>
<header className={`${styles.header}`}>나의 예매 내역</header>
<main>
</main>
</div>
)
}
export default ReservationDetails
\ No newline at end of file
export { default } from "./ReservationDetails"
\ No newline at end of file
.width{
width : 100%;
display: flex;
margin-top: 5rem;
justify-content: center;
}
.header{
display: flex;
justify-content: center;
background-color: #FEDC00;
width: 80%;
text-align: center;
font-size: 2.5rem;
}
\ No newline at end of file
import MyInfo from "../components/MyInfo/MyInfo" import MyInfo from "../components/MyInfo/MyInfo"
import ReservationDetails from "../components/ReservationDetails";
const MyPage = () => { const MyPage = () => {
return ( return (
<div className="d-flex justify-content-center py-4"> <div className="d-flex flex-column justify-content-center align-items-center py-4">
<MyInfo/> <MyInfo/>
<ReservationDetails/>
</div> </div>
) )
} }
......
...@@ -666,6 +666,11 @@ ...@@ -666,6 +666,11 @@
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
}, },
"fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
},
"fsevents": { "fsevents": {
"version": "2.3.2", "version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
......
...@@ -7,7 +7,7 @@ const app = express() ...@@ -7,7 +7,7 @@ const app = express()
app.use(express.json()) app.use(express.json())
app.use(express.urlencoded({ extended: true })) app.use(express.urlencoded({ extended: true }))
app.use(cookieParser()) app.use(cookieParser())
app.use('/upload', express.static('upload'))
app.use('/api', mainRouter) app.use('/api', mainRouter)
......
import jwt from "jsonwebtoken"; import jwt from "jsonwebtoken";
import config from "../config/app.config.js"; import config from "../config/app.config.js";
import { User, Role } from '../db/index.js'; import { User, Role } from '../db/index.js';
import fs from "fs";
const getUser = async (req, res) => { const getUser = async (req, res) => {
try { try {
if (req.cookies) { if (req.cookies.butterStudio) {
const token = req.cookies.butterStudio; const token = req.cookies.butterStudio;
const decoded = jwt.verify(token, config.jwtSecret); const decoded = jwt.verify(token, config.jwtSecret);
res.json(decoded); res.json(decoded);
...@@ -109,38 +110,44 @@ const confirmMbnum = async (req, res) => { ...@@ -109,38 +110,44 @@ const confirmMbnum = async (req, res) => {
} }
const signup = async (req, res) => { const signup = async (req, res) => {
const { userId, userEmail, userNickName, userBirthday, userPassword } = req.body; const { userId, userEmail, userNickName, userBirthday, userMbnum, userPassword } = req.body;
// 휴대폰 중복 확인 // 휴대폰 중복 확인
const userMbnum = String(req.body.userMbnum);
try { try {
const mbnum = await User.findOne({ where: { phoneNumber: userMbnum } }); const mbnum = await User.findOne({ where: { phoneNumber: userMbnum } });
if (mbnum) { const email = await User.findOne({ where: { email: userEmail } });
if (mbnum && email) {
return res.status(422).send(`이미 있는 이메일, 휴대폰번호입니다.`);
} else if (!mbnum && email) {
return res.status(422).send(`이미 있는 이메일입니다.`);
} else if (mbnum && !email) {
return res.status(422).send(`이미 있는 휴대폰번호입니다.`); return res.status(422).send(`이미 있는 휴대폰번호입니다.`);
} else {
const role = await Role.findOne({ where: { name: "member" } })
const newUser = await User.create({
userId: userId,
email: userEmail,
nickname: userNickName,
birth: userBirthday,
phoneNumber: userMbnum,
password: userPassword,
roleId: role.id
});
res.json(newUser);
} }
const role = await Role.findOne({ where: { name: "member" } })
const newUser = await User.create({
userId: userId,
email: userEmail,
nickname: userNickName,
birth: userBirthday,
phoneNumber: userMbnum,
password: userPassword,
roleId: role.id
});
res.json(newUser);
} catch (error) { } catch (error) {
console.error(error.message); console.error(error.message);
res.status(500).send("회원가입 에러. 나중에 다시 시도 해주세요"); res.status(500).send("회원가입 에러. 나중에 다시 시도 해주세요");
} }
}; };
const getNickName = async (req, res) => { const getMember = async (req, res) => {
try { try {
const token = req.cookies.butterStudio; const token = req.cookies.butterStudio;
const decoded = jwt.verify(token, config.jwtSecret); const decoded = jwt.verify(token, config.jwtSecret);
if (decoded.role === "member") { if (decoded.role === "member") {
const user = await User.findOne({ where: { id: decoded.id }, attributes: ["nickname"] }); const user = await User.findOne({ where: { id: decoded.id } });
res.json(user.nickname); res.json({nickname : user.nickname, img : user.img});
} else { } else {
res.status(401).send("잘못된 접근입니다."); res.status(401).send("잘못된 접근입니다.");
} }
...@@ -150,6 +157,34 @@ const getNickName = async (req, res) => { ...@@ -150,6 +157,34 @@ const getNickName = async (req, res) => {
} }
} }
const uploadProfile = async (req, res) => {
try {
const image = req.file.filename;
console.log(req.file);
const token = req.cookies.butterStudio;
const decoded = jwt.verify(token, config.jwtSecret);
if (decoded) {
const img = await User.findOne({ where: { id:decoded.id }, attributes : ["img"]});
console.log("여기여기");
fs.unlink( "upload"+`\\${img.img}`, function(data){ console.log(data);});
const user = await User.update({
img: image
}, { where: { id: decoded.id } });
if(user){
const success = await User.findOne({ where: { id: decoded.id }, attributes: ["img"]});
res.json(success)
}else{
throw new Error("프로필 등록 실패")
}
}
} catch (error) {
console.error(error.message);
res.status(500).send("프로필 에러");
}
}
const comparePw = async (req, res) => { const comparePw = async (req, res) => {
try { try {
//쿠키 안 토큰에서 id추출 //쿠키 안 토큰에서 id추출
...@@ -171,26 +206,50 @@ const comparePw = async (req, res) => { ...@@ -171,26 +206,50 @@ const comparePw = async (req, res) => {
} }
} }
const overlap = async (decoded, dataType, data) => {
try {
let overlap = await User.findOne({ where: { id: decoded.id } });
console.log("overlap : ", overlap, "overlap[dataType] : ", overlap[dataType]);
if (overlap[dataType] === data) {
console.log("여기여기")
return true
} else {
overlap = await User.findOne({ where: { id: decoded.id }, attributes: [dataType] });
if (overlap) {
return false
} else {
return true
}
}
}catch(error){
console.error(error.message);
}
}
const modifyUser = async (req, res) => { const modifyUser = async (req, res) => {
try { try {
const token = req.cookies.butterStudio; const token = req.cookies.butterStudio;
const decoded = jwt.verify(token, config.jwtSecret); const decoded = jwt.verify(token, config.jwtSecret);
const { userEmail, userNickName, userMbnum, userPassword } = req.body; const { userEmail, userNickName, userMbnum, userPassword } = req.body;
const emailOverlap = await User.findOne({ where: { email: userEmail } }); const overlapEmail = await overlap(decoded, "email", userEmail);
const overlapMbnum = await overlap(decoded, "phoneNumber", userMbnum);
if (emailOverlap) { console.log("overlapEmail", overlapEmail, " overlapMbnum : ", overlapMbnum);
return res.status(422).send(`이미 있는 이메일입니다.`);
if (overlapEmail && overlapMbnum) {
const user = await User.update({
email: userEmail,
nickname: userNickName,
phoneNumber: userMbnum,
password: userPassword,
}, { where: { id: decoded.id } });
console.log("user22 :", user);
res.json(user);
} else if (!overlapEmail && overlapMbnum) {
res.status(500).send("이미 있는 이메일입니다.");
} else if (overlapEmail && !overlapMbnum) {
res.status(500).send("이미 있는 이메일입니다.");
} else { } else {
if (decoded) { res.status(500).send("이미 있는 이메일, 핸드폰번호입니다.");
let user = await User.findOne({ where: { id: decoded.id } });
await user.update({
email : userEmail,
nickname : userNickName,
phoneNumber : userMbnum,
password : userPassword,
});
res.json(user);
}
} }
} catch (error) { } catch (error) {
console.error(error.message); console.error(error.message);
...@@ -205,7 +264,8 @@ export default { ...@@ -205,7 +264,8 @@ export default {
compareId, compareId,
confirmMbnum, confirmMbnum,
signup, signup,
getNickName, getMember,
uploadProfile,
comparePw, comparePw,
modifyUser modifyUser
} }
...@@ -19,7 +19,6 @@ sequelize ...@@ -19,7 +19,6 @@ sequelize
); );
const adminRole = await Role.findOne({ where: { name: "admin" } }); const adminRole = await Role.findOne({ where: { name: "admin" } });
console.log("adminRole : ", adminRole);
if (!adminRole) { if (!adminRole) {
await User.create({ await User.create({
userId: "admin", userId: "admin",
......
...@@ -14,23 +14,26 @@ const UserModel = (sequelize) => { ...@@ -14,23 +14,26 @@ const UserModel = (sequelize) => {
autoIncrement: true, autoIncrement: true,
}, },
userId: { userId: {
type: DataTypes.STRING, type: DataTypes.STRING
}, },
email: { email: {
type: DataTypes.STRING, type: DataTypes.STRING
}, },
nickname: { nickname: {
type: DataTypes.STRING, type: DataTypes.STRING
}, },
birth: { birth: {
type: DataTypes.STRING, type: DataTypes.STRING
}, },
phoneNumber: { phoneNumber: {
type: DataTypes.STRING type: DataTypes.STRING
}, },
password: { password: {
type: DataTypes.STRING, type: DataTypes.STRING
}, },
img: {
type: DataTypes.STRING
}
}, },
{ {
timestamps: true, timestamps: true,
......
import express from "express"; import express from "express";
import userCtrl from "../controllers/user.controller.js"; import userCtrl from "../controllers/user.controller.js";
import multer from "multer"
const router = express.Router(); const router = express.Router();
const upload = multer({
dest: "upload/"
})
router router
.route("/user") .route("/user")
...@@ -19,14 +23,16 @@ router ...@@ -19,14 +23,16 @@ router
.route("/signup") .route("/signup")
.post(userCtrl.signup) .post(userCtrl.signup)
router
.post("/profile", upload.single("image"), userCtrl.uploadProfile)
router router
.route("/modify") .route("/modify")
.post(userCtrl.modifyUser) .post(userCtrl.modifyUser)
router router
.route("/nickname/:id") .route("/member")
.get(userCtrl.getNickName) .get(userCtrl.getMember)
router router
.route("/pw/:pw") .route("/pw/:pw")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment