Old partial attempt at "public mode"
This commit is contained in:
parent
f872785e64
commit
8f6b030ca8
6 changed files with 37 additions and 18 deletions
11
middlewares/public.js
Normal file
11
middlewares/public.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
const verifyAuth = require('./verifyAuth')
|
||||||
|
|
||||||
|
const middlewareNoop = ( (_1, _2, next) => next() )
|
||||||
|
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,5 @@
|
||||||
const verifyAuth = require('../middlewares/verifyAuth');
|
const verifyAuth = require('../middlewares/verifyAuth');
|
||||||
|
const public = require('../middlewares/public');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ module.exports = ({ db, config }) => {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
verifyAuth(),
|
public(),
|
||||||
(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 public = require('../../middlewares/public');
|
||||||
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('/', public(), 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 (row of docs.rows) {
|
for (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', public(), 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') {
|
||||||
|
|
|
@ -23,6 +23,10 @@ nav.navbar.is-fixed-top(role='navigation', aria-label='main navigation',style='b
|
||||||
.navbar-item.has-dropdown.is-hoverable
|
.navbar-item.has-dropdown.is-hoverable
|
||||||
a.navbar-link= req.user._id
|
a.navbar-link= req.user._id
|
||||||
.navbar-dropdown
|
.navbar-dropdown
|
||||||
|
if req.user._id === 'Unknown'
|
||||||
|
.navbar-item
|
||||||
|
a.button.is-primary(href='/login') Log In
|
||||||
|
else
|
||||||
+navBarLink(`/wishlist/${req.user._id}`, 'My Wishlist')
|
+navBarLink(`/wishlist/${req.user._id}`, 'My Wishlist')
|
||||||
+navBarLink('/profile', 'Profile')
|
+navBarLink('/profile', 'Profile')
|
||||||
if req.user.admin
|
if req.user.admin
|
||||||
|
|
|
@ -12,6 +12,7 @@ block title
|
||||||
span #{config.siteTitle} - #{title}
|
span #{config.siteTitle} - #{title}
|
||||||
|
|
||||||
block content
|
block content
|
||||||
|
if req.user
|
||||||
script(type='data/user_id')= req.user._id
|
script(type='data/user_id')= req.user._id
|
||||||
if process.env.TABLE !== 'false'
|
if process.env.TABLE !== 'false'
|
||||||
.box
|
.box
|
||||||
|
|
|
@ -2,6 +2,7 @@ extends layout.pug
|
||||||
|
|
||||||
block content
|
block content
|
||||||
ul.noStyle.noLeftMargin
|
ul.noStyle.noLeftMargin
|
||||||
|
if req.user._id !== 'Unknown'
|
||||||
li
|
li
|
||||||
a(href=`/wishlist/${req.user._id}`)
|
a(href=`/wishlist/${req.user._id}`)
|
||||||
.box
|
.box
|
||||||
|
|
Loading…
Reference in a new issue