Commit 4527d9d2 authored by Spark's avatar Spark
Browse files

Merge remote-tracking branch 'origin/merger' into who

parents bc74fe72 e92762f2
......@@ -2,18 +2,16 @@
## API 명세 Table
| Category | HTTP Method | URI | Description |
| -------------- | ----------- | -------------------------- | ----------------------------------------------------------- |
| Root Directory | ﹒ | /api | api 서버를 통해 들어오는 기본 경로 |
| Data Collector | GET | /data/input?... | 아두이노를 통해 수집한 자료 등록 (내부, 외부는 쿼리로 구분) |
| Data - User | GET | /data/user/:id | 사용자 지정 장소의 데이터 요청 |
| Data - Outside | GET | /data/outside/:id | 해당 지역구의 데이터 요청 |
| Local Code | GET | /loccode/doe | 행정 구역 코드 '도' 요청 |
| Local Code | GET | /loccode/si-gun-gu/:id | 사용자 입력 '도'에 따른 행정 구역 코드 '시군구' 요청 |
| Local Code | GET | /loccod/eup-myeon-dong/:id | 사용자 입력 '시군구'에 따른 행정 구역 코드 '읍면동' 요청 |
| Auth | POST | /signup | 회원가입 요청 |
| Auth | POST | /login | 로그인 요청 |
| Auth | POST | /:id/edit-profile | 회원 정보 수정 요청 |
| Category | HTTP Method | URI | Description |
| :------------- | :---------: | :---------------- | :---------------------------------------------------------- |
| Root | ﹒ | /api | 서버의 기본 경로 |
| Data Collector | GET | /data/input?... | 아두이노를 통해 수집한 자료 등록 (내부, 외부는 쿼리로 구분) |
| Data - User | GET | /data/user/:id | 사용자 지정 장소의 날씨 데이터 요청 |
| Data - Outside | GET | /data/outside/:id | 해당 지역구의 날씨 데이터 요청 |
| Local Code | GET | /data/loccode | 행정 구역 코드 요청 |
| Auth | POST | /signup | 회원가입 요청 |
| Auth | POST | /login | 로그인 요청 |
| Auth | POST | /:id/edit-profile | 회원 정보 수정 요청 |
<br><br>
......@@ -47,3 +45,11 @@
1. 도 정보를 가져오는 경로 수정
: loccode/do -> loccode/doe
### 2021.07.19 \_ 경로 수정
1. API 서버로의 기본 주소 수정
: "/" -> "/api"
2. 행정 구역 코드 데이터 주소 수정
: "도", "시/군/구", "읍/면/동"의 데이터를 따로 요청할 수 있던 것에서, 한번에 처리하도록 변경
......@@ -4,7 +4,8 @@
"description": "",
"main": "init.js",
"scripts": {
"dev:server": "nodemon --exec \"npx babel-node src/init.js\" --delay 2",
"dev:server": "nodemon --exec babel-node src/init.js --delay 2",
"dev:server_window": "nodemon --exec\"npx babel-node src/init.js\" --delay 2",
"start": "babel-node src/init.js"
},
"repository": {
......@@ -18,12 +19,16 @@
},
"homepage": "https://github.com/dorakang612/EUE#readme",
"dependencies": {
"@babel/cli": "^7.14.5",
"@babel/core": "^7.11.6",
"@babel/node": "^7.10.5",
"@babel/preset-env": "^7.11.5",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"helmet": "^4.1.1",
"jsonwebtoken": "^8.5.1",
"morgan": "^1.10.0",
"mysql2": "^2.2.5",
"node-fetch": "^2.6.1",
......@@ -35,9 +40,6 @@
"sequelize": "^6.6.5"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/node": "^7.14.7",
"@babel/preset-env": "^7.14.7",
"nodemon": "^2.0.4"
}
}
import cookieParser from "cookie-parser";
import cors from "cors";
import express from "express";
import morgan from "morgan";
import helmet from "helmet";
......@@ -10,7 +11,6 @@ import globalRouter from "./routers/globalRouter";
import dataRouter from "./routers/dataRouter";
import { localmiddleware } from "./middlewares";
import locCodeRouter from "./routers/locCodeRouter";
const app = express();
......@@ -18,6 +18,7 @@ const app = express();
app.set("view engine", "pug");
app.set("views", path.join(__dirname, "views"));
app.use(cors());
app.use(helmet());
app.use(cookieParser());
app.use(express.json());
......@@ -28,8 +29,7 @@ app.use(morgan("dev"));
app.use(localmiddleware);
// router 사용
app.use(routes.home, globalRouter);
app.use(routes.data, dataRouter);
app.use(routes.locCode, locCodeRouter);
app.use(routes.base, globalRouter);
app.use(routes.base + routes.data, dataRouter);
export default app;
import fs from "fs";
import fetch from "node-fetch";
import { serverMSG, statusCode } from "../serverinfo";
import db from "../db/index";
......@@ -81,8 +80,54 @@ export const getDataInput = (req, res) => {
// 사용자의 데이터 가져오기 및 예측 값 전송
export const getUserWeatherData = (req, res) => {
const {
params: { id },
params: { email },
} = req;
/* 사용자 email에 따른 사용자 날씨 데이터 가져오기 */
res.status(statusCode.ok).send(serverMSG.server_ok);
};
// 지역 코드 요청 처리
export const getLocCode = async (req, res) => {
/* 통합 지역 코드 및 이름 json으로 생성 및 전송 */
let locCodes = [];
const does = await db.Doe.findAll({ logging: false });
const sggs = await db.Sgg.findAll({ logging: false });
const emds = await db.Emd.findAll({ logging: false });
let doe_sgg = [];
let sgg_emd = [];
does.map((info_doe) => {
let temp = {
name_doe: info_doe["name_doe"],
code_doe: info_doe["code_doe"],
};
temp.sgg = sggs.filter(
(info_sgg) => info_sgg["code_doe"] === info_doe["code_doe"]
);
doe_sgg.push(temp);
});
sggs.map((info_sgg) => {
let temp = {
code_doe: info_sgg["code_doe"],
name_sgg: info_sgg["name_sgg"],
code_sgg: info_sgg["code_sgg"],
};
temp.emd = emds.filter(
(info_emd) => info_emd["code_sgg"] === info_sgg["code_sgg"]
);
sgg_emd.push(temp);
});
res.status(statusCode.ok).json({
locCodes: {
DOE: does,
SGG: doe_sgg,
EMD: sgg_emd,
},
});
};
import db from "../db/index";
import dotenv from "dotenv";
import jwt from "jsonwebtoken";
import nodemailer from "nodemailer";
import { serverMSG, statusCode } from "../serverinfo";
import routes from "../routes";
dotenv.config();
......@@ -24,7 +26,11 @@ const postMail = async (email, token) => {
from: `EUE Auth Supply <${process.env.NODEMAILER_USER}>`,
to: email,
subject: "EUE 사용자 계정 확인용 메일.",
text: `You enter locCode : ${locCode}.`,
html: `<a href="${process.env.HOST}:${process.env.PORT}${
routes.base + routes.confirm
}?token=${token}">${process.env.HOST}:${process.env.PORT}${
routes.base + routes.confirm
}?token=${token}</a>`,
};
try {
......@@ -55,7 +61,7 @@ export const getLogin = (req, res) => {
// Function for Signup Proccess.
export const postSignup = async (req, res) => {
const {
body: { email, locCode },
body: { email, nick_name },
} = req;
const result = db.User.findOne({
......@@ -63,14 +69,18 @@ export const postSignup = async (req, res) => {
logging: false,
});
if (result) {
if (result.length != 0) {
res.status(statusCode.err).json({
msg: serverMSG.server_err,
content: "You are aleady registered",
});
} else {
db.User.create({ email: email, locCode: locCode }, { logging: false });
db.User.create({ email: email, nick_name: nick_name }, { logging: false });
// 로그인 페이지로 넘겨주기.
res.status(statusCode.ok).json({
msg: serverMSG.server_ok,
content: "Successfully create user.",
});
}
};
......@@ -79,25 +89,44 @@ export const postLogin = (req, res) => {
body: { email },
} = req;
const result = db.User.findOne({
const result = db.User.findAll({
where: { email: email },
logging: false,
});
if (result) {
if (result.length != 0) {
// token 발행
const token = "ex Token";
const mail_token = jwt.sign(
{
email: email,
nick_name: resutl[0]["nick_name"],
},
process.env.AUTH_SECRETKEY,
{
expiresIn: 10 * 60,
issuer: "eue.com",
subject: "userInfo",
}
);
// 토큰이 포함된 로그인 링크 전송
postLogin(email, token);
postMail(email, mail_token);
res
.status(statusCode.ok)
.json({ msg: serverMSG.server_ok, content: "Send Mail Successfully." });
} else {
res
.status(statusCode.err)
.json({
msg: serverMSG.server_err,
content: "You are still not our user.",
});
res.status(statusCode.err).json({
msg: serverMSG.server_err,
content: "You are not one of our user yet.",
});
}
};
export const getConfirm = (req, res) => {
const {
params: { token },
} = req;
console.log(`Hi, test token : ${token}`);
};
......@@ -18,6 +18,11 @@ export class User extends Model {
allowNull: false,
primaryKey: true,
},
nick_name: {
type: DataTypes.STRING(16),
allowNull: false,
unique: true,
},
password: {
type: DataTypes.STRING(20),
allowNull: false,
......
......@@ -2,6 +2,7 @@ import express from "express";
import routes from "../routes";
import {
getDataInput,
getLocCode,
getUserWeatherData,
} from "../controllers/dataController";
import { onlyPrivate } from "../middlewares";
......@@ -10,5 +11,6 @@ const dataRouter = express.Router();
dataRouter.get(routes.dataInput, getDataInput);
dataRouter.get(routes.dataUser, onlyPrivate, getUserWeatherData);
dataRouter.get(routes.locCode, getLocCode);
export default dataRouter;
......@@ -2,6 +2,7 @@ import express from "express";
import routes from "../routes";
import { getHome } from "../controllers/globalController";
import {
getConfirm,
getLogin,
getSignup,
postLogin,
......@@ -10,12 +11,13 @@ import {
const globalRouter = express.Router();
globalRouter.get(routes.home, getHome);
globalRouter.get("/", getHome); // For development test.
// Authentication
globalRouter.get(routes.signup, getSignup); // For development test.
globalRouter.get(routes.login, getLogin); // For development test.
globalRouter.post(routes.signup, postSignup);
globalRouter.post(routes.login, postLogin);
globalRouter.get(routes.confirm, getConfirm);
export default globalRouter;
import express from "express";
import routes from "../routes";
import { getDoe, getEMD, getSGG } from "../controllers/locCodeController";
const locCodeRouter = express.Router();
locCodeRouter.get(routes.doe, getDoe);
locCodeRouter.get(routes.sigungu + routes.Detail(), getSGG);
locCodeRouter.get(routes.eupmyeondong + routes.Detail(), getEMD);
export default locCodeRouter;
// # Global Routes
const HOME = "/";
const BASE = "/api";
// # Data Routes
const DATA = "/data";
......@@ -11,30 +11,26 @@ const DATA_OUTSIDE = "/outside";
// # Local Code Data
const LOCCODE = "/loccode";
const DOE = "/doe";
const SIGUNGU = "/si-gun-gu";
const EUPMYEONDONG = "/eup-myeon-dong";
// # Auth
const SIGNUP = "/signup";
const LOGIN = "/login";
const CONFIRM = "/confirm";
const EDIT_PROFILE = "/edit-profile";
// # Detail Object
const DETAIL = "/:id";
const routes = {
home: HOME,
base: BASE,
data: DATA,
dataInput: DATA_INPUT,
dataUser: DATA_USER,
dataOutside: DATA_OUTSIDE,
locCode: LOCCODE,
doe: DOE,
sigungu: SIGUNGU,
eupmyeondong: EUPMYEONDONG,
signup: SIGNUP,
login: LOGIN,
confirm: CONFIRM,
editProfile: EDIT_PROFILE,
Detail: (id) => {
if (id) {
......
......@@ -3,8 +3,8 @@ block content
strong Efficient Usage of Electricity
ul
li
a(href=routes.data+routes.dataInput) 데이터 등록
a(href=routes.base + routes.data + routes.dataInput) 데이터 등록
li
a(href=routes.signup) 회원가입
a(href=routes.base + routes.signup) 회원가입
li
a(href=routes.login) 로그인
\ No newline at end of file
a(href=routes.base + routes.login) 로그인
\ No newline at end of file
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