From ccd8349d35f0087932fc365459edaafee53f71f5 Mon Sep 17 00:00:00 2001
From: Diego Solari
Date: Fri, 7 May 2021 16:20:58 -0400
Subject: [PATCH 1/5] feat: code review
---
.DS_Store | Bin 0 -> 6148 bytes
src/assets/styles/index.scss | 40 ++++++++++++++++++
...20210506014608-add-description-to-books.js | 19 +++++++++
src/models/book.js | 12 ++++++
src/routes/authors.js | 1 +
src/routes/books.js | 17 +++++++-
src/seeds/20210420000337-add-books.js | 12 ++++--
src/views/authors/show.html.ejs | 4 +-
src/views/books/new.html.ejs | 8 ++++
src/views/books/new_for_authors.html.ejs | 8 ++++
src/views/books/show.html.ejs | 12 ++++++
11 files changed, 127 insertions(+), 6 deletions(-)
create mode 100644 .DS_Store
create mode 100644 src/migrations/20210506014608-add-description-to-books.js
create mode 100644 src/views/books/show.html.ejs
diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..7bf23ec9001796a615354d0448038dbcb0154e82
GIT binary patch
literal 6148
zcmeHKJ5Iw;5S%3`B0-Uo@?C)&SW!3u2LKVL3s}NR?<(iwXv}_u5;@S(pjl~m-dpdy
zCr{z^0RbNjy_YUvD+T)zR$Jmd%
z!|O1_SqqH#!0tSC{X}J@fE17dQa}nwf!`Eh&vskgCMrq+DIf*D74YvvqdRtmQ(}BN
z7-9qCCsP>k6mDq{HH7o>MnlO(+((GvA^d
z)+H)R0V!~)z#_M6@BfeVALjo{l6F!+3j8YtY`J~fZum;oTW2rly|&R`=w9(T=(Cc6=X2S=W5c=Uw5H7mri^f33h5DnlCy
literal 0
HcmV?d00001
diff --git a/src/assets/styles/index.scss b/src/assets/styles/index.scss
index 5e935b2..fccda7b 100644
--- a/src/assets/styles/index.scss
+++ b/src/assets/styles/index.scss
@@ -1,2 +1,42 @@
@import './layout';
@import './hello';
+
+
+.books-container {
+ width: 80vw;
+ margin: 10 auto;
+ .book-attributes-container {
+ position: relative;
+ height: 100%;
+ width: 100%;
+ padding: 4px 7px;
+ .book-title {
+ font-size: 1.3rem;
+ font-weight: bold;
+ background-color: rgba(51, 83, 189, 0.904);
+ color: white;
+ padding: 5px 10px;
+ border-radius: 5px;
+ margin: 0;
+ }
+ .book-pages {
+ position: absolute;
+ top: 8px;
+ right: 15px;
+ font-size: 0.9rem;
+ font-weight: 500;
+ color: white;
+ padding: 3px;
+ border-radius: 5px;
+ margin: 2px 0;
+ }
+ .book-description {
+ font-size: 1.1rem;
+ background-color: rgba(150, 153, 161, 0.644);
+ color: white;
+ padding: 5px 10px 5px 20px;
+ border-radius: 5px;
+ margin: 0;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/migrations/20210506014608-add-description-to-books.js b/src/migrations/20210506014608-add-description-to-books.js
new file mode 100644
index 0000000..dda4caa
--- /dev/null
+++ b/src/migrations/20210506014608-add-description-to-books.js
@@ -0,0 +1,19 @@
+'use strict';
+
+module.exports = {
+ up: async (queryInterface, Sequelize) => [
+ await queryInterface.addColumn('books', 'description', {
+ type: Sequelize.TEXT,
+ allowNull: false,
+ }),
+ await queryInterface.addColumn('books', 'pages', {
+ type: Sequelize.INTEGER,
+ allowNull: false,
+ }),
+ ],
+
+ down: async (queryInterface) => [
+ await queryInterface.removeColumn('books', 'description'),
+ await queryInterface.removeColumn('books', 'pages'),
+ ],
+};
diff --git a/src/models/book.js b/src/models/book.js
index 6297dec..bbfe46a 100644
--- a/src/models/book.js
+++ b/src/models/book.js
@@ -28,6 +28,18 @@ module.exports = (sequelize, DataTypes) => {
},
},
authorId: DataTypes.INTEGER,
+ description: {
+ type: DataTypes.STRING,
+ validate: {
+ notEmpty: true,
+ },
+ },
+ pages: {
+ type: DataTypes.INTEGER,
+ validate: {
+ notEmpty: true,
+ },
+ },
},
{
sequelize,
diff --git a/src/routes/authors.js b/src/routes/authors.js
index e63a5e4..a461b09 100644
--- a/src/routes/authors.js
+++ b/src/routes/authors.js
@@ -34,6 +34,7 @@ router.get('authors.show', '/:id', async (ctx) => {
// const books = await author.getBooks();
await ctx.render('authors/show', {
author,
+ bookDetailsPath: (bookId) => ctx.router.url('books.show', { id: bookId }),
newBookPath: ctx.router.url('books_for_authors.new', {
authorId: author.id,
}),
diff --git a/src/routes/books.js b/src/routes/books.js
index 0ce2dc6..75d65d5 100644
--- a/src/routes/books.js
+++ b/src/routes/books.js
@@ -2,6 +2,12 @@ const KoaRouter = require('koa-router');
const router = new KoaRouter();
+router.param('id', async (id, ctx, next) => {
+ ctx.state.book = await ctx.orm.book.findByPk(ctx.params.id);
+ if (!ctx.state.book) return ctx.throw(404);
+ return next();
+});
+
router.get('books.new', '/new', async (ctx) => {
const book = ctx.orm.book.build();
const authorList = await ctx.orm.author.findAll();
@@ -15,7 +21,7 @@ router.get('books.new', '/new', async (ctx) => {
router.post('books.create', '/', async (ctx) => {
const book = ctx.orm.book.build(ctx.request.body);
try {
- await book.save({ field: ['title', 'publication', 'authorId'] });
+ await book.save({ field: ['title', 'publication', 'authorId', 'description', 'pages'] });
ctx.redirect(ctx.router.url('authors.show', { id: book.authorId }));
} catch (ValidationError) {
const authorList = await ctx.orm.author.findAll();
@@ -28,4 +34,13 @@ router.post('books.create', '/', async (ctx) => {
}
});
+router.get('books.show', '/:id', async (ctx) => {
+ const { book } = ctx.state;
+ await ctx.render('books/show', {
+ book,
+ backToAuthorPath: ctx.router.url('authors.show', { id: book.authorId }),
+ notice: ctx.flashMessage.notice,
+ });
+});
+
module.exports = router;
diff --git a/src/seeds/20210420000337-add-books.js b/src/seeds/20210420000337-add-books.js
index c9887a9..1559760 100644
--- a/src/seeds/20210420000337-add-books.js
+++ b/src/seeds/20210420000337-add-books.js
@@ -7,25 +7,31 @@ module.exports = {
booksArray.push({
title: 'Harry Potter y la piedra filosofal',
publication: 1997,
- authorId: 1,
+ authorId: 8, // Fix this according to your db
createdAt: new Date(),
updatedAt: new Date(),
+ description: 'Harry Potter se ha quedado huérfano y vive en casa de sus abominables tíos y el insoportable primo Dudley. Harry se siente muy triste y solo, hasta que un buen día recibe una carta que cambiará su vida para siempre. En ella le comunican que ha sido aceptado como alumno en el Colegio Hogwarts de Magia.',
+ pages: 800,
});
booksArray.push({
title: 'Harry Potter y la camara secreta',
publication: 1998,
- authorId: 1,
+ authorId: 8, // Fix this according to your db
createdAt: new Date(),
updatedAt: new Date(),
+ description: 'La trama sigue el segundo año de Harry Potter en el Colegio Hogwarts de Magia y Hechicería, durante el cual una serie de mensajes en las paredes de los pasillos de la escuela advierten que la Cámara de los Secretos ha sido abierta y que el "heredero de Slytherin" matará a todos los alumnos que no provengan de familias con sangre mágica.',
+ pages: 940,
});
booksArray.push({
title: 'Los juegos del hambre',
publication: 2008,
- authorId: 2,
+ authorId: 9, // Fix this according to your db
createdAt: new Date(),
updatedAt: new Date(),
+ description: 'Sin libertad y en la pobreza, nadie puede salir de los límites de su distrito. Sólo una chica de 16 años, Katniss Everdeen, osa desafiar las normas para conseguir comida. Sus prinicipios se pondrán a prueba con “Los juegos del hambre”, espectáculo televisado que el Capitolio organiza para humillar a la población.',
+ pages: 560,
});
return queryInterface.bulkInsert('books', booksArray);
diff --git a/src/views/authors/show.html.ejs b/src/views/authors/show.html.ejs
index b727228..1e32126 100644
--- a/src/views/authors/show.html.ejs
+++ b/src/views/authors/show.html.ejs
@@ -1,12 +1,12 @@
<% if (notice) { %>
<%= notice %>
-<% } else {%>
+<% } else { %>
<%= author.firstName %> <%= author.lastName %>
<%= author.lastName %> Nació en <%= author.birthDate %>, ...
Libros:
<% author.books.forEach((book) => { %>
- - <%= book.title %>
+ - <%= book.title %>
<% }) %>
Agregar libro
diff --git a/src/views/books/new.html.ejs b/src/views/books/new.html.ejs
index 84f73ab..6084fe1 100644
--- a/src/views/books/new.html.ejs
+++ b/src/views/books/new.html.ejs
@@ -26,6 +26,14 @@
<% }) %>
+
+
+
+
+
+
+
+
diff --git a/src/views/books/new_for_authors.html.ejs b/src/views/books/new_for_authors.html.ejs
index 5f24166..fc8d6ac 100644
--- a/src/views/books/new_for_authors.html.ejs
+++ b/src/views/books/new_for_authors.html.ejs
@@ -16,6 +16,14 @@
+
+
+
+
+
+
+
+
diff --git a/src/views/books/show.html.ejs b/src/views/books/show.html.ejs
new file mode 100644
index 0000000..d2e5da8
--- /dev/null
+++ b/src/views/books/show.html.ejs
@@ -0,0 +1,12 @@
+<% if (notice) { %>
+ <%= notice %>
+<% } else {%>
+
+
+
<%= book.title %>
+
Número de páginas: <%= book.pages %>
+
<%= book.description %>
+
+
+<% } %>
+Volver al Autor
\ No newline at end of file
From f5879805723d42b18a9c6d88d2d1e074b6d20202 Mon Sep 17 00:00:00 2001
From: valeeeriquelme <37518300+valeeeriquelme@users.noreply.github.com>
Date: Thu, 6 May 2021 20:04:43 -0400
Subject: [PATCH 2/5] =?UTF-8?q?Agregar=20manejo=20de=20sesi=C3=B3n=20para?=
=?UTF-8?q?=20el=20usuario=20=20(#10)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feature login added :watermelon:
* Update README.md
* fix:add faker to package.json
* fix:add faker to package.json
* fix:add faker to package.json
* fix:add test user to seed
* fix: add envrc to gitignore
* fix: delete .envrc
* fix src/migrations/20210503202812-create-user.js
Co-authored-by: Sebastián Vicencio
* fix src/models/user.js
Co-authored-by: Sebastián Vicencio
* fix src/routes/session.js
Co-authored-by: Sebastián Vicencio
* fix src/views/layout.html.ejs
Co-authored-by: Sebastián Vicencio
* fix src/views/session/new.html.ejs
Co-authored-by: Sebastián Vicencio
* fix routes.js
* Update src/routes.js
Co-authored-by: Sebastián Vicencio
* fix session.js
* fix session.js
* fix:add faker to package.json
Co-authored-by: Kelsey Franken
Co-authored-by: kelseyfranken <42187498+kelseyfranken@users.noreply.github.com>
Co-authored-by: valeeeriquelme
Co-authored-by: Sebastián Vicencio
---
.gitignore | 5 ++-
README.md | 4 ++
package.json | 1 +
src/migrations/20210503202812-create-user.js | 36 +++++++++++++++
src/models/user.js | 46 ++++++++++++++++++++
src/routes.js | 22 ++++++++++
src/routes/session.js | 34 +++++++++++++++
src/seeds/20210503205007-add-users.js | 31 +++++++++++++
src/views/layout.html.ejs | 14 ++++++
src/views/session/new.html.ejs | 17 ++++++++
yarn.lock | 5 +++
11 files changed, 214 insertions(+), 1 deletion(-)
create mode 100755 src/migrations/20210503202812-create-user.js
create mode 100755 src/models/user.js
create mode 100644 src/routes/session.js
create mode 100755 src/seeds/20210503205007-add-users.js
create mode 100644 src/views/session/new.html.ejs
diff --git a/.gitignore b/.gitignore
index 4f43fc1..dcdc86a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -105,4 +105,7 @@ dist
# Zone Identifiers
*.Identifier
-**/.Identifier
\ No newline at end of file
+**/.Identifier
+
+#envrc
+.envrc
\ No newline at end of file
diff --git a/README.md b/README.md
index ee74ffc..e94a67a 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,6 @@
# Gud Reads
Código de ejemplo en el contexto de las cápsulas desarrolladas para demostrar usos básicos del template del curso.
+
+## Usuario de prueba para login:
+- email: Jalen83@gmail.com
+- contraseña: KMsnQpv4
diff --git a/package.json b/package.json
index 3fc2275..8126d44 100644
--- a/package.json
+++ b/package.json
@@ -46,6 +46,7 @@
"dependencies": {
"core-js": "^3.6.5",
"dotenv": "^8.2.0",
+ "faker": "^5.5.3",
"koa": "^2.13.0",
"koa-body": "^4.2.0",
"koa-ejs": "^4.3.0",
diff --git a/src/migrations/20210503202812-create-user.js b/src/migrations/20210503202812-create-user.js
new file mode 100755
index 0000000..d7aa1e6
--- /dev/null
+++ b/src/migrations/20210503202812-create-user.js
@@ -0,0 +1,36 @@
+'use strict';
+module.exports = {
+ up: async (queryInterface, Sequelize) => {
+ await queryInterface.createTable('users', {
+ id: {
+ allowNull: false,
+ autoIncrement: true,
+ primaryKey: true,
+ type: Sequelize.INTEGER
+ },
+ firstName: {
+ type: Sequelize.STRING
+ },
+ lastName: {
+ type: Sequelize.STRING
+ },
+ email: {
+ type: Sequelize.STRING
+ },
+ password: {
+ type: Sequelize.STRING
+ },
+ createdAt: {
+ allowNull: false,
+ type: Sequelize.DATE
+ },
+ updatedAt: {
+ allowNull: false,
+ type: Sequelize.DATE
+ }
+ });
+ },
+ down: async (queryInterface, Sequelize) => {
+ await queryInterface.dropTable('users');
+ }
+};
diff --git a/src/models/user.js b/src/models/user.js
new file mode 100755
index 0000000..97cdbfa
--- /dev/null
+++ b/src/models/user.js
@@ -0,0 +1,46 @@
+'use strict';
+const {
+ Model
+} = require('sequelize');
+module.exports = (sequelize, DataTypes) => {
+ class user extends Model {
+ /**
+ * Helper method for defining associations.
+ * This method is not a part of Sequelize lifecycle.
+ * The `models/index` file will call this method automatically.
+ */
+ static associate(models) {
+ // define association here
+ }
+ };
+ user.init({
+ firstName: {
+ type: DataTypes.STRING,
+ validate: {
+ notEmpty: true,
+ },
+ },
+ lastName: {
+ type: DataTypes.STRING,
+ validate: {
+ notEmpty: true,
+ },
+ },
+ email: {
+ type: DataTypes.STRING,
+ validate: {
+ notEmpty: true,
+ },
+ },
+ password: {
+ type: DataTypes.STRING,
+ validate: {
+ notEmpty: true,
+ },
+ }
+ }, {
+ sequelize,
+ modelName: 'user',
+ });
+ return user;
+};
diff --git a/src/routes.js b/src/routes.js
index 3b33d6a..b0a2484 100644
--- a/src/routes.js
+++ b/src/routes.js
@@ -5,13 +5,35 @@ const index = require('./routes/index');
const authors = require('./routes/authors');
const books = require('./routes/books');
const booksForAuthors = require('./routes/booksForAuthors');
+const session = require('./routes/session');
const router = new KoaRouter();
+router.use(async (ctx, next) => {
+ if (ctx.session.currentUserId){
+ ctx.state.currentUser = await ctx.orm.user.findByPk(ctx.session.currentUserId);
+ }
+ return next();
+ });
+
+router.use(async (ctx, next) => {
+ Object.assign(ctx.state, {
+ paths: {
+ destroySession: ctx.router.url('session.destroy'),
+ newSession: ctx.router.url('session.new'),
+
+ },
+ });
+ return next();
+ });
+
+
router.use('/', index.routes());
router.use('/hello', hello.routes());
router.use('/authors', authors.routes());
router.use('/books', books.routes());
router.use('/authors/:authorId/books', booksForAuthors.routes());
+router.use('/session', session.routes());
+
module.exports = router;
diff --git a/src/routes/session.js b/src/routes/session.js
new file mode 100644
index 0000000..64b24ea
--- /dev/null
+++ b/src/routes/session.js
@@ -0,0 +1,34 @@
+const KoaRouter = require('koa-router');
+
+const router = new KoaRouter();
+
+router.get('session.new', '/new', (ctx) => ctx.render(
+ 'session/new',{
+ submitPath: ctx.router.url('session.create'),
+ }
+));
+
+router.post('session.create', '/', async (ctx) => {
+ const { email, password } = ctx.request.body;
+ const user = await ctx.orm.user.findOne({ where: { email } });
+
+ /* TODO: replace plain-text password comparison with encrypted version */
+ const authenticated = user && password === user.password;
+ if (user && authenticated) {
+ ctx.session.currentUserId = user.id;
+ ctx.redirect('/');
+ } else {
+ await ctx.render('session/new', {
+ error: 'Email y/o contraseña incorrectos',
+ email,
+ submitPath: ctx.router.url('session.create'),
+ });
+ }
+ });
+
+router.delete('session.destroy', '/', (ctx) => {
+ ctx.session.currentUserId = null;
+ ctx.redirect('/');
+ });
+
+module.exports = router;
diff --git a/src/seeds/20210503205007-add-users.js b/src/seeds/20210503205007-add-users.js
new file mode 100755
index 0000000..38f7317
--- /dev/null
+++ b/src/seeds/20210503205007-add-users.js
@@ -0,0 +1,31 @@
+'use strict';
+const faker = require('faker');
+
+const users = [...Array(10)].map((user) => (
+ {
+ firstName: faker.name.firstName(),
+ lastName: faker.name.lastName(),
+ email: faker.internet.email(),
+ password: faker.internet.password(8),
+ createdAt: new Date(),
+ updatedAt: new Date()
+ }
+))
+
+users.push({
+ firstName: 'Jalen',
+ lastName: '87',
+ email: 'Jalen83@gmail.com',
+ password: 'KMsnQpv4',
+ createdAt: new Date(),
+ updatedAt: new Date()
+})
+
+module.exports = {
+ up: (queryInterface, Sequelize) => {
+ return queryInterface.bulkInsert('users', users, {});
+ },
+ down: (queryInterface, Sequelize) => {
+ return queryInterface.bulkDelete('users', null, {});
+ }
+};
diff --git a/src/views/layout.html.ejs b/src/views/layout.html.ejs
index 418fcc5..91681eb 100644
--- a/src/views/layout.html.ejs
+++ b/src/views/layout.html.ejs
@@ -14,6 +14,20 @@
+
+
+
+ <% if (locals.currentUser) { %>
+
Hola <%= currentUser.email %>!
+
+
+ <% } else { %>
+
Iniciar sesión
+ <% } %>
+
<%- body %>
diff --git a/src/views/session/new.html.ejs b/src/views/session/new.html.ejs
new file mode 100644
index 0000000..cbe77d9
--- /dev/null
+++ b/src/views/session/new.html.ejs
@@ -0,0 +1,17 @@
+
diff --git a/yarn.lock b/yarn.lock
index 02712cd..8d5091c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3773,6 +3773,11 @@ extsprintf@^1.2.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz"
+faker@^5.5.3:
+ version "5.5.3"
+ resolved "https://registry.yarnpkg.com/faker/-/faker-5.5.3.tgz#c57974ee484431b25205c2c8dc09fda861e51e0e"
+ integrity sha512-wLTv2a28wjUyWkbnX7u/ABZBkUkIF2fCd73V6P2oFqEGEktDfzWx4UxrSqtPRw0xPRAcjeAOIiJWqZm3pP4u3g==
+
fast-deep-equal@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz"
From d4b0417d20c3f56aeb1d5b3b7853bae0177797ac Mon Sep 17 00:00:00 2001
From: Diego Solari
Date: Fri, 7 May 2021 17:44:47 -0400
Subject: [PATCH 3/5] feat: descripcion
---
src/middlewares/auth.js | 9 +++++++
src/routes.js | 42 +++++++++++++++++++++------------
src/routes/books.js | 3 +++
src/routes/booksForAuthors.js | 3 +++
src/views/authors/show.html.ejs | 4 +++-
src/views/index.html.ejs | 4 +++-
6 files changed, 48 insertions(+), 17 deletions(-)
create mode 100644 src/middlewares/auth.js
diff --git a/src/middlewares/auth.js b/src/middlewares/auth.js
new file mode 100644
index 0000000..c6795e3
--- /dev/null
+++ b/src/middlewares/auth.js
@@ -0,0 +1,9 @@
+function checkAuth(ctx, next) {
+ const { currentUser } = ctx.state;
+ if (!currentUser) ctx.throw(401);
+ return next();
+}
+
+module.exports = {
+ checkAuth,
+};
diff --git a/src/routes.js b/src/routes.js
index b0a2484..3848b6c 100644
--- a/src/routes.js
+++ b/src/routes.js
@@ -10,23 +10,36 @@ const session = require('./routes/session');
const router = new KoaRouter();
router.use(async (ctx, next) => {
- if (ctx.session.currentUserId){
- ctx.state.currentUser = await ctx.orm.user.findByPk(ctx.session.currentUserId);
+ try {
+ await next();
+ } catch (err) {
+ switch (err.status) {
+ case 401:
+ ctx.app.emit('error', err, ctx);
+ ctx.redirect(ctx.router.url('session.new'));
+ break;
+ default:
+ throw err;
}
- return next();
- });
-
+ }
+});
+
router.use(async (ctx, next) => {
- Object.assign(ctx.state, {
- paths: {
- destroySession: ctx.router.url('session.destroy'),
- newSession: ctx.router.url('session.new'),
-
- },
- });
- return next();
+ if (ctx.session.currentUserId) {
+ ctx.state.currentUser = await ctx.orm.user.findByPk(ctx.session.currentUserId);
+ }
+ return next();
+});
+
+router.use(async (ctx, next) => {
+ Object.assign(ctx.state, {
+ paths: {
+ destroySession: ctx.router.url('session.destroy'),
+ newSession: ctx.router.url('session.new'),
+ },
});
-
+ return next();
+});
router.use('/', index.routes());
router.use('/hello', hello.routes());
@@ -35,5 +48,4 @@ router.use('/books', books.routes());
router.use('/authors/:authorId/books', booksForAuthors.routes());
router.use('/session', session.routes());
-
module.exports = router;
diff --git a/src/routes/books.js b/src/routes/books.js
index 75d65d5..8dac4f4 100644
--- a/src/routes/books.js
+++ b/src/routes/books.js
@@ -1,4 +1,5 @@
const KoaRouter = require('koa-router');
+const { checkAuth } = require('../middlewares/auth');
const router = new KoaRouter();
@@ -8,6 +9,8 @@ router.param('id', async (id, ctx, next) => {
return next();
});
+router.use(checkAuth);
+
router.get('books.new', '/new', async (ctx) => {
const book = ctx.orm.book.build();
const authorList = await ctx.orm.author.findAll();
diff --git a/src/routes/booksForAuthors.js b/src/routes/booksForAuthors.js
index 0104259..8e96492 100644
--- a/src/routes/booksForAuthors.js
+++ b/src/routes/booksForAuthors.js
@@ -1,7 +1,10 @@
const KoaRouter = require('koa-router');
+const { checkAuth } = require('../middlewares/auth');
const router = new KoaRouter();
+router.use(checkAuth);
+
async function getAuthor(ctx, next) {
ctx.state.author = await ctx.orm.author.findByPk(ctx.params.authorId);
if (!ctx.state.author) return ctx.throw(404);
diff --git a/src/views/authors/show.html.ejs b/src/views/authors/show.html.ejs
index 1e32126..cfc507c 100644
--- a/src/views/authors/show.html.ejs
+++ b/src/views/authors/show.html.ejs
@@ -9,5 +9,7 @@
<%= book.title %>
<% }) %>
- Agregar libro
+ <% if (locals.currentUser) { %>
+ Agregar libro
+ <% } %>
<% } %>
diff --git a/src/views/index.html.ejs b/src/views/index.html.ejs
index 6fef283..05fd9e6 100644
--- a/src/views/index.html.ejs
+++ b/src/views/index.html.ejs
@@ -4,6 +4,8 @@
<%= appVersion %>
Esta es una aplicaición con código de ejemplo para el uso del template, que no considera estilos.
Ver autores
-Agregar libro
+<% if (locals.currentUser) { %>
+ Agregar libro
+<% } %>
Here a React app will be rendered
From 2a3fa2edcdc6cea34a13edd95bbf32d2b8ded595 Mon Sep 17 00:00:00 2001
From: Diego Solari
Date: Fri, 7 May 2021 18:01:29 -0400
Subject: [PATCH 4/5] feat: descripcion a libros
---
src/routes/books.js | 2 +-
src/views/books/new.html.ejs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/routes/books.js b/src/routes/books.js
index c1d0c0a..82d7439 100644
--- a/src/routes/books.js
+++ b/src/routes/books.js
@@ -47,4 +47,4 @@ router.get('books.show', '/:id', async (ctx) => {
});
});
-module.exports = router;
+module.exports = router;
\ No newline at end of file
diff --git a/src/views/books/new.html.ejs b/src/views/books/new.html.ejs
index 6084fe1..b62d434 100644
--- a/src/views/books/new.html.ejs
+++ b/src/views/books/new.html.ejs
@@ -27,7 +27,7 @@
-
+
From 518979139eda946174b48d3c4ed87a63403993c5 Mon Sep 17 00:00:00 2001
From: Diego Solari
Date: Fri, 7 May 2021 18:12:24 -0400
Subject: [PATCH 5/5] fix: arreglo de nombre
---
src/views/books/new.html.ejs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/views/books/new.html.ejs b/src/views/books/new.html.ejs
index b62d434..6084fe1 100644
--- a/src/views/books/new.html.ejs
+++ b/src/views/books/new.html.ejs
@@ -27,7 +27,7 @@
-
+