UNPKG

cozy-proxy

Version:

Cozy Proxy redirects requests properly to the right application of the Cozy platform depending on given path. It also handles authentication to the Cozy for users and devices.

50 lines (40 loc) 1.3 kB
// Generated by CoffeeScript 1.10.0 var Client, PasswordKeys, urlHelper; Client = require("request-json").JsonClient; urlHelper = require('cozy-url-sdk'); PasswordKeys = (function() { function PasswordKeys() { var ref; this.client = new Client(urlHelper.dataSystem.url()); this.name = process.env.NAME; this.token = process.env.TOKEN; if ((ref = process.env.NODE_ENV) === "production" || ref === "test") { this.client.setBasicAuth(this.name, this.token); } } PasswordKeys.prototype.initializeKeys = function(pwd, callback) { return this.client.post("accounts/password/", { password: pwd }, callback); }; PasswordKeys.prototype.updateKeys = function(pwd, callback) { return this.client.put("accounts/password/", { password: pwd }, callback); }; PasswordKeys.prototype.resetKeys = function(pwd, callback) { return this.client.put("accounts/password/", { password: pwd }, (function(_this) { return function(err, res, body) { if ((res != null ? res.statusCode : void 0) === 400) { return _this.client.del("accounts/reset/", callback); } else { return callback(err); } }; })(this)); }; return PasswordKeys; })(); module.exports = new PasswordKeys();