송용우

Merge commit '24bb25e9' into develop

......@@ -27,6 +27,7 @@
| friend | 유저 친구 등록 | POST | api/friend | 바로가기 | JWT Token |
| friend | 유저의 친구 조회 | GET | api/friend:id | 바로가기 | None |
| profile | 유저가 푼 문제 조회 | GET | api/profile/solved:id | 바로가기 | None |
| profile | 유저가 푼 문제 동기화 | Update | api/profile/solved:id | 바로가기 | None |
| profile | 유저가 푼 문제 개수 조회 | GET | api/profile/solvednum:id | 바로가기 | None |
| profile | 추천 문제 조회 | GET | api/profile/recommendps:id | 바로가기 | None |
| notify | 슬랙 메시지 전송 요청 | POST | api/notify/slack | 바로가기 | Jwt Token |
......
const express = require("express");
const morgan = require("morgan");
const Koa = require("koa");
const Router = require("koa-router");
const bodyParser = require("koa-bodyparser");
const mongoose = require("mongoose");
const app = express();
const bodyParser = require("body-parser");
const api = require("./src/api");
const jwtMiddleware = require("./src/lib/jwtMiddleware");
const app = new Koa();
const router = new Router();
require("dotenv").config();
const { SERVER_PORT, MONGO_URL } = process.env;
app.use(morgan("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser());
app.use(jwtMiddleware);
const api = require("./src/api");
const { SERVER_PORT, MONGO_URL } = process.env;
router.use("/api", api.routes());
app.use(router.routes()).use(router.allowedMethods());
app.use("/api", api);
mongoose
.connect(MONGO_URL, { useNewUrlParser: true, useFindAndModify: false })
.connect(MONGO_URL, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
})
.then(() => {
console.log("Connected to MongoDB");
})
......
This diff is collapsed. Click to expand it.
......@@ -8,13 +8,16 @@
"bcrypt": "^4.0.1",
"body-parser": "^1.19.0",
"cheerio": "^1.0.0-rc.3",
"cookie-parser": "^1.4.5",
"dotenv": "^8.2.0",
"eslint-config-prettier": "^6.11.0",
"express": "^4.17.1",
"fs": "^0.0.1-security",
"iconv": "^3.0.0",
"joi": "^14.3.1",
"jsonwebtoken": "^8.5.1",
"koa": "^2.12.0",
"koa-bodyparser": "^4.3.0",
"koa-router": "^9.0.1",
"mongoose": "^5.9.17",
"morgan": "^1.10.0",
"path": "^0.12.7",
......
......@@ -12,6 +12,7 @@ exports.register = async (ctx) => {
username: Joi.string().alphanum().min(3).max(20).required(),
password: Joi.string().required(),
});
const result = Joi.validate(ctx.request.body, schema);
if (result.error) {
ctx.status = 400;
......@@ -33,7 +34,7 @@ exports.register = async (ctx) => {
await user.save();
ctx.body = user.serialize();
const token = user.generateToekn();
const token = user.generateToken();
ctx.cookies.set("acces_token", token, {
//3일동안 유효
maxAge: 1000 * 60 * 60 * 24 * 3,
......
const express = require("express");
const router = express.Router();
router.post("/login");
router.get("/logout");
router.post("/register");
module.exports = router;
const Router = require("koa-router");
const auth = new Router();
const authCtrl = require("./auth.ctrl");
auth.post("/login", authCtrl.login);
auth.get("/logout", authCtrl.logout);
auth.post("/register", authCtrl.register);
module.exports = auth;
......
const express = require("express");
const router = express.Router();
const Router = require("koa-router");
const friend = new Router();
router.post("/");
router.delete("/:id");
router.get("/:id");
router.get("");
friend.post("/");
friend.delete("/:id");
friend.get("/:id");
friend.get("");
module.exports = router;
module.exports = friend;
......
const express = require("express");
const app = express();
const Router = require("koa-router");
const api = new Router();
const auth = require("./auth");
const friend = require("./friend");
......@@ -7,10 +7,10 @@ const notify = require("./profile");
const user = require("./user");
const profile = require("./profile");
app.use("/auth", auth);
app.use("/friend", friend);
app.use("/notify", notify);
app.use("/user", user);
app.use("/profile", profile);
api.use("/auth", auth.routes());
api.use("/friend", friend.routes());
api.use("/notify", notify.routes());
api.use("/user", user.routes());
api.use("/profile", profile.routes());
module.exports = app;
module.exports = api;
......
const express = require("express");
const router = express.Router();
const Router = require("koa-router");
const notify = new Router();
router.post("/slack");
notify.post("/slack");
module.exports = router;
module.exports = notify;
......
const express = require("express");
const router = express.Router();
const Router = require("koa-router");
const profile = new Router();
router.post("/solved:id");
router.get("/solvednum:id");
router.get("recommendps:id");
profile.post("/solved:id");
profile.get("/solvednum:id");
profile.get("recommendps:id");
module.exports = router;
module.exports = profile;
......
const express = require("express");
const router = express.Router();
const Router = require("koa-router");
const user = new Router();
user.post("/");
user.delete("/:id");
user.get("/:id");
user.get("");
router.post("/");
router.delete("/:id");
router.get("/:id");
router.get("");
module.exports = router;
module.exports = user;
......
const mongoose = require("mongoose");
const bcrypt = require("bcrypt");
const jwt = require("jsonwebtoken");
const Schema = mongoose.Schema;
const UserSchema = new Schema({
......@@ -12,7 +13,7 @@ UserSchema.methods.setPassword = async function (password) {
const hash = await bcrypt.hash(password, 10);
this.hashedPassword = hash;
};
UserSchema.methodss.checkPassword = async function (password) {
UserSchema.methods.checkPassword = async function (password) {
const result = await bcrypt.compare(password, this.hashedPassword);
return result;
};
......
This diff is collapsed. Click to expand it.