박유빈

Merge branch 'develop'

......@@ -5,6 +5,28 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch via NPM",
"request": "launch",
"runtimeArgs": [
"run-script",
"debug"
],
"runtimeExecutable": "npm run start:dev",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
},
{"name": "Launch ",
"program": "${workspaceFolder}/app.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
},
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
......
......@@ -19,7 +19,7 @@ server use Node.js, Koa.js and frotend use flutter(Dart)
* [Node.js](https://nodejs.org/)
* [Koa.js](https://koajs.com/)
* [flutter](https://flutter.dev/)
......@@ -31,7 +31,6 @@ server use Node.js, Koa.js and frotend use flutter(Dart)
## Getting Started
Go to the Server [Project folder](http://khuhub.khu.ac.kr/2018102946/likeBack), and git clone.
And go the Frontend [Project folder](http://khuhub.khu.ac.kr/2018102946/likefront)and git clone.
### Installation
......@@ -72,7 +71,7 @@ _Below is an example of how you can instruct your audience on installing and set
Email -- yoobinpark@khu.ac.kr
Project Link: [http://khuhub.khu.ac.kr/2018102946/likeBack](http://khuhub.khu.ac.kr/2018102946/likeBack)
[http://khuhub.khu.ac.kr/2018102946/likefront](http://khuhub.khu.ac.kr/2018102946/likefront)
<p align="right">(<a href="#top">back to top</a>)</p>
......
[debug] [2021-12-06T16:19:50.991Z] ----------------------------------------------------------------------
[debug] [2021-12-06T16:19:50.996Z] Command: /usr/local/bin/node /usr/local/bin/firebase login
[debug] [2021-12-06T16:19:50.997Z] CLI Version: 9.23.0
[debug] [2021-12-06T16:19:50.997Z] Platform: linux
[debug] [2021-12-06T16:19:50.998Z] Node Version: v16.13.0
[debug] [2021-12-06T16:19:51.007Z] Time: Tue Dec 07 2021 01:19:50 GMT+0900 (Korean Standard Time)
[debug] [2021-12-06T16:19:51.008Z] ----------------------------------------------------------------------
[debug]
[debug] [2021-12-06T16:19:51.014Z] >>> [apiv2][query] GET https://firebase-public.firebaseio.com/cli.json [none]
[info] i Firebase optionally collects CLI usage and error reporting information to help improve our products. Data is collected in accordance with Google's privacy policy (https://policies.google.com/privacy) and is not used to identify you.
[debug] [2021-12-06T16:19:52.476Z] <<< [apiv2][status] GET https://firebase-public.firebaseio.com/cli.json 200
[debug] [2021-12-06T16:19:52.476Z] <<< [apiv2][body] GET https://firebase-public.firebaseio.com/cli.json {"cloudBuildErrorAfter":1594252800000,"cloudBuildWarnAfter":1590019200000,"defaultNode10After":1594252800000,"minVersion":"3.0.5","node8DeploysDisabledAfter":1613390400000,"node8RuntimeDisabledAfter":1615809600000,"node8WarnAfter":1600128000000}
[info] i To change your data collection preference at any time, run `firebase logout` and log in again.
[info]
[info] Visit this URL on this device to log in:
[info] https://accounts.google.com/o/oauth2/auth?client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&scope=email%20openid%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloudplatformprojects.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Ffirebase%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&response_type=code&state=406504610&redirect_uri=http%3A%2F%2Flocalhost%3A9005
[info]
[info] Waiting for authentication...
This diff is collapsed. Click to expand it.
......@@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src",
"start:dev": "nodemon --watch src/ src/index.js"
"start:dev": "NODE_PATH=src nodemon --legacy-watch src/ src/index.js"
},
"author": "",
"license": "ISC",
......@@ -16,6 +16,7 @@
"bcrypt": "^5.0.1",
"crypto": "^1.0.1",
"dotenv": "^10.0.0",
"ejs": "^3.1.6",
"express": "^4.17.1",
"firebase": "^9.6.0",
"http2": "^3.3.7",
......@@ -23,12 +24,16 @@
"koa": "^2.13.4",
"koa-body": "^4.2.0",
"koa-bodyparser": "^4.3.0",
"koa-ejs": "^4.3.0",
"koa-passport": "^4.1.4",
"koa-router": "^10.1.1",
"koa-send": "^5.0.1",
"koa-views": "^8.0.0",
"mongoose": "^6.0.12",
"nodemailer": "^6.7.1",
"passport": "^0.5.0",
"passport-google-oauth": "^2.0.0",
"passport-local": "^1.0.0",
"spdy": "^4.0.2"
},
"devDependencies": {
......
......@@ -6,6 +6,9 @@ const nodemailer = require('nodemailer');
const config = require('../../lib/config');
const { Mongoose } = require('mongoose');
const { exist, allow } = require('@hapi/joi');
const index = require('../../../src/index');
const render = index.render;
const fs = require('fs');
exports.test = async (ctx) => {
console.log('cookie');
......@@ -61,7 +64,7 @@ exports.signupLocal = async (ctx) => {
// 응답할 데이터에서 hashedPassword 필드 제거
ctx.status = 200;
ctx.body = await account.serialize();
await ctx.render('users/new');
} catch (e) {
ctx.throw(500, e);
}
......@@ -97,6 +100,7 @@ exports.signinLocal = async (ctx) => {
httpOnly: false,
});
ctx.status = 200;
await ctx.render('users/index');
console.log('토큰나옴');
} catch (e) {
ctx.throw(500, e);
......
require('dotenv').config()
const Router = require("@koa/router");
const authCtrl = require("./auth.ctrl");
const checkLoggedIn = require("../../lib/checkLoggedIn");
var passport = require('passport');
const User = require("../../models/user");
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
const auth = new Router();
......@@ -26,12 +29,73 @@ auth.get('/book',checkLoggedIn,authCtrl.getUserBook);
auth.get('/user', checkLoggedIn,authCtrl.userinfo); // show user information
auth.patch('/user', checkLoggedIn, authCtrl.updateUser); // modify user information
auth.patch('/user/password', authCtrl.changePassword); // change password
auth.post('/find/password', authCtrl.findPassword); // 비밀번호 찾기
auth.get('/favorite',checkLoggedIn, authCtrl.showFavorite); // show a list of user's favorites
auth.post('/favorite',checkLoggedIn, authCtrl.addFavorite); // add favorite
auth.delete('/favorite',checkLoggedIn, authCtrl.delFavorite); // delete favorite
auth.post('/find/password', authCtrl.findPassword); // 비밀번호 찾기
auth.get('/new', async (ctx) => {
ctx.render('users/new');
});
auth.get('/', async (ctx) => {
try{
const users = await User.find({}).sort({email:-1}).exec();//1 오름차순 -1내림차순
ctx.render('users/index', {users});
}catch(e){
ctx.throw(500, e);
}
}
);
// show
auth.get('/:id', async (ctx) => {
const user = await User.findOne({_id:ctx.params._id});
ctx.render('users/show', {user});
});
// edit
auth.get('/:id/edit', async (ctx) => {
const user = await User.findOne({username:ctx.params.username});
ctx.render('users/edit', {user:user});
});
// update // 2
auth.post('/:id', async (ctx) => {
await User.findOne({username:ctx.params.username}).select('password').exec();
// update user object
user.originalPassword = user.password;
user.password = ctx.body.newPassword? ctx.body.newPassword : user.password; // 2-3
for(var p in ctx.body) // 2-4
user[p] = ctx.body[p];
// save updated user
await user.save();
ctx.redirect('/users/'+user.nickname);
});
// destroy
module.exports = auth;
module.exports = auth;
\ No newline at end of file
function checkPermission(ctx, next){
User.findOne({username:ctx.params.username}, function(err, user){
if(err) return res.json(err);
if(user.id != req.user.id) return util.noPermission(ctx);
next();
});
}
\ No newline at end of file
......
......@@ -5,17 +5,17 @@ const Joi = require('@hapi/joi');
const config = require('../../lib/config');
const { Mongoose } = require('mongoose');
exports.booklist = async (ctx) => {
let user;
try {
book = await Book.find()
.sort({created: -1})
.exec();
} catch (e) {
const books = await Book.find({}).sort({createDate: -1}).exec();
await ctx.render('books/index', {book:books});
console.log('get /book/');
//ctx.body = books;
} catch (e) {
return ctx.throw(500, e);
}
ctx.body = book;
}
}
......@@ -55,28 +55,24 @@ exports.addBook = async (ctx) => {
if (err) throw err;
const user = await User.findById(ctx.state.user._id).exec();
console.log(book._id);
ctx.redirect('/books');
});
} catch (e) {
ctx.throw(500, e);
}
ctx.body = book;
console.log('저장 성공!');
ctx.status = 200;
};
exports.getOneBook = async (ctx) => {
const bookid = ctx.request.body._id;
const bookid = ctx.params.id;//bookid by parameter
console.log(bookid);
try {
const mybook = await Book.findById(bookid).exec();
const user = await User.findById(mybook.author).exec();//작가정보
const author_name = user.nickname;
const bookInfo = {
"author_name":author_name
}
ctx.body = {mybook,author_name:author_name}
console.log(mybook)
ctx.render('books/show', {book:mybook, user:user});
//ctx.body.authorname = user.nickname;
//ctx.body = mybook;
} catch (e) {
......@@ -84,7 +80,8 @@ exports.getOneBook = async (ctx) => {
}
//const user = await User.findById(mybook.author).exec();
//ctx.body = mybook;
console.log('책 정보 하나! 얻기 성공');
ctx.status = 200;
};
......@@ -92,49 +89,75 @@ exports.getOneBook = async (ctx) => {
exports.updateBook = async (ctx) => {
// validation추가 필요
const file = ctx.request.files;
if(ctx.request.body.cover != undefined) // when user add a new pet image
ctx.request.body.cover = fs.readFileSync(file.image.path);
else
ctx.request.body.cover = ""
var book = ctx.request.body; //require books's _id
try {
const mybook = await Book.findOne({ _id: book._id });
mybook.updateB(book);
ctx.body = book._id;
} catch (e) {
ctx.throw(500, e);
}
ctx.body = book._id;
console.log(book);
ctx.status = 200;
};
const file = ctx.request.files;
if(ctx.request.body.cover != undefined) // when user add a new pet image
ctx.request.body.cover = fs.readFileSync(file.image.path);
else{
ctx.request.body.cover = ""
}
var book = ctx.request.body; //require books's _id
try {
const mybook = await Book.findOne({ _id: ctx.params.id });
if(ctx.state.user._id == mybook.author){//작성한 사람이 맞을 때만
await mybook.updateB(book);
await ctx.redirect('/api/page/detail/'+ctx.params.id);
ctx.status = 200;}
else{
console.log('작성자가 아니다. ');
ctx.status = 400;
}
}
catch (e) {
ctx.throw(500, e);
ctx.status = 400;
ctx.body = {
message: "작성자가 아닙니다. " }
}
};
exports.deleteBook = async (ctx) => {
let bookid =ctx.params.id;
try {
var b = await Book.find(ctx.params.id);
await Page.deleteMany({"pages":{$in:b.pages}});//book에 있던 페이지 다 지우기
//var foundB = await Book.findById(bookid).exec();
//북작가에게서 책 정보 지우기
var author = await User.findById(bookid);//북 작가.
console.log(author);
console.log(author.books);
await User.delBook(ctx.state.user.email,bookid);
//book에 있던 페이지 다 지우기
await Page.deleteMany({"pages":{$in:b.pages}});
//최종 book지우기
var b = await Book.deleteOne({_id:bookid});
} catch (e) {
if(e.name === 'CastError') {
ctx.status = 400;
return;
}
}
ctx.status = 204; // No Content
console.log('delete success');
ctx.body = {
message: "Delete"
}
};
exports.detailBook = async (ctx) => {
var ObjectId = require('mongodb').ObjectId;
var id = req.params.book_id;
var o_id = new ObjectId(id);
const book = await db.Book.find({_id:o_id});
ctx.body = book;
try{
var id = ctx.params.id;
const book = await dBook.find({_id:id});
ctx.render('books/show', {book:book});
ctx.status = 200;
} catch (e) {
ctx.status = 400;
console.log('북 삭제 오류');
}
};
exports.scrollBook = async (ctx) => {
......@@ -154,8 +177,4 @@ exports.scrollBook = async (ctx) => {
ctx.throw(500, e);
}
}
else if(filter === "추천순") { //추천순
}
};
......
......@@ -2,14 +2,154 @@ const Router = require("@koa/router");
const checkLoggedIn = require("../../lib/checkLoggedIn");
const bookCtrl = require("./book.ctrl");
const book = new Router();
const User = require("../../models/user");
const Book = require("../../models/book");
//북id params로 전달. Render books/show
book.get('/',bookCtrl.getOneBook);
book.get('/:id', async (ctx) => {
const bookid = ctx.params.id;//bookid by parameter
console.log(bookid);
try {
const book = await Book.findOne({_id:ctx.params.id});
ctx.render('books/show', {book});
//ctx.body.authorname = user.nickname;
//ctx.body = mybook;
} catch (e) {
ctx.throw(500, e);
}
//const user = await User.findById(mybook.author).exec();
//ctx.body = mybook;
console.log('책 정보 하나! 얻기 성공');
ctx.status = 200;
});
//mybook=page,title
//author_name = author name
book.post('/',checkLoggedIn,bookCtrl.addBook); // add book
book.patch('/', checkLoggedIn, bookCtrl.updateBook); // modify book information
book.delete('/',checkLoggedIn,bookCtrl.deleteBook); // delete book
book.get('/booklist',bookCtrl.booklist);
book.get('/search',bookCtrl.scrollBook);
book.post('/',checkLoggedIn,async (ctx) => {
const {
title,
author,
contents,
cover,
hashtag,
} = ctx.request.body;
const schema = Joi.object().keys({
title: Joi.string().required(),
author: Joi.string(),
contents: Joi.string().allow(null, ''),
hashtag: Joi.string().allow(null, ''),
cover: Joi.allow(null, ''),
});
try {
await schema.validateAsync(ctx.request.body);
} catch (err) {
console.log('add book validaton' + err);
ctx.status = 400;
return;
}
ctx.request.body.author = ctx.state.user;
const book = new Book(ctx.request.body);
try {
book.save(async (err) => {
if (err) throw err;
const user = await User.findById(ctx.state.user._id).exec();
console.log(book._id);
ctx.redirect('/books');
});
} catch (e) {
ctx.throw(500, e);
}
console.log('저장 성공!');
ctx.status = 200;
});
// add book
// redirect posts (create)
module.exports = book;
\ No newline at end of file
book.patch('/:id', checkLoggedIn, async (ctx) => {
const file = ctx.request.files;
if(ctx.request.body.cover != undefined) // when user add a new pet image
ctx.request.body.cover = fs.readFileSync(file.image.path);
else{
ctx.request.body.cover = ""
}
var book = ctx.request.body; //require books's _id
try {
const mybook = await Book.findOne({ _id: ctx.params.id });
if(ctx.state.user._id == mybook.author){//작성한 사람이 맞을 때만
await mybook.updateB(book);
await ctx.redirect('/api/page/detail/'+ctx.params.id);
ctx.status = 200;}
else{
console.log('작성자가 아니다. ');
ctx.status = 400;
}
}
catch (e) {
ctx.throw(500, e);
ctx.status = 400;
ctx.body = {
message: "작성자가 아닙니다. " }
}
});// modify book information
//update book rediret:"/books/"+ctx.params.id
//book.id params
book.delete('/:id',checkLoggedIn,async (ctx) => {
let bookid =ctx.params.id;
try {
//var foundB = await Book.findById(bookid).exec();
//북작가에게서 책 정보 지우기
var author = await User.findById(bookid);//북 작가.
console.log(author);
console.log(author.books);
await User.delBook(ctx.state.user.email,bookid);
//book에 있던 페이지 다 지우기
await Page.deleteMany({"pages":{$in:b.pages}});
//최종 book지우기
var b = await Book.deleteOne({_id:bookid});
} catch (e) {
if(e.name === 'CastError') {
ctx.status = 400;
return;
}
}
console.log('delete success');
ctx.body = {
message: "Delete"
}
}); // delete book
// params.id
//redirect('/books')<-index
book.get('/',async (ctx) => {
try {
const books = await Book.find({}).sort({createDate: -1}).exec();
ctx.render('books/index', {books:books});
} catch (e) {
return ctx.throw(500, e);
}
}
);
book.get('/search', async (ctx) => {
const {filter, renewal} = ctx.query
if(filter === "조회순") { //조회순
try {
const books = await Book.find().sort({'views': -1}).skip(parseInt(renewal)*10).limit(10)
let result = await bookInfo(books);
ctx.status = 200;
ctx.body = result;
} catch (e) {
ctx.throw(500, e);
}
}
});
book.get('/new', async (ctx) => {
ctx.render('books/new');
});
module.exports = book;
......
const Router = require("koa-router");
const page = require("./page");
const auth = require("./auth");
const book = require("./book");
//const page = require("./page");
//const auth = require("./auth");
//const book = require("./book");
//const render = require('../index/');
const api = new Router();
//const path = require('path');
api.use("/auth", auth.routes());
api.use("/book", book.routes());
api.use("/page", page.routes());
api.get('/test', (ctx) => (ctx.body = 'hi'));
module.exports = api;
///api.use("/auth", auth.routes());
//api.use("/book", book.routes());
//api.use("/page", page.routes());
//module.exports = api;
......
......@@ -2,8 +2,12 @@ const Router = require("@koa/router");
const checkLoggedIn = require("../../lib/checkLoggedIn");
const pageCtrl = require("./page.ctrl");
const page = new Router();
const Page = require("../../models/page");
const index = require('../../../src/index');
//const render = require('koa-ejs');
//Page api
/*
page.get('/',pageCtrl.getPage); // show a list of user's pages
page.post('/',checkLoggedIn,pageCtrl.addPage); // add page
page.patch('/', checkLoggedIn,pageCtrl.updatePage); // modify page information
......@@ -11,13 +15,62 @@ page.delete('/',checkLoggedIn,pageCtrl.deletePage); // delete book
page.get('/search', pageCtrl.search); // /search?title=search_query&petType=petType
//page.post('/search/filter', pageCtrl.searchFilter); //아직 구현 안함
page.post('/detail', pageCtrl.detailPage); // detail recipe page
page.post('/:id', pageCtrl.detailPage); // detail recipe page
//page.get('/recipe/slide', pageCtrl.slidRecipe); // 5 recommended videos in main page
// /recipe/scroll?filter=filter_query&renewal=count (filter_query: 추천순 or 조회순)
page.get('/recipe/scroll', pageCtrl.scrollPage); // video list sorted by 추천순 or 조회순 in main page
*/
page.get('/', async (ctx) => {
const page = await Page.find({}).sort({createDate:-1}).exec();
console.log(page);
await ctx.render('posts/index', {page});
});
page.get('/new', async (ctx) => {
await ctx.render('posts/new');
});
// create
page.post('/', async (ctx, next) => {
await Page.create(ctx.body);
ctx.redirect('/posts');
});
// show
page.get('/:id', async (ctx, next) => {
const page = await Page.findOne({_id:ctx.params.id});
console.log('찾은 페이지',page);
ctx.render('posts/show', {page:page,user:ctx.state.user});
});
// update
page.put('/:id', async (ctx, next) => {
ctx.body.updatedAt = Date.now(); //2
const page = await Page.findOneAndUpdate({_id:ctx.params.id}, ctx.body);
ctx.redirect("/posts/"+ctx.params.id);
});
// destroy
page.delete('/:id', async (ctx, next) => {
try{
await Page.deleteOne({_id:ctx.params.id})
ctx.redirect('/posts');
}catch(e){
ctx.throw(500, e);
}
});
//page.post('/postinfo', pageCtrl.uploadInfo);
//page.get('/info',pageCtrl.getbyurl);//url로 recipe정보 가져오기 (flutter 내 레시피에서 쓰임.)
module.exports = page;
\ No newline at end of file
module.exports = page;
......
......@@ -4,6 +4,8 @@ const Book = require("../../models/book");
const Joi = require('@hapi/joi');
const config = require('../../lib/config');
const { Mongoose } = require('mongoose');
exports.search = async (ctx) => {
const { title } = ctx.query; //search word
console.log(title)
......@@ -19,12 +21,18 @@ exports.search = async (ctx) => {
exports.detailPage = async (ctx) => {
var ObjectId = require('mongodb').ObjectId;
var id = req.params.page_id;
try{
var ObjectId = require('mongodb').ObjectId;
var id = req.params.id;
var o_id = new ObjectId(id);
const page = await db.Page.find({_id:o_id});
await ctx.redirect('/api/page/detail/'+req.params.id);
ctx.body = page;
ctx.status = 200;
}catch(e){
ctx.throw(500,e);
}
};
// parameters: array with book objects as elements
......@@ -149,19 +157,21 @@ exports.scrollPage = async (ctx) => {
else
ctx.request.body.image = ""
var user = ctx.request.body; //require user id
var page = ctx.request.body;
try {
const mybook = await Book.findOne({ _id: book._id });
mybook.updateP(book);
ctx.body = user._id;
} catch (e) {
const mypage = await Page.findOne({ _id: page._id });//require page's _id
if(ctx.state.user._id == mypage.author){
mypage.updateP(book);
ctx.body = mypage;
console.log(mypage);
ctx.status = 200;}
} catch (e) {
ctx.throw(500, e);
}
ctx.body = user._id;
console.log(user);
ctx.body = {
message: "작성자가 아닙니다. " }
}
ctx.status = 200;
};
......@@ -178,18 +188,3 @@ exports.deletePage = async (ctx) => {
}
ctx.status = 204; // No Content
};
exports.getPage = async (ctx) => {
const pageid = ctx.request.body._id;
try {
const mypage = await Book.findById(pageid).exec();
const user = await User.findById(mypage.author).exec();//작가정보
const author_name = user.nickname;
ctx.body = {mypage,author_name:author_name}
console.log(mypage)
} catch (e) {
ctx.throw(500, e);
}
};
......
......@@ -9,8 +9,17 @@ const mongoose = require('mongoose');
const bodyParser = require('koa-bodyparser');
const port = process.env.PORT || 3000
//443
const passport = require('koa-passport')
const app = new Koa();
const router = new Router()
const render = require('koa-ejs');
const path = require('path');
//const User = require('../models/user');
//const views = require('koa-views');
const book = require('./routes/book');
const auth = require('./routes/user');
const page = require('./routes/page');
const send = require('koa-send');
var options = {
key: fs.readFileSync('./server.key'),
......@@ -29,53 +38,90 @@ mongoose.connect(process.env.MONGO_URI).then(
console.error(e);
});
var readFileThunk = function(src) {
return new Promise(function (resolve, reject) {
fs.readFile(src, {'encoding': 'utf8'}, function (err, data) {
if(err) return reject(err);
resolve(data);
});
});
}
//app.use(router.routes())
/*
app
.use(router.routes())
.use(router.allowedMethods());
*/
app
.use(jwtMiddleware)
.use(bodyParser()) // bodyParser는 라우터 코드보다 상단에 있어야 합니다.
.use(router.routes())
.use(router.allowedMethods());
/*
router.get('/', (ctx, next) => {
ctx.body = '루트 페이지 입니다.';
render(app, {
root: path.join(__dirname, 'views'),
layout: false,
viewExt: 'ejs',
cache: false,
debug: true
});
*/
// app.use(async function (ctx) {
// await ctx.render('home/welcome');
// });
app
.use(jwtMiddleware)
.use(bodyParser()); // bodyParser는 라우터 코드보다 상단에 있어야 합니다.
render(app, {
root: path.join(__dirname, 'views'),
layout: false,
viewExt: 'ejs',
cache: false,
debug: true
});
*/
/*
router.get('/', async (ctx, next) => {
const rawContent = fs.readFileSync('index.html').toString('utf8')
ctx.body = rawContent
})*/
router.get('/', function *(){
this.body = yield readFileThunk(__dirname + '/public/index.html');
})
app
.use(router.routes())
.use(router.allowedMethods())
.use(passport.initialize());
// .use(views(path.join(__dirname, 'views'), {
//extension: 'ejs'
//}))
//.use(views('views', { map: { html: 'ejs' } }));
router.get('/', async ctx =>{
await ctx.render('home/welcome');
});
router.get('/about', async ctx =>{
ctx.render('home/about');
});
router.get('/auth', async ctx =>{
ctx.render('users/login');
});
//router.use('/', api.routes());
//router.use("/book", require("./routes/book"));
//router.use("/page", require("./routes/page"));
//router.use("/auth", require("./routes/user"));
router.use('/auth', auth.routes());
router.use('/book', book.routes());
router.use('/page', page.routes());
app.use(router.routes()).use(router.allowedMethods());
//router.get('/', async (ctx, next) => {
// const rawContent = fs.readFileSync('index.html').toString('utf8')
//ctx.body = rawContent
//})
//router.use(api.routes());
//app.use(router.routes()).use(router.allowedMethods())
router.use('/api', api.routes());
app.use(router.routes()).use(router.allowedMethods());
//app.use(router.routes()).use(router.allowedMethods());
http2
.createSecureServer(options, app.callback())
.listen(port, () => console.log("listening on port %i", port));
//app.listen(port, function () {
//console.log('server listening on port %d', port);
//});
/*
app.listen(port, function () {
console.log('server listening on port %d', port);
});
*/
\ No newline at end of file
......
......@@ -9,4 +9,14 @@ const checkLoggedIn = (ctx, next) => {
};
module.exports = checkLoggedIn;
const User = require('../models/user')
const checkPermission = (ctx, next) => {
const user = User.findOne({username:ctx.params.username});
if(user._id != ctx.status.user._id)
return util.noPermission(ctx);
next();
};
module.exports = checkPermission;
\ No newline at end of file
......
const config = {
mailer: {
user: "yoobinpark@khu.ac.kr",
password: "1q2w3e4r!@",
user: "like01test@gmail.com",
password: "like1412",
expiresIn: 60 * 5,
},
};
......
......@@ -5,9 +5,9 @@ const { Schema } = mongoose;
const bookSchema = new Schema({
id: mongoose.Schema.Types.ObjectId,//unique number of page
pages:[{type:String}],//book contains several pages. pages is the list of page id
pages:[{type:mongoose.Schema.Types.ObjectId, ref:'page', required:false}],//book contains several pages. pages is the list of page id
title: {type:String, require:true}, // book title
author: [{type:String, require:true, default:user.user}],//작가복수 가능
author: [{type:mongoose.Schema.Types.ObjectId, ref:'user', required:true}],//작가복수 가능
contents: {type:String}, // book subtitle or detail
createDate: {type:Date, require:true, default:Date.now},
updateDate: {type:Date, default:Date.now},
......@@ -102,5 +102,6 @@ const bookSchema = new Schema({
};
module.exports = mongoose.model("Book", bookSchema);
\ No newline at end of file
......
......@@ -4,9 +4,9 @@ const { Schema } = mongoose;
const PageSchema = new Schema({
id: mongoose.Schema.Types.ObjectId,//unique number of page
book:{type:String},//book contains several pages
book:[{type:mongoose.Schema.Types.ObjectId, ref:'book', required:false}],//book contains several pages
title: {type:String, require:true}, // title of post
author: [{type:String, require:true, default:user.user}],
author: [{type:mongoose.Schema.Types.ObjectId, ref:'user', required:true}],
contents: {type:String}, // contents of page
createDate: {type:Date, require:true, default:Date.now},
updateDate: {type:Date, default:Date.now},
......
......@@ -12,10 +12,10 @@ const UserSchema = new Schema({
password: String,
token: String,
//user info
username: String,
phone: {type: String, require: true},
nickname: {type: String, default: ""},
books: [{type: String}],//array of bookid
books: [{type:mongoose.Schema.Types.ObjectId, ref:'book', required:false}],//array of bookid
pages:[{type:mongoose.Schema.Types.ObjectId, ref:'page', required:false}],
favorite: [{ type: String }],//String of url(book, page)
});
......
/* global style */
form label{
padding: 3px;
margin-bottom: 0;
font-weight: 300;
}
form .form-control{
padding: 3px 7px;
font-size: inherit;
line-height: 20px;
height: auto;
border: 1px solid #ccc;
border-radius: 3px;
width: 100%;
}
form fieldset{
margin: 7px 0 1px;
padding: 0px 15px;
}
form .form-group{
margin: 0;
padding-bottom: 6px;
}
.ellipsis{
display: block;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.form-horizontal .control-label {
padding-top: 5px;
text-align: left;
}
.buttons {
margin: 7px 0;
padding: 0 5px;
}
.buttons form{
display: inline-block;
}
.buttons .btn-default{
min-width: 55px;
color: #165751;
border: 1px solid #ccc;
border-right: 1px solid #aaa;
border-bottom: 1px solid #aaa;
border-radius: 4px;
padding: 5px 10px;
background-color: #f5f5f5;
font-size: 0.8em;
font-weight: bold;
}
.buttons .btn-default:hover{
text-decoration: none;
position: relative;
top: 1px;
left: 1px;
border: 1px solid #ccc;
border-top: 1px solid #aaa;
border-left: 1px solid #aaa;
}
.contentBox{
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
}
.contentBoxTop {
font-size: 14px;
font-weight: 600;
margin: 0;
border-bottom: 1px solid #ccc;
background-color: #F5F5F5;
padding: 6px 15px;
}
/* home style */
.home h1{
color: darkseagreen;
}
.home-login{
max-width: 330px;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
}
/* post style */
.post {
max-width: 670px;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
}
.post h2 {
color: tomato;
text-align: center;
}
.post .post-body {
white-space: pre-line;
padding: 6px 15px 20px;
}
.post .post-info{
font-size: 11px;
margin: 5px;
padding: 5px 10px;
background-color: #E4E4E4;
border: 0 solid black;
border-radius: 5px;
}
.post .post-info>div{
padding: 5px 0;
border-top: 1px dotted #999;
}
.post .post-info>div:first-child{
border-top: none;
}
.post .post-info span{
display: inline-block;
width: 40px;
}
.post-index .posts{
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
table-layout: fixed;
}
.post .posts th,
.post .posts td
{
padding: 7px 5px;
}
.post .posts th:first-child,
.post .posts td:first-child
{
padding-left: 15px;
}
.post .posts thead{
background-color: #F5F5F5;
}
.post .posts thead tr th{
border-bottom: 1px solid #ccc;
}
.post .posts tbody tr:nth-child(odd){
background-color: #F4FFFF;
}
.post .posts tbody .noData{
background-color: #FFFFFF;
text-align: center;
}
.post .posts .author{
text-align: center;
width: 80px;
}
.post .posts .date{
text-align: center;
width: 100px;
padding-right: 15px;
}
.post-new,
.post-edit{
max-width: 520px;
}
/* user style */
.user {
max-width: 320px;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
}
.user-index ul{
margin: 0;
padding: 3px 12px;
}
.user-index ul:after {
content: "";
display: block;
clear: both;
}
.user-index ul li{
display: inline-block;
list-style-type: none;
}
.user-index ul li a{
display: inline-block;
text-decoration:none;
margin: 3px;
background-color: #eee;
padding: 3px 10px;
border-radius: 3px;
}
.user-index ul li a:hover{
background-color: #ccc;
}
.user-edit hr{
margin-top: 5px;
margin-bottom: 11px;
}
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}
.wrapper {
margin-top: 80px;
margin-bottom: 20px;
}
.form-signin {
max-width: 420px;
padding: 30px 38px 66px;
margin: 0 auto;
background-color: #eee;
border: 3px dotted rgba(0,0,0,0.1);
}
.form-signin-heading {
text-align:center;
margin-bottom: 30px;
}
.form-control {
position: relative;
font-size: 16px;
height: auto;
padding: 10px;
}
input[type="text"] {
margin-bottom: 0px;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
input[type="password"] {
margin-bottom: 20px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
$(function(){
function get2digits (num){
return ('0' + num).slice(-2);
}
function getDate(dateObj){
if(dateObj instanceof Date)
return dateObj.getFullYear() + '-' + get2digits(dateObj.getMonth()+1)+ '-' + get2digits(dateObj.getDate());
}
function getTime(dateObj){
if(dateObj instanceof Date)
return get2digits(dateObj.getHours()) + ':' + get2digits(dateObj.getMinutes())+ ':' + get2digits(dateObj.getSeconds());
}
function convertDate(){
$('[data-date]').each(function(index,element){
var dateString = $(element).data('date');
if(dateString){
var date = new Date(dateString);
$(element).html(getDate(date));
}
});
}
function convertDateTime(){
$('[data-date-time]').each(function(index,element){
var dateString = $(element).data('date-time');
if(dateString){
var date = new Date(dateString);
$(element).html(getDate(date)+' '+getTime(date));
}
});
}
convertDate();
convertDateTime();
});
\ No newline at end of file
const Router = require("@koa/router");
const checkLoggedIn = require("../../src/lib/checkLoggedIn");
//const bookCtrl = require("./book.ctrl");
const book = new Router();
const User = require("../models/user")
const Book = require("../models/book");
//북id params로 전달. Render books/show
book.get('/:id', async (ctx) => {
const bookid = ctx.params.id;//bookid by parameter
console.log(bookid);
try {
const book = await Book.findOne({_id:ctx.params.id});
ctx.render('books/show', {book});
//ctx.body.authorname = user.nickname;
//ctx.body = mybook;
} catch (e) {
ctx.throw(500, e);
}
//const user = await User.findById(mybook.author).exec();
//ctx.body = mybook;
console.log('책 정보 하나! 얻기 성공');
ctx.status = 200;
});
//mybook=page,title
//author_name = author name
book.post('/',checkLoggedIn,async (ctx) => {
const {
title,
author,
contents,
cover,
hashtag,
} = ctx.request.body;
const schema = Joi.object().keys({
title: Joi.string().required(),
author: Joi.string(),
contents: Joi.string().allow(null, ''),
hashtag: Joi.string().allow(null, ''),
cover: Joi.allow(null, ''),
});
try {
await schema.validateAsync(ctx.request.body);
} catch (err) {
console.log('add book validaton' + err);
ctx.status = 400;
return;
}
ctx.request.body.author = ctx.state.user;
const book = new Book(ctx.request.body);
try {
book.save(async (err) => {
if (err) throw err;
const user = await User.findById(ctx.state.user._id).exec();
console.log(book._id);
ctx.redirect('/books');
});
} catch (e) {
ctx.throw(500, e);
}
console.log('저장 성공!');
ctx.status = 200;
});
// add book
// redirect posts (create)
book.patch('/:id', checkLoggedIn, async (ctx) => {
const file = ctx.request.files;
if(ctx.request.body.cover != undefined) // when user add a new pet image
ctx.request.body.cover = fs.readFileSync(file.image.path);
else{
ctx.request.body.cover = ""
}
var book = ctx.request.body; //require books's _id
try {
const mybook = await Book.findOne({ _id: ctx.params.id });
if(ctx.state.user._id == mybook.author){//작성한 사람이 맞을 때만
await mybook.updateB(book);
await ctx.redirect('/api/page/detail/'+ctx.params.id);
ctx.status = 200;}
else{
console.log('작성자가 아니다. ');
ctx.status = 400;
}
}
catch (e) {
ctx.throw(500, e);
ctx.status = 400;
ctx.body = {
message: "작성자가 아닙니다. " }
}
});// modify book information
//update book rediret:"/books/"+ctx.params.id
//book.id params
book.delete('/:id',checkLoggedIn,async (ctx) => {
let bookid =ctx.params.id;
try {
//var foundB = await Book.findById(bookid).exec();
//북작가에게서 책 정보 지우기
var author = await User.findById(bookid);//북 작가.
console.log(author);
console.log(author.books);
await User.delBook(ctx.state.user.email,bookid);
//book에 있던 페이지 다 지우기
await Page.deleteMany({"pages":{$in:b.pages}});
//최종 book지우기
var b = await Book.deleteOne({_id:bookid});
} catch (e) {
if(e.name === 'CastError') {
ctx.status = 400;
return;
}
}
console.log('delete success');
ctx.body = {
message: "Delete"
}
}); // delete book
// params.id
//redirect('/books')<-index
book.get('/',async (ctx) => {
try {
const books = await Book.find({}).sort({createDate: -1}).exec();
ctx.render('books/index', {books:books});
} catch (e) {
return ctx.throw(500, e);
}
}
);
book.get('/search', async (ctx) => {
const {filter, renewal} = ctx.query
if(filter === "조회순") { //조회순
try {
const books = await Book.find().sort({'views': -1}).skip(parseInt(renewal)*10).limit(10)
let result = await bookInfo(books);
ctx.status = 200;
ctx.body = result;
} catch (e) {
ctx.throw(500, e);
}
}
});
book.get('/new', async (ctx) => {
ctx.render('books/new');
});
module.exports = book;
\ No newline at end of file
const Router = require("@koa/router");
const checkLoggedIn = require("../../src/lib/checkLoggedIn");
// const pageCtrl = require("./page.ctrl");
const page = new Router();
const Page = require("../models/page");
//const index = require('../../../src/index');
//const render = require('koa-ejs');
//Page api
/*
page.get('/',pageCtrl.getPage); // show a list of user's pages
page.post('/',checkLoggedIn,pageCtrl.addPage); // add page
page.patch('/', checkLoggedIn,pageCtrl.updatePage); // modify page information
page.delete('/',checkLoggedIn,pageCtrl.deletePage); // delete book
page.get('/search', pageCtrl.search); // /search?title=search_query&petType=petType
//page.post('/search/filter', pageCtrl.searchFilter); //아직 구현 안함
page.post('/:id', pageCtrl.detailPage); // detail recipe page
//page.get('/recipe/slide', pageCtrl.slidRecipe); // 5 recommended videos in main page
// /recipe/scroll?filter=filter_query&renewal=count (filter_query: 추천순 or 조회순)
page.get('/recipe/scroll', pageCtrl.scrollPage); // video list sorted by 추천순 or 조회순 in main page
*/
page.get('/tset', async (ctx) => {
console.log('testtest');
});
page.get('/', async (ctx) => {
const page = await Page.find({}).sort({createDate:-1}).exec();
console.log(page);
await ctx.render('posts/index', {page});
});
page.get('/new', async (ctx) => {
await ctx.render('posts/new');
});
// create
page.put('/', checkLoggedIn, async (ctx, next) => {
const {
title,
author,
contents,
cover,
hashtag,
} = ctx.request.body;
const schema = Joi.object().keys({
title: Joi.string().required(),
author: Joi.string(),
contents: Joi.string().allow(null, ''),
hashtag: Joi.string().allow(null, ''),
cover: Joi.allow(null, ''),
});
try {
await schema.validateAsync(ctx.request.body);
} catch (err) {
console.log('add book validaton' + err);
ctx.status = 400;
return;
}
ctx.request.body.author = ctx.state.user;
const book = new Book(ctx.request.body);
try {
book.save(async (err) => {
if (err) throw err;
const user = await User.findById(ctx.state.user._id).exec();
console.log(book._id);
ctx.redirect('/page');
});
} catch (e) {
ctx.throw(500, e);
}
console.log('저장 성공!');
ctx.status = 200;
ctx.redirect('/page');
});
// show
page.get('/:id', async (ctx, next) => {
try{
var id = ctx.params.id;
const page = await Page.findById(id).exec();
await ctx.render('posts/show', {page:page});
ctx.status = 200;
}catch(e){
ctx.throw(500,e);
}
});
// update
page.patch('/:id',checkLoggedIn, async (ctx, next) => {
const id = ctx.params.id;
if(ctx.request.files != undefined) // when user add a new pet image
ctx.request.body.image = fs.readFileSync(file.image.path);
else
ctx.request.body.image = ""
ctx.body.updateDate = Date.now();
var page = ctx.request.body;
try {
const mypage = await Page.findOne({ _id: id });//require page's _id
if(ctx.state.user._id == mypage.author){
mypage.updateP(page);
console.log(mypage);
ctx.redirect("/page/"+id);
ctx.status = 200;}
} catch (e) {
ctx.throw(500, e);
ctx.body = {
message: "작성자가 아닙니다. " }
}
});
// destroy
page.delete('/:id', async (ctx, next) => {
try{
await Page.deleteOne({_id:ctx.params.id})
ctx.redirect('/page');
}catch(e){
ctx.throw(500, e);
}
});
//page.post('/postinfo', pageCtrl.uploadInfo);
//page.get('/info',pageCtrl.getbyurl);//url로 recipe정보 가져오기 (flutter 내 레시피에서 쓰임.)
module.exports = page;
require('dotenv').config()
const Router = require("@koa/router");
//const authCtrl = require("auth.ctrl");
const checkLoggedIn = require("../../src/lib/checkLoggedIn");
//var passport = require('passport');
const User = require("../models/user");
//var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
const auth = new Router();
// 회원가입- 로컬 이메일 인증번호 발송 POST auth/signup/email/demand
// 회원가입 이메일 인증번호 확인 POST auth/signup/email/verify
// 로그인 "소셜 로그인
// (페이스북 구글 네이버 카카오)" POST auth/signin/social
// 회원정보갱신 설문이나 설정에서 개인정보 바꾸면 적용 PATCH auth/update/pet
// 회원정보갱신 설문이나 설정에서 개인정보 바꾸면 적용 PATCH auth/update/user
/*
auth.get('/userlist', authCtrl.userlist);
auth.get('/test', authCtrl.test);
auth.post('/signup', authCtrl.signupLocal);
auth.post('/signin', authCtrl.signinLocal);
auth.get('/signout',checkLoggedIn, authCtrl.signout);
auth.get('/check', authCtrl.check2);
auth.delete('/user',checkLoggedIn,authCtrl.Withdrawal); // 회원 탈퇴
auth.post('/validate', authCtrl.exists);
auth.post('/checkpassword', authCtrl.checkPassword);
auth.get('/book',checkLoggedIn,authCtrl.getUserBook);
auth.get('/user', checkLoggedIn,authCtrl.userinfo); // show user information
auth.patch('/user', checkLoggedIn, authCtrl.updateUser); // modify user information
auth.patch('/user/password', authCtrl.changePassword); // change password
auth.post('/find/password', authCtrl.findPassword); // 비밀번호 찾기
auth.get('/favorite',checkLoggedIn, authCtrl.showFavorite); // show a list of user's favorites
auth.post('/favorite',checkLoggedIn, authCtrl.addFavorite); // add favorite
auth.delete('/favorite',checkLoggedIn, authCtrl.delFavorite); // delete favorite
auth.post('/find/password', authCtrl.findPassword); // 비밀번호 찾기
*/
auth.get('/new', async (ctx) => {
ctx.render('users/new');
});
auth.get('/test', async (ctx) => {
ctx.render('users/login');
});
// show
/*
auth.get('/:id', async (ctx) => {
try{
const user = await User.findOne({_id:ctx.params._id});
ctx.render('users/show', {user});
}catch(e){
ctx.throw(500, e);
console.log(e); }
});
*/
auth.get('/login', async (ctx) => {
await ctx.render('home/login')
});
// edit
auth.get('/:id/edit', async (ctx) => {
const user = await User.find({email:ctx.params.email}).exec();
ctx.render('users/edit', {user:user});
});
auth.post('/login',async(ctx) =>{
const { email, password } = ctx.request.body;
const errors ='';
//handle error
if (!email || !password) {
ctx.status = 401; //Unauthorized
errors= '비밀번호, 이메일 중 하나가 틀렸습니다. '
return;
}
try {
//const user = User.findOne({ email: email });
const user = await User.findByEmail(email);
//계정없으면 에러처리
console.log(user);
if (!user) {
ctx.status = 401;
return;
}
const valid = await user.checkPassword(password);
if (!valid) {
ctx.status = 401;
return;
}
ctx.body = await user.serialize();
const token = user.generateToken();
ctx.cookies.set('access_token', token, {
maxAge: 1000 * 60 * 60 * 24 * 7, // 7일
httpOnly: false,
});
ctx.status = 200;
ctx.redirect('/page');
console.log('토큰나옴, 로그인');
} catch (e) {
ctx.throw(500, e);
ctx.redirect('/')
}
});
auth.post('/signup',async(ctx)=>{const { email, password, address } = ctx.request.body;
console.log(ctx.request.body);
const schema = Joi.object().keys({
email: Joi.string().min(3).required(),
password: Joi.string().required(),
phone: Joi.string().allow(null, ''),
nickname:Joi.string().allow(null, '')
});
//검증 결과
try {
const value = await schema.validateAsync(ctx.request.body);
} catch (err) {
console.log(err);
ctx.status = 400;
return;
}
try {
// email 이미 존재하는지 확인
const exists = await User.findByEmail(email);
if (exists) {
ctx.status = 409; // Conflict
return;
}
let account = null;
try {
account = await User.localRegister(ctx.request.body);
} catch (e) {
ctx.throw(500, e);
}
let token = null;
try {
token = await account.generateToken();
console.log('token ok');
} catch (e) {
ctx.throw(500, e);
}
ctx.cookies.set('access_token', token, { maxAge: 1000 * 60 * 60 * 24 * 7 ,httpOnly: true,});
console.log('set cookie ok');
// 응답할 데이터에서 hashedPassword 필드 제거
ctx.status = 200;
await ctx.render('users/new');
} catch (e) {
ctx.throw(500, e);
}});
// update // 2
auth.post('/:id', async (ctx) => {
await User.findOne({username:ctx.params.username}).select('password').exec();
// update user object
user.originalPassword = user.password;
user.password = ctx.body.newPassword? ctx.body.newPassword : user.password; // 2-3
for(var p in ctx.body) // 2-4
user[p] = ctx.body[p];
// save updated user
await user.save();
ctx.redirect('/users/'+user.nickname);
});
// destroy
auth.get('/logout', async (ctx) => {
ctx.cookies.set('access_token');
ctx.status = 204;
ctx.redirect('/');
});
module.exports = auth;
function checkPermission(ctx, next){
User.findOne({username:ctx.params.username}, function(err, user){
if(err) return res.json(err);
if(user.id != req.user.id) return util.noPermission(ctx);
next();
});
}
\ No newline at end of file
var util = {};
util.parseError = function(errors){
var parsed = {};
if(errors.name == 'ValidationError'){
for(var name in errors.errors){
var validationError = errors.errors[name];
parsed[name] = { message:validationError.message };
}
}
else if(errors.code == '11000' && errors.errmsg.indexOf('username') > 0) {
parsed.username = { message:'This username already exists!' };
}
else {
parsed.unhandled = JSON.stringify(errors);
}
return parsed;
}
util.isLoggedin = function(req, res, next){
if(req.isAuthenticated()){
next();
}
else {
req.flash('errors', {login:'Please login first'});
res.redirect('/login');
}
}
util.noPermission = function(ctx){
ctx.request.flash('errors', {login:"You don't have permission"});
ctx.request.logout();
ctx.request.redirect('/login');
}
module.exports = util;
\ No newline at end of file
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<nav aria-label="breadcrumb">
<ol class="breadcrumb p-1 pl-2 pr-2">
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-item"><a href="/api/page">Page</a></li>
<li class="breadcrumb-item"><a href="/api/book/<%= book._id %>"><%= book.title %></a></li>
<li class="breadcrumb-item active" aria-current="page">Edit Post</li>
</ol>
</nav>
<form action="/api/book/<%= book._id %>?_method=patch" method="patch">
<div class="form-group">
<label for="title">Title</label>
<input type="text" id="title" name="title" value="<%= book.title %>" class="form-control">
</div>
<div class="form-group">
<label for="body">Body</label>
<textarea id="body" name="body" rows="5" class="form-control"><%= book.contents %></textarea>
</div>
<div>
<a class="btn btn-primary" href="/api/book/<%= book._id %>">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
<!-- views/books/index.ejs -->
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<h2 class="mb-3">Board</h2>
<table class="board-table table table-sm border-bottom">
<thead class="thead-light">
<tr>
<th scope="col">Title</th>
<th scope="col" class="date">Date</th>
</tr>
</thead>
<tbody>
<% if(books == null || books.length == 0){ %>
<tr>
<td colspan=2> There is no data to show :( </td>
</tr>
<% } %>
<% books.forEach(function(book) { %>
<tr>
<td>
<a href="/api/book/<%= book._id %>"><div class="ellipsis"><%= book.title %></div></a>
</td>
<td class="date">
<span data-date="<%= book.createDate %>"></span> <!-- 1 -->
</td>
</tr>
<% }) %>
</tbody>
</table>
<div>
<a class="btn btn-primary" href="/api/book/new">New</a>
</div>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<nav aria-label="breadcrumb"> <!-- 1 -->
<ol class="breadcrumb p-1 pl-2 pr-2">
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-item"><a href="/api/page">Page</a></li>
<li class="breadcrumb-item active" aria-current="page">New Book</li>
</ol>
</nav>
<form action="/api/book" method="post">
<div class="form-group">
<label for="title">Title</label>
<input type="text" id="title" name="title" value="" class="form-control">
</div>
<div class="form-group">
<label for="body">Body</label>
<textarea id="body" name="body" rows="5" class="form-control"></textarea>
</div>
<div>
<a class="btn btn-primary" href="/api/book">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<nav aria-label="breadcrumb">
<ol class="breadcrumb p-1 pl-2 pr-2">
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-item"><a href="/api/page">Page</a></li>
<li class="breadcrumb-item active" aria-current="page"><%= book.title %></li>
</ol>
</nav>
<div class="card">
<h5 class="card-header p-2"><%= book.title %></h5>
<div class="row"> <!-- 1 -->
<div class="col-md-7 col-lg-8 col-xl-9 order-sm-2 order-md-1"> <!-- 1 -->
<div class="post-body p-2"><%= book.contents %></div>
</div>
<div class="col-md-5 col-lg-4 col-xl-3 order-sm-1 order-md-2"> <!-- 1 -->
<div class="post-info card m-2 p-2">
<div><span>Created</span> : <span data-date-time="<%= book.createDate %>"></span></div> <!-- 2 -->
<% if(book.createDate) { %>
<div><span>Updated</span> : <span data-date-time="<%= book.updateDate %>"></span></div> <!-- 2 -->
<% } %>
</div>
</div>
</div>
</div>
<div class="mt-3">
<a class="btn btn-primary" href="/api/book">Back</a>
<a class="btn btn-primary" href="/api/book/<%= book._id %>/edit">Edit</a>
<form action="/api/book/<%= book._id %>?_method=delete" method="post" class="d-inline">
<a class="btn btn-primary" href="javascript:void(0)" onclick="confirm('Do you want to delete this?')?this.parentElement.submit():null;">Delete</a>
</form>
</div>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<h2 class="mb-3">About</h2>
<P>이 사이트는 Like Project 임시 페이지 입니다. </p>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Login Example</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="../stylesheets/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="wrapper">
<form action="/auth/login" method="post" name="Login_Form" class="form-signin">
<h3 class="form-signin-heading">Welcome! Please Sign In</h3>
<input type="text" class="form-control" name="email" placeholder="Email Address" required="" autofocus="" />
<input type="password" class="form-control" name="password" placeholder="Password" required=""/>
<button class="btn btn-lg btn-primary btn-block" name="Submit" value="Login" type="Submit">Login</button>
</form>
</div>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<div class="jumbotron">
<h1>My Website</h1>
<P>제 웹사이트를 방문해 주셔서 감사합니다!</p>
</div>
</div>
</body>
</html>
\ No newline at end of file
<!-- views/partials/head.ejs -->
<meta name="viewport" content="width=device-width,initial-scale=1">
<!-- jquery & bootstrap -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- web font --> <!-- 1 -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet">
<!-- my css -->
<script src="/src/public/js/script.js"></script>
<title>My Website</title>
\ No newline at end of file
<nav class="navbar navbar-expand-sm navbar-light bg-light mb-3">
<div class="container">
<div class="navbar-brand"></a>Like</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item"><a href="/" class="nav-link">Home</a></li>
<li class="nav-item"><a href="/about" class="nav-link">About</a></li>
<li class="nav-item"><a href="/book" class="nav-link">Book</a></li>
<li class="nav-item"><a href="/page" class="nav-link">Page</a></li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a href="/auth/new" class="nav-link">Sign Up</a></li>
<li class="nav-item"><a href="/auth/login" class="nav-link">Login</a></li>
</ul>
</div>
</div>
</nav>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<nav aria-label="breadcrumb">
<ol class="breadcrumb p-1 pl-2 pr-2">
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-item"><a href="/book">Book</a></li>
<li class="breadcrumb-item"><a href="/page/<%= page._id %>"><%= page.title %></a></li>
<li class="breadcrumb-item active" aria-current="page">Edit Post</li>
</ol>
</nav>
<form action="/page<%= page._id %>?_method=put" method="patch">
<div class="form-group">
<label for="title">Title</label>
<input type="text" id="title" name="title" value="<%= page.title %>" class="form-control">
</div>
<div class="form-group">
<label for="body">Body</label>
<textarea id="body" name="body" rows="5" class="form-control"><%= page.contents %></textarea>
</div>
<div>
<a class="btn btn-primary" href="/page/<%= page._id %>">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
<!-- views/posts/index.ejs -->
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<h2 class="mb-3">Board</h2>
<table class="board-table table table-sm border-bottom">
<thead class="thead-light">
<tr>
<th scope="col">Title</th>
<th scope="col" class="date">Date</th>
</tr>
</thead>
<tbody>
<% if(page == null || page.length == 0){ %>
<tr>
<td colspan=2> There is no data to show :( </td>
</tr>
<% } %>
<% page.forEach(function(page) { %>
<tr>
<td>
<a href="/page/<%= page._id %>"><div class="ellipsis"><%= page.title %></div></a>
</td>
<td class="date">
<span data-date="<%= page.createDate %>"></span> <!-- 1 -->
</td>
</tr>
<% }) %>
</tbody>
</table>
<div>
<a class="btn btn-primary" href="/page/new">New</a>
</div>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<nav aria-label="breadcrumb"> <!-- 1 -->
<ol class="breadcrumb p-1 pl-2 pr-2">
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-item"><a href="/page">Board</a></li>
<li class="breadcrumb-item active" aria-current="page">New Post</li>
</ol>
</nav>
<form action="/page" method="post">
<div class="form-group">
<label for="title">Title</label>
<input type="text" id="title" name="title" value="" class="form-control">
</div>
<div class="form-group">
<label for="body">Body</label>
<textarea id="body" name="body" rows="5" class="form-control"></textarea>
</div>
<div>
<a class="btn btn-primary" href="/page">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<nav aria-label="breadcrumb">
<ol class="breadcrumb p-1 pl-2 pr-2">
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-item"><a href="/page">Page</a></li>
<li class="breadcrumb-item active" aria-current="page"><%= page.title %></li>
</ol>
</nav>
<div class="card">
<h5 class="card-header p-2"><%= page.title %></h5>
<div class="row"> <!-- 1 -->
<div class="col-md-7 col-lg-8 col-xl-9 order-sm-2 order-md-1"> <!-- 1 -->
<div class="post-body p-2"><%= page.contents %></div>
</div>
<div class="col-md-5 col-lg-4 col-xl-3 order-sm-1 order-md-2"> <!-- 1 -->
<div class="post-info card m-2 p-2">
<div><span>Created</span> : <span data-date-time="<%= page.createDate %>"></span></div> <!-- 2 -->
<% if(page.updateDate) { %>
<div><span>Updated</span> : <span data-date-time="<%= page.updateDate %>"></span></div> <!-- 2 -->
<% } %>
</div>
</div>
</div>
</div>
<div class="mt-3">
<a class="btn btn-primary" href="/page">Back</a>
<a class="btn btn-primary" href="/page/<%= page._id %>/edit">Edit</a>
<form action="/page/<%= page._id %>/_method=delete" method="post" class="d-inline">
<a class="btn btn-primary" href="#" onclick="confirm('Do you want to delete this?')?this.parentElement.submit():null;">Delete</a>
</form>
</div>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<h3 class="mb-3">Edit User</h3>
<form action="/auth/users/<%= user.username %>?_method=put" method="post">
<div class="form-group row">
<label for="currentPassword" class="col-sm-3 col-form-label">Current Password*</label>
<div class="col-sm-9 col-sm-offset-3">
<input type="password" id="currentPassword" name="currentPassword" value="" class="form-control">
</div>
</div>
<hr></hr>
<div class="form-group row">
<label for="username" class="col-sm-3 col-form-label">Username*</label>
<div class="col-sm-9">
<input type="text" id="username" name="username" value="<%= user.nickname %>" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-3 col-form-label">Name*</label>
<div class="col-sm-9">
<input type="text" id="name" name="name" value="<%= user.email %>" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="email" class="col-sm-3 col-form-label">Email</label>
<div class="col-sm-9">
<input type="text" id="email" name="email" value="<%= user.email %>" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="newPassword" class="col-sm-3 col-form-label">New Password</label>
<div class="col-sm-9 col-sm-offset-3">
<input type="password" id="newPassword" name="newPassword" value="" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="passwordConfirmation" class="col-sm-3 col-form-label">Password Confirmation</label>
<div class="col-sm-9 col-sm-offset-3">
<input type="password" id="passwordConfirmation" name="passwordConfirmation" value="" class="form-control">
</div>
</div>
<p>
<small>*Required</small>
</p>
<div class="buttons">
<a class="btn btn-primary" href="/auth/users/<%= user.username %>">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
File mode changed
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<h3 class="contentBoxTop mb-3">New User</h3>
<form action="/auth/signin" method="post">
<div class="form-group row">
<label for="nickname" class="col-sm-3 col-form-label">Username*</label>
<div class="col-sm-9">
<input type="text" id="nickname" name="nickname" value="" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="email" class="col-sm-3 col-form-label">Email</label>
<div class="col-sm-9">
<input type="text" id="email" name="email" value="" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-sm-3 col-form-label">Password*</label>
<div class="col-sm-9">
<input type="password" id="password" name="password" value="" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="passwordConfirmation" class="col-sm-3 col-form-label">Password Confirmation*</label>
<div class="col-sm-9 col-sm-offset-3">
<input type="password" id="passwordConfirmation" name="passwordConfirmation" value="" class="form-control">
</div>
</div>
<p>
<small>*Required</small>
</p>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<h3 class="contentBoxTop">usefname</h3>
<form class="user-form" action="/users" method="post">
<fieldset disabled>
<div class="form-group row">
<label for="email" class="col-sm-3 col-form-label">Email</label>
<div class="col-sm-9">
<input class="form-control" type="text" id="email" name="email" value="<%= 9 %>">
</div>
</div>
</fieldset>
</form>
<div>
<a class="btn btn-primary" href="/auth/users">Back</a>
<a class="btn btn-primary" href="/auth/users/<%= user.email %>/edit">Edit</a>
<form action="/users/<%= user.email %>?_method=delete" method="post" class="d-inline">
<a class="btn btn-primary" href="javascript:void(0)" onclick="confirm('Do you want to delete this?')?this.parentElement.submit():null;">Delete</a>
</form>
</div>
</div>
</body>
</html>
\ No newline at end of file