LISTS_PUBLIC
This commit is contained in:
parent
12558d3384
commit
fc9fbc6bdf
5 changed files with 37 additions and 22 deletions
10
middlewares/publicRoute.js
Normal file
10
middlewares/publicRoute.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
const verifyAuth = require('./verifyAuth')
|
||||||
|
|
||||||
|
const publicMiddleware = () => process.env.LISTS_PUBLIC === 'true'
|
||||||
|
? (req, res, next) => {
|
||||||
|
if (!req.user) req.user = { _id: 'Unknown' }
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
: verifyAuth()
|
||||||
|
|
||||||
|
module.exports = publicMiddleware
|
|
@ -1,4 +1,4 @@
|
||||||
const verifyAuth = require('../middlewares/verifyAuth')
|
const publicRoute = require('../middlewares/publicRoute')
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ module.exports = ({ db, config }) => {
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
verifyAuth(),
|
publicRoute(),
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
res.redirect('/wishlist')
|
res.redirect('/wishlist')
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const verifyAuth = require('../../middlewares/verifyAuth')
|
const verifyAuth = require('../../middlewares/verifyAuth')
|
||||||
|
const publicRoute = require('../../middlewares/publicRoute')
|
||||||
const getProductName = require('get-product-name')
|
const getProductName = require('get-product-name')
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const config = require('../../config')
|
const config = require('../../config')
|
||||||
|
@ -29,7 +30,7 @@ const ValidURL = (string) => { // Ty SO
|
||||||
module.exports = (db) => {
|
module.exports = (db) => {
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.get('/', verifyAuth(), async (req, res) => {
|
router.get('/', publicRoute(), async (req, res) => {
|
||||||
const docs = await db.allDocs({ include_docs: true })
|
const docs = await db.allDocs({ include_docs: true })
|
||||||
if (process.env.SINGLE_LIST === 'true') {
|
if (process.env.SINGLE_LIST === 'true') {
|
||||||
for (const row of docs.rows) {
|
for (const row of docs.rows) {
|
||||||
|
@ -39,7 +40,7 @@ module.exports = (db) => {
|
||||||
res.render('wishlists', { title: 'Wishlists', users: docs.rows, totals })
|
res.render('wishlists', { title: 'Wishlists', users: docs.rows, totals })
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get('/:user', verifyAuth(), async (req, res) => {
|
router.get('/:user', publicRoute(), async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const dbUser = await db.get(req.params.user)
|
const dbUser = await db.get(req.params.user)
|
||||||
if (process.env.SINGLE_LIST === 'true') {
|
if (process.env.SINGLE_LIST === 'true') {
|
||||||
|
|
|
@ -20,16 +20,19 @@ nav.navbar.is-fixed-top(role='navigation', aria-label='main navigation',style='b
|
||||||
.navbar-menu#navBarMenu
|
.navbar-menu#navBarMenu
|
||||||
.navbar-start
|
.navbar-start
|
||||||
if req.isAuthenticated()
|
if req.isAuthenticated()
|
||||||
.navbar-item.has-dropdown.is-hoverable
|
if req.user._id === 'Unknown'
|
||||||
a.navbar-link= req.user._id
|
.navbar-item
|
||||||
.navbar-dropdown
|
a.button.is-primary(href='/login') Log In
|
||||||
+navBarLink(`${_CC.config.base}wishlist/${req.user._id}`, 'My Wishlist')
|
else
|
||||||
+navBarLink(`${_CC.config.base}profile`, 'Profile')
|
.navbar-item.has-dropdown.is-hoverable
|
||||||
if req.user.admin
|
a.navbar-link= req.user._id
|
||||||
+navBarLink(`${_CC.config.base}admin-settings`, 'Admin settings')
|
.navbar-dropdown
|
||||||
hr.navbar-divider
|
+navBarLink(`${_CC.config.base}wishlist/${req.user._id}`, 'My Wishlist')
|
||||||
.navbar-item
|
+navBarLink(`${_CC.config.base}profile`, 'Profile')
|
||||||
form#logoutForm(action=`${_CC.config.base}logout`, method='POST')
|
if req.user.admin
|
||||||
button.button.is-warning(type='submit') Log Out
|
+navBarLink(`${_CC.config.base}admin-settings`, 'Admin settings')
|
||||||
//-+navBarLink('javascript:document.getElementById("logoutForm").submit()', 'Log Out')
|
hr.navbar-divider
|
||||||
|
.navbar-item
|
||||||
|
form#logoutForm(action=`${_CC.config.base}logout`, method='POST')
|
||||||
|
button.button.is-warning(type='submit') Log Out
|
||||||
script(src=`${_CC.config.base}js/nav.js`)
|
script(src=`${_CC.config.base}js/nav.js`)
|
||||||
|
|
|
@ -2,12 +2,13 @@ extends layout.pug
|
||||||
|
|
||||||
block content
|
block content
|
||||||
ul.noStyle.noLeftMargin
|
ul.noStyle.noLeftMargin
|
||||||
li
|
if req.user._id !== 'Unknown'
|
||||||
a(href=`${_CC.config.base}wishlist/${req.user._id}`)
|
li
|
||||||
.box
|
a(href=`${_CC.config.base}wishlist/${req.user._id}`)
|
||||||
span=req.user._id
|
.box
|
||||||
span : ???/???
|
span=req.user._id
|
||||||
progress.progress(value=1, max=1)
|
span : ???/???
|
||||||
|
progress.progress(value=1, max=1)
|
||||||
each user in users
|
each user in users
|
||||||
if req.user._id !== user.id
|
if req.user._id !== user.id
|
||||||
li
|
li
|
||||||
|
|
Loading…
Reference in a new issue