Link to disable monitoring

This commit is contained in:
baldo 2016-05-18 23:15:43 +02:00
parent 0bdce5debb
commit 5a5c70cfb1
10 changed files with 230 additions and 0 deletions

View file

@ -34,9 +34,36 @@ angular.module('ffffng').factory('MonitoringResource', function (
hostname: node.hostname,
mac: node.mac,
email: node.email,
monitoring: node.monitoring,
monitoringConfirmed: node.monitoringConfirmed
});
});
},
disable: function (req, res) {
var data = Resources.getData(req);
var mac = Strings.normalizeMac(data.mac);
if (!isValidMac(mac)) {
return Resources.error(res, {data: 'Invalid MAC.', type: ErrorTypes.badRequest});
}
var token = Strings.normalizeString(data.token);
if (!isValidToken(token)) {
return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest});
}
return MonitoringService.disable(mac, token, function (err, node) {
if (err) {
return Resources.error(res, err);
}
return Resources.success(res, {
hostname: node.hostname,
mac: node.mac,
email: node.email,
monitoring: node.monitoring
});
});
}
};
});

View file

@ -9,6 +9,7 @@ angular.module('ffffng').factory('Router', function (app, NodeResource, Monitori
app.get('/api/node/:token', NodeResource.get);
app.put('/api/monitoring/confirm/:mac', MonitoringResource.confirm);
app.put('/api/monitoring/disable/:mac', MonitoringResource.disable);
}
};
});

View file

@ -18,6 +18,29 @@ angular.module('ffffng')
}
node.monitoringConfirmed = true;
NodeService.internalUpdateNode(node.token, node, nodeSecrets, function (err, token, node) {
if (err) {
return callback(err);
}
callback(null, node);
});
});
},
disable: function (mac, token, callback) {
NodeService.getNodeDataByMac(mac, function (err, node, nodeSecrets) {
if (err) {
return callback(err);
}
if (!node.monitoring || !nodeSecrets.monitoringToken || nodeSecrets.monitoringToken !== token) {
return callback({data: 'Invalid token.', type: ErrorTypes.badRequest});
}
node.monitoring = false;
node.monitoringConfirmed = false;
nodeSecrets.monitoringToken = '';
NodeService.internalUpdateNode(node.token, node, nodeSecrets, function (err, token, node) {
if (err) {
return callback(err);