add some setup routes already

This commit is contained in:
2023-09-06 15:27:50 +02:00
parent 667b542893
commit 4afeb7a146
12 changed files with 136 additions and 130 deletions

View File

@@ -52,10 +52,11 @@ const settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/config/se
// Vue SSR and gets its support files (e.g. CSS and JS files) from
// the /home/supportFiles/:file route plus its assets from the /otherAssets/:file
// route).
app.get( '/', ( req, res ) => {
res.sendFile( path.join( __dirname + '/ui/home/active/en/index.html' ) );
} );
if ( settings.init ) {
app.get( '/', ( req, res ) => {
res.sendFile( path.join( __dirname + '/ui/home/active/en/index.html' ) );
} );
}
// Set up static routes for static file serving (performance wise not
@@ -94,6 +95,7 @@ if ( settings.init ) {
require( './backend/payments/paymentRoutes.js' )( app, settings ); // payment routes
require( './backend/plugins/pluginLoader.js' )( app, settings ); // plugin loader
} else {
console.log( '[ Setup ] Loading setup routes' );
require( './setup/setupRoutes.js' )( app, settings ); // setup routes
file = path.join( __dirname + '/webapp/setup/dist/index.html' );
}

View File

@@ -1 +1 @@
{"init":true,"twoFA":"enforce","setupKey":"hello world","twoFAMode":"enhanced","db":"json","payments":"stripe","name":"libreevent","yourDomain":"http://localhost:8080","mailSender":"libreevent <info@libreevent.janishutz.com>","maxTickets":10,"currency":"CHF","gcInterval":300,"ticketTimeout":900,"startPage":"default","version":"1.0.0"}
{"init":false,"twoFA":"enforce","setupKey":"hello world","twoFAMode":"enhanced","db":"json","payments":"stripe","name":"libreevent","yourDomain":"http://localhost:8080","mailSender":"libreevent <info@libreevent.janishutz.com>","maxTickets":10,"currency":"CHF","gcInterval":300,"ticketTimeout":900,"startPage":"default","version":"1.0.0"}

View File

