mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 13:24:24 +00:00
restruct + 2fa + auth
This commit is contained in:
@@ -36,6 +36,7 @@ app.use( cookieParser() );
|
||||
app.use( express.static( '../webapp/dist' ) );
|
||||
|
||||
require( './admin/routes.js' )( app, settings ); // admin route
|
||||
require( './backend/userRoutes.js' )( app, settings ); // user route
|
||||
|
||||
app.use( ( request, response ) => {
|
||||
response.sendFile( path.join( __dirname + '/../webapp/dist/index.html' ) );
|
||||
|
||||
25
src/server/backend/credentials/pwdmanager.js
Normal file
25
src/server/backend/credentials/pwdmanager.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* libreevent - pwdmanager.js
|
||||
*
|
||||
* Created by Janis Hutz 07/11/2023, Licensed under the GPL V3 License
|
||||
* https://janishutz.com, development@janishutz.com
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
These functions are required to verify user login and to create new users
|
||||
and to hash new passwords (if user changes password.)
|
||||
*/
|
||||
|
||||
// import and init
|
||||
const bcrypt = require( 'bcrypt' );
|
||||
const db = require( '../db/db.js' );
|
||||
|
||||
module.exports.checkpassword = function checkpassword ( username, password ) {
|
||||
return new Promise( resolve => {
|
||||
db.getData( 'user', username ).then( data => {
|
||||
resolve( bcrypt.compareSync( password, data ) );
|
||||
} );
|
||||
} );
|
||||
};
|
||||
@@ -11,7 +11,6 @@ const path = require( 'path' );
|
||||
const fs = require( 'fs' );
|
||||
|
||||
module.exports.getData = function getData ( db, searchQuery ) {
|
||||
console.log( db + searchQuery );
|
||||
return new Promise( resolve => {
|
||||
resolve( '$2b$05$ElMYWoMjk7567lXkIkee.e.6cxCrWU4gkfuNLB8gmGYLQQPm7gT3O' );
|
||||
} );
|
||||
|
||||
@@ -1 +1,14 @@
|
||||
class
|
||||
/*
|
||||
* libreevent - jsondb.js
|
||||
*
|
||||
* Created by Janis Hutz 07/11/2023, Licensed under the GPL V3 License
|
||||
* https://janishutz.com, development@janishutz.com
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class JSONDB {
|
||||
constructor () {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* libreevent - routes.js
|
||||
*
|
||||
* Created by Janis Hutz 07/11/2023, Licensed under the GPL V3 License
|
||||
* https://janishutz.com, development@janishutz.com
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
const db = require( './db/db.js' );
|
||||
|
||||
module.exports = ( app, settings ) => {
|
||||
app.post( '/api/reserveTicket', ( request, response ) ) {
|
||||
db.getData( 'test', request.body );
|
||||
response.send( 'ok' );
|
||||
};
|
||||
};
|
||||
38
src/server/backend/userRoutes.js
Normal file
38
src/server/backend/userRoutes.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* libreevent - routes.js
|
||||
*
|
||||
* Created by Janis Hutz 07/11/2023, Licensed under the GPL V3 License
|
||||
* https://janishutz.com, development@janishutz.com
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
const db = require( './db/db.js' );
|
||||
const pwdmanager = require( './credentials/pwdmanager.js' );
|
||||
|
||||
module.exports = ( app, settings ) => {
|
||||
app.post( '/api/reserveTicket', ( request, response ) => {
|
||||
db.getData( 'test', request.body );
|
||||
response.send( 'ok' );
|
||||
} );
|
||||
|
||||
app.post( '/user/login', ( request, response ) => {
|
||||
if ( request.body.mail && request.body.password ) {
|
||||
pwdmanager.checkpassword( request.body.mail, request.body.password ).then( data => {
|
||||
if ( data ) {
|
||||
if ( settings.twoFA ) {
|
||||
// TODO: Support both methods of 2fa
|
||||
response.send( '2fa' );
|
||||
} else {
|
||||
request.session.loggedInUser = true;
|
||||
response.send( 'ok' );
|
||||
}
|
||||
} else {
|
||||
response.send( 'pwErr' );
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
response.send( 'missingCredentials' );
|
||||
}
|
||||
} );
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"init":true
|
||||
"init":true,
|
||||
"twoFA": true
|
||||
}
|
||||
Reference in New Issue
Block a user