app endpoints, enforce email verification

This commit is contained in:
2023-08-19 14:10:40 +02:00
parent 71a2927372
commit 5505313e3e
6 changed files with 169 additions and 77 deletions

View File

@@ -0,0 +1,63 @@
/*
* libreevent - appApiRoutes.js
*
* Created by Janis Hutz 08/19/2023, Licensed under the GPL V3 License
* https://janishutz.com, development@janishutz.com
*
*
*/
const bodyParser = require( 'body-parser' );
const db = require( '../backend/db/db.js' );
const pwHandler = require( './pwdmanager.js' );
module.exports = ( app ) => {
app.post( '/app/authenticate', bodyParser.json(), ( req, res ) => {
pwHandler.checkpassword( req.body.email, req.body.password ).then( status => {
if ( status ) {
if ( status.status ) {
res.send( 'authOk' );
} else {
res.send( 'wrong' );
}
} else {
res.send( 'wrong' );
}
} );
} );
app.post( '/app/ticketLookup', bodyParser.json(), ( req, res ) => {
pwHandler.checkpassword( req.body.email, req.body.password ).then( status => {
if ( status ) {
if ( status.status ) {
db.getDataSimple( 'orders', 'order_name', req.body.ticketID.slice( 0, req.body.ticketID.indexOf( '_' ) ) ).then( dat => {
if ( dat[ 0 ] ) {
const tickets = JSON.parse( dat[ 0 ][ 'tickets' ] );
const event = req.body.ticketID.slice( req.body.ticketID.indexOf( '_' ) + 1, req.body.ticketID.indexOf( '-' ) );
const ticket = req.body.ticketID.slice( req.body.ticketID.indexOf( '-' ) + 1, req.body.ticketID.length );
if ( tickets[ event ] ) {
if ( tickets[ event ][ ticket ] ) {
if ( !tickets[ event ][ ticket ][ 'invalidated' ] ) {
res.send( 'ticketValid' );
} else {
res.send( 'ticketInvalid' );
}
} else {
res.send( 'ticketInvalid' );
}
} else {
res.send( 'ticketInvalid' );
}
} else {
res.send( 'ticketInvalid' );
}
} );
} else {
res.send( 'wrong' );
}
} else {
res.send( 'wrong' );
}
} );
} );
};

View File

