박유빈

fix the post error and login rendering error

......@@ -17,7 +17,7 @@
],
"type": "pwa-node"
},
{
{"name": "Launch ",
"program": "${workspaceFolder}/app.js",
"request": "launch",
"skipFiles": [
......
This diff is collapsed. Click to expand it.
......@@ -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",
......@@ -27,6 +28,7 @@
"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",
......
require('dotenv').config()
const Router = require("@koa/router");
const authCtrl = require("./auth.ctrl");
......@@ -40,7 +42,7 @@ auth.get('/new', async (ctx) => {
auth.get('/', async (ctx) => {
try{
const user = await User.find({}).sort({email:-1}).exec();//1 오름차순 -1내림차순
const users = await User.find({}).sort({email:-1}).exec();//1 오름차순 -1내림차순
ctx.render('users/index', {users});
}catch(e){
ctx.throw(500, e);
......@@ -50,7 +52,7 @@ auth.get('/', async (ctx) => {
// show
auth.get('/:username', async (ctx) => {
auth.get('/:id', async (ctx) => {
const user = await User.findOne({_id:ctx.params._id});
ctx.render('users/show', {user});
});
......@@ -58,14 +60,14 @@ auth.get('/:username', async (ctx) => {
// edit
auth.get('/:username/edit', async (ctx) => {
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('/:username', async (ctx) => {
auth.post('/:id', async (ctx) => {
await User.findOne({username:ctx.params.username}).select('password').exec();
......@@ -84,15 +86,16 @@ auth.get('/:username', async (ctx) => {
// destroy
auth.delete('/:username',async (ctx) => {
try{
var username = ctx.params.username;
await User.deleteOne({username:username});
ctx.redirect('/users');
}catch(e){
ctx.throw(500, e);
}
});
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
......
......@@ -5,16 +5,16 @@ 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({createDate: -1})
.exec();
await ctx.render('books/index', {book:book});
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);
console.log('get /book/booklist');
}
}
......@@ -66,17 +66,13 @@ exports.addBook = async (ctx) => {
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;
};
......@@ -95,16 +92,20 @@ exports.updateBook = 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
else{
ctx.request.body.cover = ""
}
var book = ctx.request.body; //require books's _id
try {
const mybook = await Book.findOne({ _id: book._id });
if(ctx.state.user._id == mybook.author){
mybook.updateB(book);
ctx.body = book._id;
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);
......@@ -116,10 +117,9 @@ exports.updateBook = async (ctx) => {
};
exports.deleteBook = async (ctx) => {
let bookid = ctx.query.id;
let bookid =ctx.params.id;
try {
//var foundB = await Book.findById(bookid).exec();
......
......@@ -2,15 +2,153 @@ 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)
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');
});
......
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;
......
......@@ -4,6 +4,7 @@ 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
/*
......@@ -32,7 +33,7 @@ page.get('/recipe/scroll', pageCtrl.scrollPage); // video list sorted by 추
page.get('/new', async (ctx) => {
ctx.render('posts/new');
await ctx.render('posts/new');
});
// create
......@@ -46,12 +47,13 @@ page.get('/recipe/scroll', pageCtrl.scrollPage); // video list sorted by 추
// show
page.get('/:id', async (ctx, next) => {
const page = await Page.findOne({_id:ctx.params.id});
ctx.render('posts/show', {page});
console.log('찾은 페이지',page);
ctx.render('posts/show', {page:page,user:ctx.state.user});
});
// update
page.post('/:id', async (ctx, next) => {
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);
......
body {
font-family: 'Open Sans', sans-serif;
}
.breadcrumb-item {
font-size: 0.8em !important;
}
.ellipsis{
display: block;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis; /* 1 */
}
.board-table {
table-layout: fixed;
}
.board-table .date {
width: 100px;
}
.post-body{
white-space: pre-line; /* 2 */
}
.post-info{
font-size: 0.8em;
}
\ No newline at end of file
......@@ -14,6 +14,11 @@ 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 = {
......@@ -39,7 +44,7 @@ mongoose.connect(process.env.MONGO_URI).then(
app
.use(router.routes())
.use(router.allowedMethods());
*/
render(app, {
root: path.join(__dirname, 'views'),
......@@ -48,46 +53,64 @@ app
cache: false,
debug: true
});
*/
// app.use(async function (ctx) {
// await ctx.render('home/welcome');
// });
app
.use(jwtMiddleware)
.use(bodyParser()) // bodyParser는 라우터 코드보다 상단에 있어야 합니다.
.use(router.routes())
.use(router.allowedMethods())
.use(passport.initialize());
.use(bodyParser()); // bodyParser는 라우터 코드보다 상단에 있어야 합니다.
render(app, {
root: path.join(__dirname, 'views'),
layout: false,
viewExt: 'ejs',
cache: false,
debug: true
});
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 =>{
await ctx.render('home/about');
ctx.render('home/about');
});
router.get('/login', async ctx =>{
await ctx.render('users/index');
router.get('/auth', async ctx =>{
ctx.render('users/login');
});
router.get('/signup', async ctx =>{
await ctx.render('users/new');
});
//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.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());
......@@ -95,10 +118,10 @@ 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);
});
*/
\ No newline at end of file
*/
\ No newline at end of file
......
......@@ -10,3 +10,13 @@ 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
......
/* 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;
}
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
......@@ -9,26 +9,26 @@
<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">Board</a></li>
<li class="breadcrumb-item"><a href="/api/page/<%= page._id %>"><%= page.title %></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/page/<%= page._id %>?_method=put" method="post">
<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="<%= page.title %>" class="form-control">
<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"><%= post.contents %></textarea>
<textarea id="body" name="body" rows="5" class="form-control"><%= book.contents %></textarea>
</div>
<div>
<a class="btn btn-primary" href="/api/page/<%= page._id %>">Back</a>
<a class="btn btn-primary" href="/api/book/<%= book._id %>">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
......
<!-- views/books/index.ejs -->
<!DOCTYPE html>
<html>
<head>
......@@ -20,18 +21,18 @@
</thead>
<tbody>
<% if(page == null || page.length == 0){ %>
<% if(books == null || books.length == 0){ %>
<tr>
<td colspan=2> There is no data to show :( </td>
</tr>
<% } %>
<% page.forEach(function(page) { %>
<% books.forEach(function(book) { %>
<tr>
<td>
<a href="/api/page/<%= page._id %>"><div class="ellipsis"><%= page.title %></div></a>
<a href="/api/book/<%= book._id %>"><div class="ellipsis"><%= book.title %></div></a>
</td>
<td class="date">
<span data-date="<%= page.createDate %>"></span> <!-- 1 -->
<span data-date="<%= book.createDate %>"></span> <!-- 1 -->
</td>
</tr>
<% }) %>
......@@ -40,7 +41,7 @@
</table>
<div>
<a class="btn btn-primary" href="/api/page/new">New</a>
<a class="btn btn-primary" href="/api/book/new">New</a>
</div>
</div>
......
......@@ -11,12 +11,12 @@
<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">Board</a></li>
<li class="breadcrumb-item active" aria-current="page">New Post</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/page/" method="post">
<form action="/api/book" method="post">
<div class="form-group">
<label for="title">Title</label>
......@@ -29,7 +29,7 @@
</div>
<div>
<a class="btn btn-primary" href="/api/page">Back</a>
<a class="btn btn-primary" href="/api/book">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
......
......@@ -11,24 +11,24 @@
<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/book">Book</a></li>
<li class="breadcrumb-item active" aria-current="page"><%= page.title %></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"><%= page.title %></h5>
<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"><%= page.contents %></div>
<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="<%= page.createDate %>"></span></div> <!-- 2 -->
<% if(page.updateDate) { %>
<div><span>Updated</span> : <span data-date-time="<%= page.updateDate %>"></span></div> <!-- 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>
......@@ -37,9 +37,9 @@
</div>
<div class="mt-3">
<a class="btn btn-primary" href="/api/page">Back</a>
<a class="btn btn-primary" href="/api/page/<%= page._id %>/edit">Edit</a>
<form action="/api/page/<%= page._id %>?_method=delete" method="post" class="d-inline">
<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>
......
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<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>
<h3 class="mb-3">Login</h3>
<form class="user-form" action="/login" method="post">
<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="<%= username %>" class="form-control <%= (errors.username)?'is-invalid':'' %>">
<% if(errors.username){ %>
<span class="invalid-feedback"><%= errors.username %></span>
<% } %>
</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 <%= (errors.password)?'is-invalid':'' %>">
<% if(errors.password){ %>
<span class="invalid-feedback"><%= errors.password %></span>
<% } %>
</div>
</div>
<% if(errors.login){ %>
<div class="invalid-feedback d-block"><%= errors.login %></div>
<% } %>
<div class="mt-3">
<input class="btn btn-primary" type="submit" value="Submit">
</div>
<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>
</body>
</div>
</body>
</html>
\ No newline at end of file
......
......@@ -12,6 +12,6 @@
<link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet">
<!-- my css -->
<script src="/src/api/page/script.js"></script>
<script src="/src/public/js/script.js"></script>
<title>My Website</title>
\ No newline at end of file
......
......@@ -8,13 +8,13 @@
<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="/api/book" class="nav-link">Book</a></li>
<li class="nav-item"><a href="/api/page" class="nav-link">Page</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="/api/auth" class="nav-link">Sign Up</a></li>
<li class="nav-item"><a href="/api/auth/new" class="nav-link">Login</a></li>
<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>
......
......@@ -11,13 +11,13 @@
<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">Board</a></li>
<li class="breadcrumb-item"><a href="/api/page/<%= page._id %>"><%= page.title %></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="/api/page/<%= page._id %>?_method=put" method="post">
<form action="/page<%= page._id %>?_method=put" method="patch">
<div class="form-group">
<label for="title">Title</label>
......@@ -26,11 +26,11 @@
<div class="form-group">
<label for="body">Body</label>
<textarea id="body" name="body" rows="5" class="form-control"><%= post.contents %></textarea>
<textarea id="body" name="body" rows="5" class="form-control"><%= page.contents %></textarea>
</div>
<div>
<a class="btn btn-primary" href="/api/page/<%= page._id %>">Back</a>
<a class="btn btn-primary" href="/page/<%= page._id %>">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
......
......@@ -30,7 +30,7 @@
<% page.forEach(function(page) { %>
<tr>
<td>
<a href="/api/page/<%= page._id %>"><div class="ellipsis"><%= page.title %></div></a>
<a href="/page/<%= page._id %>"><div class="ellipsis"><%= page.title %></div></a>
</td>
<td class="date">
<span data-date="<%= page.createDate %>"></span> <!-- 1 -->
......@@ -42,7 +42,7 @@
</table>
<div>
<a class="btn btn-primary" href="/api/page/new">New</a>
<a class="btn btn-primary" href="/page/new">New</a>
</div>
</div>
......
......@@ -11,12 +11,12 @@
<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">Board</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="/api/page/" method="post">
<form action="/page" method="post">
<div class="form-group">
<label for="title">Title</label>
......@@ -29,7 +29,7 @@
</div>
<div>
<a class="btn btn-primary" href="/api/page">Back</a>
<a class="btn btn-primary" href="/page">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
......
......@@ -5,6 +5,7 @@
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
......@@ -12,7 +13,7 @@
<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/book">Book</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>
......@@ -38,10 +39,10 @@
</div>
<div class="mt-3">
<a class="btn btn-primary" href="/api/page">Back</a>
<a class="btn btn-primary" href="/api/page/<%= page._id %>/edit">Edit</a>
<form action="/api/page/<%= page._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>
<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>
......
......@@ -11,7 +11,7 @@
<h3 class="mb-3">Edit User</h3>
<form action="/api/auth/users/<%= user.username %>?_method=put" method="post">
<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>
......@@ -62,7 +62,7 @@
</p>
<div class="buttons">
<a class="btn btn-primary" href="/api/auth/users/<%= user.username %>">Back</a>
<a class="btn btn-primary" href="/auth/users/<%= user.username %>">Back</a>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
......
<!DOCTYPE html>
<html>
<head>
<%- include('../partials/head') %>
</head>
<body>
<%- include('../partials/nav') %>
<div class="container mb-3">
<h3 class="mb-3">Users</h3>
<ul class="list-group">
<% if(user == null || user.length == 0){ %>
<li class="list-group-item"> There is no user yet.</li>
<% } %>
<% user.forEach(function(user) { %>
<li class="list-group-item">
<a href="/api/auth/userlist/<%= user._id %>"><%= user.nickname %></a>
</li>
<% }) %>
</ul>
</div>
</body>
</html>
\ No newline at end of file
......@@ -12,7 +12,7 @@
<h3 class="contentBoxTop mb-3">New User</h3>
<form action="/api/auth/signin" method="post">
<form action="/auth/signin" method="post">
<div class="form-group row">
<label for="nickname" class="col-sm-3 col-form-label">Username*</label>
......
......@@ -10,28 +10,23 @@
<div class="container mb-3">
<h3 class="contentBoxTop"><%= user.nickname</h3>
<h3 class="contentBoxTop">usefname</h3>
<form class="user-form" action="/users" method="post">
<fieldset disabled>
<div class="form-group row">
<label for="name" class="col-sm-3 col-form-label">Name</label>
<div class="col-sm-9">
<input class="form-control" type="text" id="name" name="name" value="<%= user.name %>">
</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 class="form-control" type="text" id="email" name="email" value="<%= user.email %>">
<input class="form-control" type="text" id="email" name="email" value="<%= 9 %>">
</div>
</div>
</fieldset>
</form>
<div>
<a class="btn btn-primary" href="/api/auth/users">Back</a>
<a class="btn btn-primary" href="/api/auth/users/<%= user.email %>/edit">Edit</a>
<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>
......