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' );
}
} );
} );
};