a
This commit is contained in:
parent
e710fa15a1
commit
d0aeab286a
@ -13,7 +13,7 @@ const { generateUUID } = require("./generateUUID.js");
|
|||||||
//can be used for api key or token. Both are the same logic
|
//can be used for api key or token. Both are the same logic
|
||||||
async function addAPIKey(userId, permission) {
|
async function addAPIKey(userId, permission) {
|
||||||
let hashtoken = await generateUUID();
|
let hashtoken = await generateUUID();
|
||||||
let apikey = await hashAPIKey(hashtoken);
|
let apikey = await hash(hashtoken);
|
||||||
|
|
||||||
let token = await apikeyModel.create({
|
let token = await apikeyModel.create({
|
||||||
userid: userId,
|
userid: userId,
|
||||||
|
@ -2,26 +2,6 @@ const bcrypt = require('bcrypt');
|
|||||||
const saltRounds = 10;
|
const saltRounds = 10;
|
||||||
//https://github.com/kelektiv/node.bcrypt.js#readme
|
//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
|
//hash for pass or token lol doesnt matter
|
||||||
async function hash(password) {
|
async function hash(password) {
|
||||||
return await bcrypt.hash(password, saltRounds);
|
return await bcrypt.hash(password, saltRounds);
|
||||||
|
@ -6,6 +6,7 @@ async function getLocation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addLocation(name, added_by, description) {
|
async function addLocation(name, added_by, description) {
|
||||||
|
console.log(name, added_by, description);
|
||||||
const location = await locationModel.create({
|
const location = await locationModel.create({
|
||||||
name: name,
|
name: name,
|
||||||
added_by: added_by,
|
added_by: added_by,
|
||||||
|
@ -20,6 +20,8 @@ async function getUserID(userid) {
|
|||||||
return userRes;
|
return userRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//register
|
||||||
|
//api/v0/auth/register
|
||||||
async function addUser(user) {
|
async function addUser(user) {
|
||||||
//hash password
|
//hash password
|
||||||
let hashed = await hash(user.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
|
//api/v0/auth/register
|
||||||
/* Registering new user
|
/* Registering new user
|
||||||
1) req.body is taken from html form or wtv
|
1) req.body is taken from html form or wtv
|
||||||
|
@ -25,6 +25,7 @@ router.get("/", async (req, res, next) => {
|
|||||||
//add location
|
//add location
|
||||||
router.post("/new", async (req, res, next) => {
|
router.post("/new", async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
console.log(req.body);
|
||||||
const { name, added_by, description } = req.body;
|
const { name, added_by, description } = req.body;
|
||||||
await addLocation(name, added_by, description);
|
await addLocation(name, added_by, description);
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user