Merge branch 'main' of github.com:Newtbot/MP
This commit is contained in:
commit
17ee99d570
@ -13,7 +13,7 @@ const { generateUUID } = require("./generateUUID.js");
|
||||
//can be used for api key or token. Both are the same logic
|
||||
async function addAPIKey(userId, permission) {
|
||||
let hashtoken = await generateUUID();
|
||||
let apikey = await hashAPIKey(hashtoken);
|
||||
let apikey = await hash(hashtoken);
|
||||
|
||||
let token = await apikeyModel.create({
|
||||
userid: userId,
|
||||
|
@ -2,26 +2,6 @@ const bcrypt = require('bcrypt');
|
||||
const saltRounds = 10;
|
||||
//https://github.com/kelektiv/node.bcrypt.js#readme
|
||||
|
||||
|
||||
/*
|
||||
// Load hash from your password DB.
|
||||
bcrypt.compare(myPlaintextPassword, hash, function(err, result) {
|
||||
// result == true
|
||||
});
|
||||
bcrypt.compare(someOtherPlaintextPassword, hash, function(err, result) {
|
||||
// result == false
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
//hash with salt
|
||||
bcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) {
|
||||
// Store hash in your password DB.
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
//hash for pass or token lol doesnt matter
|
||||
async function hash(password) {
|
||||
return await bcrypt.hash(password, saltRounds);
|
||||
|
@ -6,6 +6,7 @@ async function getLocation() {
|
||||
}
|
||||
|
||||
async function addLocation(name, added_by, description) {
|
||||
console.log(name, added_by, description);
|
||||
const location = await locationModel.create({
|
||||
name: name,
|
||||
added_by: added_by,
|
||||
|
@ -20,6 +20,8 @@ async function getUserID(userid) {
|
||||
return userRes;
|
||||
}
|
||||
|
||||
//register
|
||||
//api/v0/auth/register
|
||||
async function addUser(user) {
|
||||
//hash password
|
||||
let hashed = await hash(user.password);
|
||||
@ -40,21 +42,6 @@ async function addUser(user) {
|
||||
}
|
||||
}
|
||||
|
||||
//getuser
|
||||
//api/v0/user/me
|
||||
async function getUserID(userid) {
|
||||
//console.log(userid);
|
||||
//console.log(userid.id);
|
||||
let userRes = await userModel.findByPk(userid.id, {
|
||||
attributes: {
|
||||
exclude: ["password"],
|
||||
},
|
||||
});
|
||||
|
||||
if (!userRes) return false;
|
||||
return userRes;
|
||||
}
|
||||
|
||||
//api/v0/auth/register
|
||||
/* Registering new user
|
||||
1) req.body is taken from html form or wtv
|
||||
|
@ -25,6 +25,7 @@ router.get("/", async (req, res, next) => {
|
||||
//add location
|
||||
router.post("/new", async (req, res, next) => {
|
||||
try {
|
||||
console.log(req.body);
|
||||
const { name, added_by, description } = req.body;
|
||||
await addLocation(name, added_by, description);
|
||||
res.sendStatus(200)
|
||||
|
Loading…
x
Reference in New Issue
Block a user