Skip to content
Open
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
Binary file modified .DS_Store
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions final_project/general.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const axios = require("axios");

async function getAllBooks() {
try {
const response = await axios.get("http://localhost:5000/");
console.log(response.data);
} catch (error) {
console.error("Error fetching books:", error.message);
}
}

async function getBookByISBN(isbn) {
axios
.get(`http://localhost:5000/isbn/${isbn}`)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error("Error fetching book by ISBN:", error.message);
});
}

async function getBooksByAuthor(author) {
try {
const response = await axios.get(`http://localhost:5000/author/${author}`);
console.log(response.data);
} catch (error) {
console.error("Error fetching books by author:", error.message);
}
}

async function getBooksByTitle(title) {
try {
const response = await axios.get(`http://localhost:5000/title/${title}`);
console.log(response.data);
} catch (error) {
console.error("Error fetching books by title:", error.message);
}
}
45 changes: 34 additions & 11 deletions final_project/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
const express = require('express');
const jwt = require('jsonwebtoken');
const session = require('express-session')
const customer_routes = require('./router/auth_users.js').authenticated;
const genl_routes = require('./router/general.js').general;
const express = require("express");
const jwt = require("jsonwebtoken");
const session = require("express-session");
const { authenticatedUser } = require("./router/auth_users.js");
const customer_routes = require("./router/auth_users.js").authenticated;
const genl_routes = require("./router/general.js").general;

const app = express();

app.use(express.json());

app.use("/customer",session({secret:"fingerprint_customer",resave: true, saveUninitialized: true}))
app.use(
"/customer",
session({
secret: "fingerprint_customer",
resave: true,
saveUninitialized: true,
})
);

app.use("/customer/auth/*", function auth(req,res,next){
//Write the authenication mechanism here
app.use("/customer/auth/*", function auth(req, res) {
const { username, password } = req.body;

if (!username || !password)
return res.status(404).json({ message: "Error logging in" });

if (authenticatedUser(username, password)) {
let accessToken = jwt.sign({ data: password }, "access", {
expiresIn: 60 * 60,
});

req.session.authorization = { accessToken, username };
return res.status(200).send("User logged in");
}
return res
.status(208)
.json({ message: "Invalid login. Check username and password" });
});
const PORT =5000;

const PORT = 5000;

app.use("/customer", customer_routes);
app.use("/", genl_routes);

app.listen(PORT,()=>console.log("Server is running"));
app.listen(PORT, () => console.log("Server is running"));
Loading