Skip to content

Commit

Permalink
Add check on POST /verify to avoid duplicate MQTT ACL creation
Browse files Browse the repository at this point in the history
Further reST documentation testing
  • Loading branch information
coldfire84 committed Jan 9, 2020
1 parent e735527 commit 4ad4f2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Getting Started
########
Before you can use this service with Alexa or Google Home you need to:

* Create and verify an `account. <https://red.cb-net.co.uk/new-user>`
* Define one or more `devices. <https://red.cb-net.co.uk/devices>`
* Create and verify an `account. <https://red.cb-net.co.uk/new-user>`_
* Define one or more `devices. <https://red.cb-net.co.uk/devices>`_
* Install the associated Node-RED nodes. `Install Node-RED Nodes`_
* Setup Node-RED flows using your devices.

Expand Down
17 changes: 13 additions & 4 deletions src/routes/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,24 @@ router.post('/verify', defaultLimiter, async (req, res) => {
if (account) logger.log('debug', "[Verify] account hash: " + account.hash + ", account salt: " + account.salt);
// Find pattern-based ACL
// var aclPattern = await Topics.findOne({topics: ['command/%u/#','state/%u/#','response/%u/#','message/%u/#']});
// Create user-specific ACL
var aclUser = new Topics({topics: [
// Check for existing ACL
var aclUser = await Topics.findOne({topics: [
'command/' + req.params.username +'/#',
'state/'+ req.params.username + '/#',
'response/' + req.params.username + '/#',
'message/' + req.params.username + '/#'
]});
// Save new user-specific MQTT topics
await aclUser.save();
// If does not exist, create user-specific ACL
if (!aclUser) {
var aclUser = new Topics({topics: [
'command/' + req.params.username +'/#',
'state/'+ req.params.username + '/#',
'response/' + req.params.username + '/#',
'message/' + req.params.username + '/#'
]});
// Save new user-specific MQTT topics
await aclUser.save();
}
// Create MQTT password based upon returned salt and hash
var mqttPass = "PBKDF2$sha256$901$" + account.salt + "$" + account.hash;
// Update the user account with MQTT password and MQTT topics, set isVerified to true
Expand Down

0 comments on commit 4ad4f2f

Please sign in to comment.