Archived
2

changed to findById and improved db.loadJson

This commit is contained in:
VLE2FE
2020-04-24 10:53:45 +02:00
parent 4e68267bfd
commit 8bf408138f
7 changed files with 48 additions and 8 deletions

View File

@ -56,7 +56,7 @@ function basic (req, next): any { // checks basic auth and returns changed user
return new Promise(resolve => {
const auth = basicAuth(req);
if (auth !== undefined) { // basic auth available
UserModel.find({name: auth.name}).lean().exec( 'find', (err, data) => { // find user
UserModel.find({name: auth.name}).lean().exec( (err, data: any) => { // find user
if (err) next(err);
if (data.length === 1) { // one user found
bcrypt.compare(auth.pass, data[0].pass, (err, res) => { // check password
@ -83,7 +83,7 @@ function basic (req, next): any { // checks basic auth and returns changed user
function key (req, next): any { // checks API key and returns changed user object
return new Promise(resolve => {
if (req.query.key !== undefined) {
UserModel.find({key: req.query.key}).lean().exec( 'find', (err, data) => { // find user
UserModel.find({key: req.query.key}).lean().exec( (err, data: any) => { // find user
if (err) next(err);
if (data.length === 1) { // one user found
resolve({level: data[0].level, name: data[0].name});