Commit 65c7735b authored by seoyeon's avatar seoyeon
Browse files

0804

parent 3a6135b9
...@@ -14078,9 +14078,9 @@ ...@@ -14078,9 +14078,9 @@
"integrity": "sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==" "integrity": "sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA=="
}, },
"tar": { "tar": {
"version": "6.1.0", "version": "6.1.5",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.5.tgz",
"integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", "integrity": "sha512-FiK6MQyyaqd5vHuUjbg/NpO8BuEGeSXcmlH7Pt/JkugWS8s0w8nKybWjHDJiwzCAIKZ66uof4ghm4tBADjcqRA==",
"requires": { "requires": {
"chownr": "^2.0.0", "chownr": "^2.0.0",
"fs-minipass": "^2.0.0", "fs-minipass": "^2.0.0",
......
import { User } from "../models/index.js"; import { User } from '../models/index.js'
import jwt from "jsonwebtoken"; import jwt from 'jsonwebtoken'
import config from "../config/app.config.js"; import config from '../config/app.config.js'
import isLength from "validator/lib/isLength.js"; import isLength from 'validator/lib/isLength.js'
import multer from "multer"; import multer from 'multer'
const uploadimg = multer({ dest: "uploads/" }); const uploadimg = multer({ dest: 'uploads/' })
const imgUpload = uploadimg.fields([{ name: "img", maxCount: 1 }]); const imgUpload = uploadimg.fields([{ name: 'img', maxCount: 1 }])
const update = async (req, res) => { const update = async (req, res) => {
try { try {
console.log("id:", req.body.id); console.log('id:', req.body.id)
const id = req.body.id; const id = req.body.id
const avatar = req.files["img"][0]; const avatar = req.files['img'][0]
const img = avatar.filename; const img = avatar.filename
console.log(img); console.log(img)
await User.update({ img: img }, { where: { id: id } }); await User.update({ img: img }, { where: { id: id } })
res.json(img); res.json(img)
} catch (error) { } catch (error) {
console.log(error); console.log(error)
res.status(500).send("이미지 업데이트 실패"); res.status(500).send('이미지 업데이트 실패')
} }
}; }
const getUser = async (req, res) => { const getUser = async (req, res) => {
const user = await User.findOne({ where: { id: req.params.id } }); const user = await User.findOne({ where: { id: req.params.id } })
res.json(user) res.json(user)
}; }
const updateinfo = async (req, res) => { const updateinfo = async (req, res) => {
console.log(req.body); console.log(req.body)
const { id, name, email, phone, img } = req.body; const { id, name, email, phone, img } = req.body
console.log("id:", id); console.log('id:', id)
const A = { const A = {
name: name, name: name,
email: email, email: email,
phone: phone, phone: phone,
img: img, img: img,
}; }
await User.update(A, { where: { id: id } }); await User.update(A, { where: { id: id } })
const user = await User.findOne({ where: { id: id } }); const user = await User.findOne({ where: { id: id } })
console.log('user:', user) console.log('user:', user)
}; }
const login = async (req, res) => { const login = async (req, res) => {
try { try {
const { email, password } = req.body const { email, password } = req.body
const user = await User.findOne({ where: { email: email } }) const user = await User.findOne({ where: { email: email } })
if (!user) { if (!user) {
return res.status(422).send(`${email} 사용자가 존재하지 않습니다.`); return res.status(422).send(`${email} 사용자가 존재하지 않습니다.`)
} else { } else {
const passworMatch = await user.comparePassword(password); const passworMatch = await user.comparePassword(password)
if (passworMatch) { if (passworMatch) {
const token = jwt.sign({ userID: user.id }, config.jwtSecret, { const token = jwt.sign({ userID: user.id }, config.jwtSecret, {
expiresIn: config.jwtExpires, expiresIn: config.jwtExpires,
}); })
res.cookie(config.cookieName, token, { res.cookie(config.cookieName, token, {
path: "/", path: '/',
httpOnly: true, httpOnly: true,
secure: true, secure: true,
}); })
res.json(user); res.json(user)
} else { } else {
res.status(401).send("비밀번호가 일치하지 않습니다."); res.status(401).send('비밀번호가 일치하지 않습니다.')
} }
} }
} catch (error) { } catch (error) {
return res.status(500).send('로그인 중 에러') return res.status(500).send('로그인 중 에러')
} }
}; }
const signup = async (req, res) => { const signup = async (req, res) => {
console.log('sign up= ', req.body) console.log('sign up= ', req.body)
const { name, email, password, phone } = req.body const { name, email, password, phone } = req.body
const id = Math.floor(Math.random() * (9999 - 1000) + 1000) const id = Math.floor(Math.random() * (9999 - 1000) + 1000)
...@@ -77,20 +76,20 @@ const signup = async (req, res) => { ...@@ -77,20 +76,20 @@ const signup = async (req, res) => {
const Id = await User.findOne({ where: { id: id } }) const Id = await User.findOne({ where: { id: id } })
// console.log('Id 중복확인:', Id) // console.log('Id 중복확인:', Id)
while (Id) { while (Id) {
const id = Math.floor(Math.random() * (9999 - 1000) + 1000); const id = Math.floor(Math.random() * (9999 - 1000) + 1000)
const Id = await User.findOne({ where: { id: id } }); const Id = await User.findOne({ where: { id: id } })
} }
try { try {
const user = await User.findOne({ where: { email: email } }); const user = await User.findOne({ where: { email: email } })
if (user) { if (user) {
return res.status(422).send(`${email} 이미 존재하는 사용자입니다.`); return res.status(422).send(`${email} 이미 존재하는 사용자입니다.`)
} else { } else {
if (!isLength(name, { min: 2, max: 10 })) { if (!isLength(name, { min: 2, max: 10 })) {
return res.status(422).send("이름은 2-10자 사이입니다"); return res.status(422).send('이름은 2-10자 사이입니다')
} else if (!isLength(password, { min: 6 })) {
return res.status(422).send("비밀번호는 6자이상 입니다");
} else if (!isLength(email, { min: 3, max: 10 })) { } else if (!isLength(email, { min: 3, max: 10 })) {
return res.status(422).send("아이디는 3-10자 사이입니다"); return res.status(422).send('아이디는 3-10자 사이입니다')
} else if (!isLength(password, { min: 6 })) {
return res.status(422).send('비밀번호는 6자이상 입니다')
} }
const newUser = { const newUser = {
id: id, id: id,
...@@ -99,20 +98,20 @@ const signup = async (req, res) => { ...@@ -99,20 +98,20 @@ const signup = async (req, res) => {
password: password, password: password,
phone: phone, phone: phone,
} }
console.log('newUser:',newUser) console.log('newUser:', newUser)
await User.create(newUser) await User.create(newUser)
res.json(true) res.json(true)
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error)
return res.status(500).send("회원가입 중 에러"); return res.status(500).send('회원가입 중 에러')
} }
}; }
const logout = (req, res) => { const logout = (req, res) => {
res.clearCookie("token"); res.clearCookie('token')
res.send("Logout Successful"); res.send('Logout Successful')
}; }
export default { export default {
getUser, getUser,
...@@ -122,4 +121,4 @@ export default { ...@@ -122,4 +121,4 @@ export default {
imgUpload, imgUpload,
update, update,
updateinfo, updateinfo,
}; }
...@@ -16,7 +16,7 @@ const RoomModel = (sequelize) => { ...@@ -16,7 +16,7 @@ const RoomModel = (sequelize) => {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
}, },
member: { member: {
type: DataTypes.ARRAY(DataTypes.INTEGER), type: DataTypes.ARRAY(DataTypes.STRING),
//type: DataTypes.STRING, //type: DataTypes.STRING,
}, },
profileimg: { profileimg: {
......
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