modify pairing code

pull/4/head
AdamSBlack 2021-12-31 01:22:34 +00:00
parent b4540abb5c
commit c2e730f09a
4 changed files with 17 additions and 8 deletions

3
.gitignore vendored
View File

@ -10,4 +10,5 @@ config.js
database.sqlite
config.js
test/.devKeys
config_prod.js
config_prod.js
database - copy.sqlite

View File

@ -19,7 +19,12 @@ async function pairDevice(account, qr_string) {
} else {
pairJWT = qr_string;
const data = await authenticationController.readJWT(qr_string);
deviceQuery = await models_orm.models.device.findOne({ where: { dongle_id: data.identiy }});
if (data.pair === true) {
deviceQuery = await models_orm.models.device.findOne({ where: { dongle_id: data.identiy }});
} else{
return {success: false, noPair: true}
}
}

View File

@ -106,7 +106,7 @@ router.get('/v1.1/devices/:dongleId/', runAsyncWrapper(async (req, res) => {
return res.send('Unauthorized.').status(400)
}
let response={'is_paired': (device.account_id>0 ? true : false), 'prime': (device.account_id>0 ? true : false)};
let response={'is_paired': (device.account_id !== 0 ? true : false), 'prime': (device.account_id>0 ? true : false)};
logger.info("HTTP.DEVICES for " + req.params.dongleId + " returning: "+JSON.stringify(response));
res.status(200);
@ -215,9 +215,7 @@ router.get('/v1/devices/:dongleId/owner', runAsyncWrapper(async (req, res) => {
res.json(response);
}))
// DRIVE & BOOT/CRASH LOG FILE UPLOAD URL REQUEST
router.get('/v1.3/:dongleId/upload_url/', runAsyncWrapper(async (req, res) => {
async function upload(req,res) {
var path = req.query.path;
const dongleId = req.params.dongleId;
const auth = req.headers.authorization;
@ -347,7 +345,12 @@ router.get('/v1.3/:dongleId/upload_url/', runAsyncWrapper(async (req, res) => {
res.status(400);
res.send('Malformed Request.');
}
}))
}
// DRIVE & BOOT/CRASH LOG FILE UPLOAD URL REQUEST
router.get('/v1.3/:dongleId/upload_url/', upload)
router.get('/v1.4/:dongleId/upload_url/', upload)
// DEVICE REGISTRATION OR RE-ACTIVATION

View File

@ -218,7 +218,7 @@ router.post('/retropilot/0/pair_device', bodyParser.urlencoded({extended: true})
res.json({success: false, msg: 'UNAUTHORISED', status: 403})
}
const pairDevice = await controllers.devices.pairDevice(req.body.qr_string);
const pairDevice = await controllers.devices.pairDevice(account, req.body.qr_string);
if (pairDevice.success === true) {
res.json({success: true, msg: 'Paired', status: 200, data: pairDevice})