@@ -8,19 +8,34 @@
*/
let db = null;
const fs = require( 'fs' );
const path = require( 'path' );
const bodyParser = require( 'body-parser' );
// const db = require( '../backend/db/db.js' );
module.exports = ( app, settings ) => {
/*
Admin login route that checks the password
Setup start route that checks if setup key was correct
*/
app.get( '/setup/start', ( request, response ) => {
if ( request.query.token === settings.setupToken ) {
app.post( '/setup/start', bodyParser.json(), ( request, response ) => {
if ( request.body.token === '' + fs.readFileSync( path.join( __dirname + '/../setupkey.txt' ) ) ) {
response.send( 'ok' );
} else {
response.send( 'incorrect' );
response.status( 400 ).send( 'incorrect' );
}
} );
app.get( '/setup/getKeyStatus', ( req, res ) => {
if ( req.session.setupKeyOk ) {
res.send( 'ok' );
} else {
res.status( 403 ).send( 'not authorized' );
}
} );
app.get( '/test/login', ( req, res ) => {
req.session.setupKeyOk = true;
res.send( 'ok' );
} );
};

View File

@@ -0,0 +1 @@
klbjdfgsgsdjhlfkgfshjkgsfhjsiutuitpwergvuilavlsuv

View File

@@ -43,15 +43,6 @@ export default {
setupAuthRequired: true,
}
},
{
path: 'page',
name: 'setupPage',
component: () => import( '../views/SetupPageView.vue' ),
meta: {
title: 'Landing page :: Setup - libreevent',
setupAuthRequired: true,
}
},
{
path: 'complete',
name: 'setupComplete',

View File

@@ -14,24 +14,55 @@
<p>Let's start the setup by entering the setup key below! You may define a setup key in the <i>setupkey.txt</i> file of libreevent. See <a href="https://libreevent.janishutz.com/docs/setup/installation" target="_blank">here</a> for more instructions</p>
<form>
<label for="key">Your setup key</label><br>
<input type="text" v-model="formData[ 'key' ]" required name="key" id="key">
<input type="text" v-model="formData[ 'token' ]" required name="key" id="key">
</form>
<button @click="setup();" class="button">Start setup</button>
<notifications ref="notification" location="topright" size="bigger"></notifications>
</div>
</template>
<script>
import notifications from '../components/notifications.vue';
export default {
data() {
return {
formData: {},
}
},
components: {
notifications,
},
methods: {
setup () {
this.$router.push( '/setup' );
const options = {
method: 'post',
body: JSON.stringify( this.formData ),
headers: {
'Content-Type': 'application/json',
'charset': 'utf-8'
}
};
fetch( '/setup/start', options ).then( res => {
if ( res.status === 200 ) {
this.$router.push( '/setup' );
} else {
this.$refs.notification.createNotification( 'Setup key incorrect!', 5, 'error', 'normal' );
}
} );
}
},
created() {
fetch( '/setup/getKeyStatus' ).then( res => {
if ( res.status === 200 ) {
res.text().then( text => {
if ( text === 'ok' ) {
this.$router.push( '/setup' );
}
} );
}
} );
}
}
</script>

View File

@@ -1,51 +0,0 @@
<!--
* libreevent - SetupPageView.vue
*
* Created by Janis Hutz 05/14/2023, Licensed under the GPL V3 License
* https://janishutz.com, development@janishutz.com
*
*
-->
<template>
<div class="wrapper">
<div class="content">
<h1>Landing page</h1>
<p>The landing page is the page your customers see when they visit your webpage. You may select a page template <a href="https://libreevent.janishutz.com/docs/homepage/templates" target="_blank">here</a>.</p>
<p>You may find more infos about this part <a href="https://libreevent.janishutz.com/docs/setup/setup#page-setup" target="_blank">here</a></p>
<label for="template">Choose a template</label><br>
<select name="template" id="template">
<option v-for="option in options" :key="option.id" :value="option.id">{{ option.name }}</option>
</select><br>
<button @click="submit()" class="button">Continue</button>
</div>
</div>
</template>
<script>
import { useBackendStore } from '@/stores/backendStore.js';
import { mapStores } from 'pinia';
export default {
data () {
return {
options: {
'default': { 'id': 'default', 'name': 'Default' },
'none': { 'id': 'none', 'name': 'Configure later (will show an empty page)' },
},
websiteName: 'libreevent',
}
},
computed: {
...mapStores( useBackendStore )
},
methods: {
submit () {
this.backendStore.addVisitedSetupPages( 'complete', true );
this.$router.push( '/setup/complete' );
}
},
};
</script>

View File

@@ -169,8 +169,8 @@
}
},
proceed () {
this.backendStore.addVisitedSetupPages( 'page', true );
this.$router.push( 'page' );
this.backendStore.addVisitedSetupPages( 'complete', true );
this.$router.push( 'complete' );
}
},
};

View File

@@ -15,8 +15,6 @@
<a v-else class="inactive">Basic Setup</a> |
<router-link to="/setup/root" v-if="backendStore.getVisitedSetupPages[ 'root' ]">Root account</router-link>
<a v-else class="inactive">Root account</a> |
<router-link to="/setup/page" v-if="backendStore.getVisitedSetupPages[ 'page' ]">Landing page</router-link>
<a v-else class="inactive">Landing page</a> |
<router-link to="/setup/complete" v-if="backendStore.getVisitedSetupPages[ 'complete' ]">Complete</router-link>
<a v-else class="inactive">Complete</a>
</nav>
@@ -45,6 +43,17 @@
},
created () {
this.backendStore.loadVisitedSetupPages();
fetch( '/setup/getKeyStatus' ).then( res => {
if ( res.status === 200 ) {
res.text().then( text => {
if ( text != 'ok' ) {
this.$router.push( '/' );
}
} );
} else {
this.$router.push( '/' );
}
} );
},
};
</script>