Update api.js

This commit is contained in:
xfarrow 2023-09-27 15:22:01 +02:00
parent 022a85e211
commit ba5d9d30cb
1 changed files with 14 additions and 5 deletions

View File

@ -1,11 +1,12 @@
/* /*
** This code is part of Blinklink ** This code is part of Blink
** licensed under GPLv3 ** licensed under GPLv3
*/ */
const express = require('express'); const express = require('express');
const bcrypt = require('bcrypt'); const bcrypt = require('bcrypt');
const { Pool } = require('pg'); const { Pool } = require('pg');
const crypto = require('crypto');
const app = express(); const app = express();
const port = 3000; const port = 3000;
@ -38,9 +39,16 @@ app.post('/api/register', (req, res) => {
} }
bcrypt.hash(userData.password, 10, (err, hashedPassword) => { bcrypt.hash(userData.password, 10, (err, hashedPassword) => {
if (err) { if (err) {
console.error('Error hashing password:', err); console.error('Error hashing password:', err);
} else { }
else {
// Generate activation link token
const activationLink = crypto.randomBytes(16).toString('hex');
// Acquire a connection from the pool // Acquire a connection from the pool
pool.connect() pool.connect()
.then((client) => { .then((client) => {
@ -76,10 +84,11 @@ app.post('/api/register', (req, res) => {
res.status(500).json("Internal server error"); res.status(500).json("Internal server error");
}); });
} }
});
});
}); });
// Start the server // Start the server
app.listen(port, () => { app.listen(port, () => {
console.log(`Server is running on port ${port}`); console.log(`Blink API server is running on port ${port}`);
}); });