2016-05-18 22:50:06 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('ffffng').factory('MonitoringResource', function (
|
|
|
|
Constraints,
|
|
|
|
Validator,
|
|
|
|
MonitoringService,
|
|
|
|
_,
|
|
|
|
Strings,
|
|
|
|
Resources,
|
|
|
|
ErrorTypes
|
|
|
|
) {
|
|
|
|
var isValidToken = Validator.forConstraint(Constraints.token);
|
|
|
|
|
|
|
|
return {
|
|
|
|
confirm: function (req, res) {
|
|
|
|
var data = Resources.getData(req);
|
|
|
|
|
|
|
|
var token = Strings.normalizeString(data.token);
|
|
|
|
if (!isValidToken(token)) {
|
|
|
|
return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest});
|
|
|
|
}
|
|
|
|
|
2016-05-23 22:36:27 +02:00
|
|
|
return MonitoringService.confirm(token, function (err, node) {
|
2016-05-18 22:50:06 +02:00
|
|
|
if (err) {
|
|
|
|
return Resources.error(res, err);
|
|
|
|
}
|
|
|
|
return Resources.success(res, {
|
|
|
|
hostname: node.hostname,
|
|
|
|
mac: node.mac,
|
|
|
|
email: node.email,
|
2016-05-18 23:15:43 +02:00
|
|
|
monitoring: node.monitoring,
|
2016-05-18 22:50:06 +02:00
|
|
|
monitoringConfirmed: node.monitoringConfirmed
|
|
|
|
});
|
|
|
|
});
|
2016-05-18 23:15:43 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
disable: function (req, res) {
|
|
|
|
var data = Resources.getData(req);
|
|
|
|
|
|
|
|
var token = Strings.normalizeString(data.token);
|
|
|
|
if (!isValidToken(token)) {
|
|
|
|
return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest});
|
|
|
|
}
|
|
|
|
|
2016-05-23 22:36:27 +02:00
|
|
|
return MonitoringService.disable(token, function (err, node) {
|
2016-05-18 23:15:43 +02:00
|
|
|
if (err) {
|
|
|
|
return Resources.error(res, err);
|
|
|
|
}
|
|
|
|
return Resources.success(res, {
|
|
|
|
hostname: node.hostname,
|
|
|
|
mac: node.mac,
|
|
|
|
email: node.email,
|
|
|
|
monitoring: node.monitoring
|
|
|
|
});
|
|
|
|
});
|
2016-05-18 22:50:06 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|