Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev buppgard tuesday #8

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const userController = require('./controllers/userController');

const app = express();

// Middleware
app.use(bodyParser.json());

// Routes
app.post('/api/login', userController.login);

// Default route for testing
app.get('/', (req, res) => {
res.send('Welcome to ProBooker Backend');
});

// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
14 changes: 14 additions & 0 deletions backend/controllers/userController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const userService = require('../services/userService'); // Ensure the correct path is used

exports.login = async (req, res) => {
try {
const { username, password } = req.body;
console.log('Login request:', username, password);
const token = await userService.login(username, password);
console.log('Generated token:', token);
res.status(200).json({ token });
} catch (error) {
console.error('Login error:', error.message);
res.status(401).json({ error: error.message });
}
};
14 changes: 14 additions & 0 deletions backend/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { Pool } = require('pg');

// Set up the connection pool
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'pro_booker_test',
password: 'password',
port: 5432,
});

module.exports = {
query: (text, params) => pool.query(text, params),
};
9 changes: 9 additions & 0 deletions backend/hashPassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const bcrypt = require('bcryptjs');

const hashPassword = async (plaintextPassword) => {
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(plaintextPassword, saltRounds);
console.log(hashedPassword);
};

hashPassword('your_password'); // Replace 'your_password' with the password you want to hash
Loading
Loading