Commit 4cdee925 authored by 우지원's avatar 우지원
Browse files

Merge remote-tracking branch 'origin/room-api' into jiweon827

parents 776bd873 aa59e0a7
PG_DATABASE=boraIt
PG_USER=postgres
PG_PASSWORD=postgres
\ No newline at end of file
node_modules/
package-lock.json
config/
env.development
\ No newline at end of file
// express 설정 파일
import express from "express";
import fs from "fs";
import cookieParser from "cookie-parser";
import mainRouter from "./routes/index.js";
// fs.readdir('uploads', (error) => {
// if (error) {
// fs.mkdirSync('uploads');
// }
// })
const app = express();
app.use(express.json());
// app.use('/uploads', express.static('uploads'))
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use("/api", mainRouter);
export default app;
......@@ -14,6 +14,7 @@
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"socket.io-client": "^4.1.2",
"web-vitals": "^1.0.1"
},
"scripts": {
......
......@@ -15,7 +15,7 @@ function App() {
<Route exact path="/user" component={HomeUserPage} />
<Route path="/profile/:id/update" component={InfoUpdatePage} />
<Route path="/profile/:id" component={ProfilePage} />
<Route path="/room/:id/:channel" component={RoomPage} />
<Route path="/room/:roomId/:channelId" component={RoomPage} />
</Switch>
{/* </AuthProvider> */}
</Router>
......
const endpoints = {
API_BASE_URL: "https://localhost:8080/api",
HOME_API: "",
ROOM_API: "room",
PROFILE_API: "profile",
};
export default endpoints;
import axios from "axios";
import endpoints from "./endpoints";
const login = async (email, password) => {
const payload = { email, password };
const { data } = await axios.post(`${endpoints.API_BASE_URL}/`, payload);
return data;
};
export default login;
import { useEffect, useState } from "react";
import login from "../apis/user.api";
const INIT_USER = {
id: "",
email: "",
password: "",
};
......@@ -26,7 +27,7 @@ const Login = () => {
try {
// setLoading(true);
// setError("");
// const success = await login(user.email, user.password);
const success = await login(user.email, user.password);
console.log(user);
setSuccess(success);
} catch (error) {
......@@ -36,7 +37,7 @@ const Login = () => {
}
}
const { id, password } = user;
const { email, password } = user;
return (
<div className="modal-content">
......@@ -57,11 +58,11 @@ const Login = () => {
<label>아이디</label>
<input
className="form-control"
id="id"
id="email"
type="text"
name="id"
name="email"
placeholder="아이디를 입력하세요"
value={id}
value={email}
onChange={handleChange}
/>
</div>
......
import React, { useEffect, useRef, useState } from "react";
const Video = ({ stream, muted }) => {
const ref = useRef(null);
const [isMuted, setIsMuted] = useState(false);
useEffect(() => {
if (ref.current) ref.current.srcObject = stream;
if (muted) setIsMuted(muted);
});
return (
<div>
<video ref={ref} muted={isMuted} autoPlay></video>
</div>
);
};
export default Video;
......@@ -13,17 +13,19 @@ const INIT_USER = {
const Signup = () => {
const [user, setUser] = useState(INIT_USER);
const [error, setError] = useState("");
const [disabled, setDisabled] = useState(false);
const [success, setSuccess] = useState(false);
let disabled = false;
useEffect(() => {
disabled = !(
setDisabled(
!(
user.name &&
user.idNumber1 &&
user.idNumber2 &&
user.id &&
user.password &&
user.checkpw
)
);
}, [user]);
......@@ -156,6 +158,7 @@ const Signup = () => {
/>
</div>
</div>
{console.log(disabled)}
<div className="modal-footer">
<button type="submit" className="btn btn-primary" disabled={disabled}>
회원가입
......
import { Room } from "../models/index.js";
import config from "../config/app.config.js";
const login = async (req, res) => {
try {
console.log("login= ", req.body);
res.json("안녕");
} catch (error) {
console.log(error);
return res.status(500).send("안녕 중 에러");
}
};
export default {
login,
};
import { User } from "../models/index.js";
import config from "../config/app.config.js";
const login = async (req, res) => {
try {
console.log("login= ", req.body);
const { email, password } = req.body;
const user = await User.scope("password").findOne({ where: email });
if (!user)
return res.status(422).send(`${email} 사용자가 존재하지 않습니다.`);
const passworMatch = await user.comparePassword(password);
if (passworMatch) {
const token = jwt.sign({ userID: user.id }, config.jwtSecret, {
expiresIn: config.jwtExpires,
});
res.cookie(config.cookieName, token, {
path: "/",
httpOnly: true,
secure: true,
});
res.json({ user });
} else {
res.status(401).send("비밀번호가 일치하지 않습니다.");
}
} catch (error) {
console.log(error);
return res.status(500).send("로그인 중 에러");
}
};
export default {
login,
};
// server 진입점
import dotenv from "dotenv";
import app from "./app.js";
import appConfig from "./config/app.config.js";
import { sequelize, User } from "./models/index.js";
dotenv.config({
path: `${
process.env.NODE_ENV === "production" ? ".env" : ".env.development"
}`,
});
sequelize
.sync({ force: true })
.then(async () => {
console.log(" DB 연결 성공");
// await User.create({
// id: 0,
// name: "admin",
// email: "admin",
// password: "admin!",
// gender: 0,
// });
app.listen(appConfig.port, () => {
console.log(`Server is running on port ${appConfig.port}`);
});
})
.catch((err) => {
console.log("연결 실패");
console.log(err);
});
// production
// sequelize.sync().then(() => {
// app.listen(appConfig.port, () => {
// console.log(`Server is running on port ${appConfig.port}`)
// })
// })
// development
// 주의!!!: {force: true}는 서버가 다시 시작되면 기존 디비 모두 삭제되고 새로운 디비 생성
// sequelize
// .sync({ force: true })
// .then(async () => {
// // await Promise.all(
// // Object.keys(ROLE_NAME).map((name) => {
// // return Role.create({ name });
// // })
// // );
// // const adminRole = await Role.findOne({ where: { name: "admin" } });
// await User.create({
// id: "0000",
// name: "admin",
// email: "admin",
// password: "admin!",
// gender: 0,
// });
// app.listen(appConfig.port, () => {
// console.log(`Server is running on port ${appConfig.port}`);
// });
// })
// .catch((err) => {
// console.log(err);
// });
import { Sequelize } from "sequelize";
import UserModel from "./user.model.js";
import RoomModel from "./room.model.js";
const env = process.env.NODE_ENV || "development";
import configs from "../config/config.js";
const config = configs[env];
const sequelize = new Sequelize(
config.database,
config.username,
config.password,
{ host: config.host, dialect: config.dialect }
);
const User = UserModel(sequelize);
const Room = RoomModel(sequelize);
export { sequelize, User, Room };
import { DataTypes } from "sequelize";
const RoomModel = (sequelize) => {
const Room = sequelize.define(
"room",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
},
owner: {
type: DataTypes.STRING,
},
member: {
type: DataTypes.ARRAY(DataTypes.INTEGER),
},
channel: {
type: DataTypes.ARRAY(DataTypes.JSON),
},
},
{ timestamps: true }
);
return Room;
};
export default RoomModel;
import bcrypt from "bcryptjs";
import { DataTypes } from "sequelize";
const UserModel = (sequelize) => {
const User = sequelize.define(
"user",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
},
email: {
type: DataTypes.STRING,
},
password: {
type: DataTypes.STRING,
},
gender: {
type: DataTypes.INTEGER,
},
phone: {
type: DataTypes.STRING,
},
img: {
type: DataTypes.ARRAY(DataTypes.INTEGER),
},
roomNumber: {
type: DataTypes.ARRAY(DataTypes.STRING),
},
},
{ timestamps: true }
);
User.beforeSave(async (user) => {
if (!user.changed("password")) {
return;
}
if (user.password) {
const hashedPassword = await bcrypt.hash(user.password, 10);
user.password = hashedPassword;
}
});
User.prototype.toJSON = function toJSON() {
const values = Object.assign({}, this.get());
delete values.password;
return values;
};
User.prototype.comparePassword = async function (plainPassword) {
const passwordMatch = await bcrypt.compare(plainPassword, this.password);
return passwordMatch;
};
return User;
};
export default UserModel;
......@@ -3,23 +3,36 @@
"version": "1.0.0",
"description": "Streaming Service",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"dev": "nodemon -r esm index.js",
"build": "tsc -p ."
},
"repository": {
"type": "git",
"url": "https://compmath.korea.ac.kr/gitlab/research/bora_it.git"
},
"keywords": [],
"author": "Chaerin Kim,",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"cookie-parser": "^1.4.5",
"cors": "2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"esm": "^3.2.25",
"express": "4.17.1",
"http": "0.0.1-security",
"jsonwebtoken": "^8.5.1",
"nodemon": "^2.0.7",
"npm": "^7.18.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://compmath.korea.ac.kr/gitlab/research/bora_it.git"
"pg": "^8.6.0",
"pg-hstore": "^2.3.4",
"postgres": "^1.0.2",
"sequelize": "^6.6.5",
"socket.io": "2.3.0",
"wrtc": "0.4.6"
},
"author": "",
"license": "ISC"
"devDependencies": {
"nodemon": "2.0.7"
}
}
import express from "express";
import userRouter from "./user.route.js";
import roomRouter from "./room.route.js";
const router = express.Router();
router.use("/", userRouter);
router.use("/room/:userId/:channelId", roomRouter);
export default router;
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