@@ -27,6 +27,9 @@ let paymentOk = {};
module.exports = ( app, settings ) => { module.exports = ( app, settings ) => {
app.post( '/payments/prepare', bodyParser.json(), ( req, res ) => { app.post( '/payments/prepare', bodyParser.json(), ( req, res ) => {
if ( req.session.loggedInUser ) { if ( req.session.loggedInUser ) {
db.getDataSimple( 'users', 'email', req.session.username ).then( user => {
if ( user[ 0 ] ) {
if ( user[ 0 ][ 'mail_confirmed' ] ) {
let purchase = { let purchase = {
'successRedirectUrl': settings.yourDomain + '/payments/success', 'successRedirectUrl': settings.yourDomain + '/payments/success',
'cancelRedirectUrl': settings.yourDomain + '/payments/canceled', 'cancelRedirectUrl': settings.yourDomain + '/payments/canceled',
@@ -69,6 +72,13 @@ module.exports = ( app, settings ) => {
console.error( '[ STRIPE ] DB ERROR: ' + error ); console.error( '[ STRIPE ] DB ERROR: ' + error );
res.status( 500 ).send( 'ERR_DB' ); res.status( 500 ).send( 'ERR_DB' );
} ); } );
} else {
res.status( 428 ).send( 'ERR_MAIL_UNCONFIRMED' );
}
} else {
res.status( 428 ).send( 'ERR_MAIL_UNCONFIRMED' );
}
} );
} else { } else {
res.status( 403 ).send( 'ERR_UNAUTHORIZED' ); res.status( 403 ).send( 'ERR_UNAUTHORIZED' );
} }

View File

@@ -27,6 +27,9 @@ let paymentOk = {};
module.exports = ( app, settings ) => { module.exports = ( app, settings ) => {
app.post( '/payments/prepare', bodyParser.json(), ( req, res ) => { app.post( '/payments/prepare', bodyParser.json(), ( req, res ) => {
if ( req.session.loggedInUser ) { if ( req.session.loggedInUser ) {
db.getDataSimple( 'users', 'email', req.session.username ).then( user => {
if ( user[ 0 ] ) {
if ( user[ 0 ][ 'mail_confirmed' ] ) {
let purchase = { let purchase = {
'line_items': [], 'line_items': [],
'mode': 'payment', 'mode': 'payment',
@@ -36,6 +39,7 @@ module.exports = ( app, settings ) => {
'customer_email': req.session.username 'customer_email': req.session.username
}; };
// Get cart and prepare order
db.getDataSimple( 'temp', 'user_id', req.session.id ).then( dat => { db.getDataSimple( 'temp', 'user_id', req.session.id ).then( dat => {
if ( dat[ 0 ] ) { if ( dat[ 0 ] ) {
db.getJSONData( 'events' ).then( events => { db.getJSONData( 'events' ).then( events => {
@@ -68,6 +72,13 @@ module.exports = ( app, settings ) => {
console.error( '[ STRIPE ] DB ERROR: ' + error ); console.error( '[ STRIPE ] DB ERROR: ' + error );
res.status( 500 ).send( 'ERR_DB' ); res.status( 500 ).send( 'ERR_DB' );
} ); } );
} else {
res.status( 428 ).send( 'ERR_MAIL_UNCONFIRMED' );
}
} else {
res.status( 428 ).send( 'ERR_MAIL_UNCONFIRMED' );
}
} );
} else { } else {
res.status( 403 ).send( 'ERR_UNAUTHORIZED' ); res.status( 403 ).send( 'ERR_UNAUTHORIZED' );
} }

View File

@@ -176,7 +176,7 @@ class TicketGenerator {
'eventName': this.events[ event ][ 'name' ], 'eventName': this.events[ event ][ 'name' ],
'locationAndTime': new Date( this.events[ event ][ 'date' ] ).toLocaleString(), 'locationAndTime': new Date( this.events[ event ][ 'date' ] ).toLocaleString(),
'ticketName': order[ event ][ ticket ][ 'name' ], 'ticketName': order[ event ][ ticket ][ 'name' ],
'ticketQRCode': ord[ 0 ].order_name + '_' + order[ event ][ ticket ][ 'id' ], 'ticketQRCode': ord[ 0 ].order_name + '_' + event + '-' + order[ event ][ ticket ][ 'id' ],
} ]; } ];
const page = await pdfLib.PDFDocument.load( await pdfme.generate( { 'template': template, 'inputs': data } ) ); const page = await pdfLib.PDFDocument.load( await pdfme.generate( { 'template': template, 'inputs': data } ) );
const p = await doc.copyPages( page, page.getPageIndices() ); const p = await doc.copyPages( page, page.getPageIndices() );

View File

@@ -14,7 +14,6 @@ const getHandler = new geth();
const path = require( 'path' ); const path = require( 'path' );
const bodyParser = require( 'body-parser' ); const bodyParser = require( 'body-parser' );
// settings is missing in arguments which shouldn't pose any problem
module.exports = ( app, settings ) => { module.exports = ( app, settings ) => {
// Add specific routes here to have them be checked first to not get general handling // Add specific routes here to have them be checked first to not get general handling

View File

@@ -18,7 +18,9 @@
</div> </div>
<div v-else class="wrapper"> <div v-else class="wrapper">
<div class="data"> <div class="data">
<h2>Billing</h2> <h2>Purchase</h2>
<p>Ready to buy? Please once again check that all the right items are in your cart.</p>
<!--<h2>Billing</h2>
<table class="billing-info-table"> <table class="billing-info-table">
<tr v-if="settings.requiresAddress"> <tr v-if="settings.requiresAddress">
<td>Street and house number</td> <td>Street and house number</td>
@@ -39,8 +41,8 @@
</table> </table>
<div v-if="settings.requiresSpecialToken"> <div v-if="settings.requiresSpecialToken">
<!-- TODO: FUTURE: Implement --> TODO: FUTURE: Implement
</div> </div> -->
<button id="buy-button" @click="preparePayment();">Buy now</button> <button id="buy-button" @click="preparePayment();">Buy now</button>
</div> </div>
<div class="cart"> <div class="cart">
@@ -293,6 +295,13 @@ export default {
window.location.href = text; window.location.href = text;
}, 300 ); }, 300 );
} ); } );
} else if ( res.status === 428 ) {
res.text().then( text => {
if ( text === 'ERR_MAIL_UNCONFIRMED' ) {
this.$refs.notification.cancelNotification( prep );
this.$refs.notification.createNotification( 'Please confirm your email address to proceed', 10, 'error', 'high' );
}
} );
} }
} ).catch( err => { } ).catch( err => {
console.error( err ); console.error( err );