This commit is contained in:
newtbot
2024-01-20 01:22:19 +08:00
parent 1ed59aba97
commit 2ecb69c828
8 changed files with 59 additions and 35 deletions

View File

@ -4,12 +4,9 @@ const { userModel } = require("../database/model/userModel.js");
const { Op, Sequelize } = require("sequelize");
const { hashAPIKey } = require("../functions/bcrypt.js");
const { generateUUID } = require("../functions/generateUUID.js");
const { hashPassword , hashAPIKey } = require("../functions/bcrypt.js");
const { hashPassword , comparePassword , hashAPIKey } = require("../functions/bcrypt.js");
async function getUser() {
const user = await userModel.findAll();
return user;
}
//api/v0/user/register
/* Registering new user
@ -31,6 +28,10 @@ async function addUser(user) {
});
}
async function getAPIKey() {
const apikey = await apikeyModel.findAll();
return apikey;
}
/*
1) take userid
@ -40,8 +41,6 @@ async function addUser(user) {
5) you give the user rowid-uuidv4
6) store in database
*/
async function addAPIKey(userId, permission) {
let token = await generateUUID();
let usertoken = userId + "-" + token;
@ -62,8 +61,7 @@ async function addAPIKey(userId, permission) {
}
module.exports = {
getUser,
addUser,
getAPIKey,
loginUser,
addAPIKey,
};

View File

@ -29,9 +29,14 @@ async function hashAPIKey(apikey) {
return await bcrypt.hash(apikey, saltRounds);
}
async function comparePassword(password, hash) {
return await bcrypt.compare(password, hash);
}
module.exports = {
hashPassword,
hashAPIKey,
comparePassword
};