Skip to content

Commit

Permalink
Add check for duplicate device name on create new device
Browse files Browse the repository at this point in the history
  • Loading branch information
coldfire84 committed Jan 25, 2020
1 parent cbe564f commit 88f89e1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/routes/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,13 @@ router.put('/devices', defaultLimiter,
// Set username on device to match req.user.username
device.username = user;

// Sanity check new device
// Check for duplicate device name
var checkDevice = await Devices.findOne({username:user, friendlyName: device.friendlyName});
if (checkDevice) {
logger.log('warning' , "[Create Device] User tried to create a device with duplicate friendly name");
return res.status(500).send('Please ensure your devices have unique names!');
}
// Require 2FA PIN on Google Home-enabled user Smart Lock
if (req.user.activeServices.indexOf('Google') > -1 && device.displayCategories == 'SMARTLOCK' && (!device.attributes.require2FA || !device.attributes.pin || !device.attributes.type2FA)){
logger.log('warning' , "[Create Device] Google Home user tried to create new Smart Lock device without a PIN");
return res.status(500).send('As a Google Home user you must set a PIN on your lock!');
Expand Down Expand Up @@ -696,7 +702,7 @@ router.post('/device/:dev_id', defaultLimiter,
data.attributes = device.attributes;
data.state = device.state;

// Sanity check new device
// Require 2FA PIN on Google Home-enabled user Smart Lock
if (req.user.activeServices.indexOf('Google') > -1 && device.displayCategories == 'SMARTLOCK' && (!device.attributes.require2FA || !device.attributes.pin || !device.attributes.type2FA)){
logger.log('warning' , "[Create Device] Google Home user tried to create new Smart Lock device without a PIN");
return res.status(500).send('As a Google Home user you must set a PIN on your lock!');
Expand Down

0 comments on commit 88f89e1

Please sign in to comment.