Skip to content
Browse files

overhaul of password system

  • Loading branch information...
1 parent e37936c commit 2111906756a6d0addb7d3ce96e63503cc7e979d5 @contra contra committed
Showing with 108 additions and 57 deletions.
  1. +107 −56 nodester.js
  2. +1 −1 package.json
View
163 nodester.js
@@ -3,24 +3,26 @@ var querystring = require('querystring');
var fs = require('fs');
var sys = require('sys');
-var headers = {'Content-Type': 'application/x-www-form-urlencoded'};
-var nodester = function (username, password, basehost, secure) {
- if (typeof basehost != 'undefined') this.basehost = basehost;
- else this.basehost = 'api.nodester.com';
- if (typeof secure != 'undefined' && secure == true) this.proto = 'https://';
- else this.proto = 'http://';
- this.username = username;
- this.password = password;
- if (typeof this.username != 'undefined' && typeof this.password != 'undefined' && this.username.length > 0 && this.password.length > 0) {
- var userbits = this.username + ":" + this.password + "@";
- } else {
- var userbits = "";
- }
- this.baseurl = this.proto + userbits + this.basehost + "/";
+var headers = {
+ 'Content-Type': 'application/x-www-form-urlencoded'
};
+var nodester = function (username, password, basehost, secure) {
+ if (typeof basehost != 'undefined') this.basehost = basehost;
+ else this.basehost = 'api.nodester.com';
+ if (typeof secure != 'undefined' && secure == true) this.proto = 'https://';
+ else this.proto = 'http://';
+ this.username = username;
+ this.password = password;
+ if (typeof this.username != 'undefined' && typeof this.password != 'undefined' && this.username.length > 0 && this.password.length > 0) {
+ var userbits = this.username + ":" + this.password + "@";
+ } else {
+ var userbits = "";
+ }
+ this.baseurl = this.proto + userbits + this.basehost + "/";
+ };
function process_response(cb, errfn) {
- return function(err, response, body) {
+ return function (err, response, body) {
var errCode = null;
if (!err && response && response.statusCode >= 400) {
errCode = response.statusCode;
@@ -29,64 +31,101 @@ function process_response(cb, errfn) {
try {
data = JSON.parse(body);
} catch (e) {
- if (!err) err = { message: body };
+ if (!err) err = {
+ message: body
+ };
data = body;
}
if (errfn) {
if (!err) err = errfn(data);
} else {
- if (!err && data.status && !/^success/.exec(data.status)) err = { message: data.status }
+ if (!err && data.status && !/^success/.exec(data.status)) err = {
+ message: data.status
+ }
}
if (errCode) {
- if (err) { err.code = errCode; err.message = '[HTTP ' + errCode + '] ' + err.message; }
- else err = { code: errCode, message: "HTTP Error " + errCode };
+ if (err) {
+ err.code = errCode;
+ err.message = '[HTTP ' + errCode + '] ' + err.message;
+ } else err = {
+ code: errCode,
+ message: "HTTP Error " + errCode
+ };
}
cb(err, data);
}
}
-nodester.prototype.request = function(method, path, body, cb) {
+nodester.prototype.request = function (method, path, body, cb) {
request({
- uri: this.baseurl + path,
- method: method,
- body: querystring.stringify(body),
- headers: headers,
- proxy: process.env.http_proxy
- },
- process_response(cb)
- );
+ uri: this.baseurl + path,
+ method: method,
+ body: querystring.stringify(body),
+ headers: headers,
+ proxy: process.env.http_proxy
+ }, process_response(cb));
}
-nodester.prototype.get = function(path, cb) { this.request('GET', path, null, cb); }
-nodester.prototype.post = function(path, body, cb) { this.request('POST', path, body, cb); }
-nodester.prototype.put = function(path, body, cb) { this.request('PUT', path, body, cb); }
-nodester.prototype.del = function(path, body, cb) { this.request('DELETE', path, body, cb); }
+nodester.prototype.get = function (path, cb) {
+ this.request('GET', path, null, cb);
+}
+nodester.prototype.post = function (path, body, cb) {
+ this.request('POST', path, body, cb);
+}
+nodester.prototype.put = function (path, body, cb) {
+ this.request('PUT', path, body, cb);
+}
+nodester.prototype.del = function (path, body, cb) {
+ this.request('DELETE', path, body, cb);
+}
nodester.prototype.coupon_request = function (email, cb) {
- this.post('coupon', { email: email }, cb)
+ this.post('coupon', {
+ email: email
+ }, cb)
}
nodester.prototype.user_create = function (user, pass, email, rsakey, coupon, cb) {
- fs.readFile(rsakey, 'ascii', function(err, rsadata) {
+ fs.readFile(rsakey, 'ascii', function (err, rsadata) {
if (err) cb(err, null);
if (rsadata.length < 40) {
- cb({ message: "Error: Invalid SSH key file." });
+ cb({
+ message: "Error: Invalid SSH key file."
+ });
} else {
- this.post('user', { user: user, password: pass, email: email, coupon: coupon, rsakey: rsadata }, cb);
+ this.post('user', {
+ user: user,
+ password: pass,
+ email: email,
+ coupon: coupon,
+ rsakey: rsadata
+ }, cb);
}
}.bind(this));
};
nodester.prototype.user_delete = function (user, cb) {
- this.del('user', { user: user }, cb);
+ this.del('user', {
+ user: user
+ }, cb);
+};
+
+nodester.prototype.user_sendtoken = function (some_user, cb) {
+ this.post('reset_password', {
+ user: some_user
+ }, cb);
};
-nodester.prototype.user_setpass = function (newpass, cb) {
- this.put('user', { password: newpass }, cb);
+nodester.prototype.user_setpass = function (token, a_password, cb) {
+ this.put('reset_password/' + token, {
+ password: a_password
+ }, cb);
};
nodester.prototype.user_setkey = function (rsakey, cb) {
- this.put('user', { rsakey: rsakey }, cb);
+ this.put('user', {
+ rsakey: rsakey
+ }, cb);
};
nodester.prototype.apps_list = function (cb) {
@@ -94,7 +133,10 @@ nodester.prototype.apps_list = function (cb) {
};
nodester.prototype.app_create = function (name, start, cb) {
- this.post('app', { appname: name, start: start }, cb);
+ this.post('app', {
+ appname: name,
+ start: start
+ }, cb);
};
nodester.prototype.status = function (cb) {
@@ -104,7 +146,10 @@ nodester.prototype.status = function (cb) {
nodester.prototype.app_running = function (name, running, cb) {
- this.put('app', { appname: name, running: running }, cb);
+ this.put('app', {
+ appname: name,
+ running: running
+ }, cb);
};
nodester.prototype.app_start = function (name, cb) {
@@ -120,11 +165,15 @@ nodester.prototype.app_stop = function (name, cb) {
};
nodester.prototype.app_delete = function (name, cb) {
- this.del('app', { appname: name }, cb);
+ this.del('app', {
+ appname: name
+ }, cb);
};
nodester.prototype.app_gitreset = function (name, cb) {
- this.del('gitreset', { appname: name }, cb);
+ this.del('gitreset', {
+ appname: name
+ }, cb);
};
nodester.prototype.app_info = function (name, cb) {
@@ -136,7 +185,11 @@ nodester.prototype.app_logs = function (name, cb) {
};
nodester.prototype.appnpm_handler = function (name, package, action, cb) {
- this.post('appnpm', { appname: name, package: package, action: action }, cb);
+ this.post('appnpm', {
+ appname: name,
+ package: package,
+ action: action
+ }, cb);
};
nodester.prototype.appnpm_install = function (name, package, cb) {
@@ -153,24 +206,22 @@ nodester.prototype.appnpm_uninstall = function (name, package, cb) {
nodester.prototype.appdomain_add = function (name, domain, cb) {
- this.post('appdomains', { appname: name, domain: domain }, cb);
+ this.post('appdomains', {
+ appname: name,
+ domain: domain
+ }, cb);
};
nodester.prototype.appdomain_delete = function (name, domain, cb) {
- this.del('appdomains', { appname: name, domain: domain }, cb);
+ this.del('appdomains', {
+ appname: name,
+ domain: domain
+ }, cb);
};
-nodester.prototype.appdomains = function(cb) {
+nodester.prototype.appdomains = function (cb) {
this.get('appdomains', cb);
};
-nodester.prototype.reset_password_token = function(some_user, cb) {
- this.post('reset_password', { user: some_user }, cb);
-};
-
-nodester.prototype.reset_password_setpass = function(token, a_password, cb) {
- this.put('reset_password/' + token, { password: a_password }, cb);
-};
-
exports.nodester = nodester;
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "nodester-api",
"description": "A module to allow interaction with the http://nodester.com/ platform.",
- "version": "0.1.11",
+ "version": "0.1.12",
"homepage": "http://nodester.com/",
"repository": "git://github.com/nodester/nodester-api.git",
"author": "Daniel Bartlett <dan@f-box.org> (http://danb-uk.net/)",

0 comments on commit 2111906

Please sign in to comment.
Something went wrong with that request. Please try again.