Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add secret token to admin & overlays #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ app.get('/', (req, res) => {
// dbManager.test();
})

app.get('/camillelv', (req, res) => {
app.get('/camillelv', checkToken, (req, res) => {
res.sendFile(__dirname + '/pages/admin.html');
// dbManager.test();
})

app.get('/admin', (req, res) => {
app.get('/admin', checkToken, (req, res) => {
res.sendFile(__dirname + '/pages/admin.html');
})

app.get('/overlay/:token/:id', (req, res) => {
console.log('token:', req.params.token);
if (!req.params.token || !req.params.id) {
app.get('/overlay/camillelv/:id', checkToken, (req, res) => {
//console.log('token:', req.params.token);
if (!req.params.id) {
return res.status(400).send({ message: "token or id missing" });
}

Expand All @@ -51,12 +51,20 @@ app.get('/overlay/:token/:id', (req, res) => {
});
})

app.use(express.static('./overlays'));
app.use('/assets', express.static('./overlays/assets'));

function checkToken(req, res, next) {
if (req.query.secret == process.env.APP_SECRET_TOKEN) {
return next();
}
res.status(401);
res.send({ message: 'Invalid request!'});
}


var admin = io.of('/admin'),
client = io.of('');


admin.on('connection', function (socket) {
socket.on('message', function(m) {
console.log(m);
Expand Down
15 changes: 9 additions & 6 deletions pages/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ <h1 class="title is-4">Activités</h1>
<div class="column is-three-quarters">
<div class="container" v-if="widgetsData[0]">
<h1 class="title is-4">Serge</h1>
<a target="_blank" href="/overlay/camillelv/serge-bar">
<a target="_blank" :href="`/overlay/camillelv/serge-bar?secret=${secret}`">
<span class="icon has-text-info">
<i class="fas fa-link"></i>
</span>
Overlay Barre de progression</a>
<br>
<a target="_blank" href="/overlay/camillelv/serge-alert">
<a target="_blank" :href="`/overlay/camillelv/serge-alert?secret=${secret}`">
<span class="icon has-text-info">
<i class="fas fa-link"></i>
</span>
Expand Down Expand Up @@ -96,13 +96,13 @@ <h1 class="title is-4">Serge</h1>

<div class="container" v-if="widgetsData[1]">
<h1 class="title is-4">Machine à {{widgetsData[1].name}}</h1>
<a target="_blank" href="/overlay/camillelv/dossier-bar">
<a target="_blank" :href="`/overlay/camillelv/dossier-bar?secret=${secret}`">
<span class="icon has-text-info">
<i class="fas fa-link"></i>
</span>
Overlay Barre de progression</a>
<br>
<a target="_blank" href="/overlay/camillelv/dossier-alert">
<a target="_blank" :href="`/overlay/camillelv/dossier-alert?secret=${secret}`">
<span class="icon has-text-info">
<i class="fas fa-link"></i>
</span>
Expand All @@ -113,7 +113,7 @@ <h1 class="title is-4">Machine à {{widgetsData[1].name}}</h1>
<br>
<br>
<button class="button is-warning" type="button" @click="resetDossierCounter(1)">Réinitialiser progression</button>
<button class="button is-warning" type="button" @click="resetDossierRevealed(1)">Réinitialiser toutes les images révélé</button>
<button class="button is-warning" type="button" @click="resetDossierRevealed(1)">Réinitialiser toutes les images révélés</button>
<br>
<br>
<form v-on:submit.prevent="updateWidget(1)">
Expand Down Expand Up @@ -200,6 +200,7 @@ <h1 class="title is-4">Machine à {{widgetsData[1].name}}</h1>
var app = new Vue({
el: '#app',
data: {
secret: null,
message: 'Hello Vue!',
widgetsData: [],
myWidget: null,
Expand Down Expand Up @@ -246,7 +247,9 @@ <h1 class="title is-4">Machine à {{widgetsData[1].name}}</h1>

},
mounted () {

const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('secret');
this.secret = myParam || null;
},

methods: {
Expand Down
8 changes: 7 additions & 1 deletion pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>
<body>
<div id="app">
{{ message }}
♾️
</div>
</body>

Expand Down Expand Up @@ -38,4 +38,10 @@
})
</script>

<style lang="scss" scoped>
body {
font-family: sans-serif;
}
</style>

</html>