Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merged changes from staging server

  • Loading branch information...
commit ae318016712095e1702a895b4ce9b31ebd17da67 1 parent f9848f7
Chris Dawson authored

Showing 1 changed file with 17 additions and 10 deletions. Show diff stats Hide diff stats

  1. +17 10 lib/connect-rpx.js
27 lib/connect-rpx.js
@@ -40,6 +40,7 @@ function getCredentials(req,res,next) {
40 40 postWithCredentials( token, req, res, next );
41 41 }
42 42
  43 +var rpxResponseBody = '';
43 44 function postWithCredentials( token, req, res, next ) {
44 45 var apiKey = options['apiKey'];
45 46 var toPost = qs.stringify( { token : token, apiKey : apiKey } );
@@ -49,26 +50,32 @@ function postWithCredentials( token, req, res, next ) {
49 50 var postRequest = http.createClient( 443, RPX_HOST, true ).request( 'POST', RPX_LOGIN_ROOT, toPostHeader );
50 51 postRequest.write( toPost, 'utf8' );
51 52 postRequest.on( 'response', function(rpxResponse) {
52   - var rpxResponseBody = '';
53   - rpxResponse.on( 'data', function(chunk) { rpxResponseBody += chunk; } );
54   - rpxResponse.on( 'end', onCredentialsReceived( rpxResponseBody, req, res, next ) );
55   - rpxResponse.on( 'error', onError );
  53 + rpxResponse.on( 'data', chunkRpxResponse );
  54 + rpxResponse.on( 'end', function() { onCredentialsReceived( rpxResponseBody, req, res, next ) } );
  55 + rpxResponse.on( 'error', onError );
56 56 });
57 57 postRequest.end();
58 58 }
59 59
  60 +function chunkRpxResponse( chunk ) {
  61 + rpxResponseBody += chunk;
  62 +}
  63 +
60 64 function onError(response) {
61 65 sys.puts( "Something bad happened" );
62 66 }
63 67
64 68 function onCredentialsReceived(data, req, res, next) {
65   - try {
66   - json = JSON.parse( data );
67   - }
68   - catch( e ) {
69   - sys.puts( "E: " + sys.inspect( e ) );
  69 + var json;
  70 + if( data ) {
  71 + try {
  72 + json = JSON.parse( data );
  73 + }
  74 + catch( e ) {
  75 + sys.puts( "E: " + sys.inspect( e ) );
  76 + }
70 77 }
71   - if( 'ok' == json.stat ) {
  78 + if( json && 'ok' == json.stat ) {
72 79 options.onSuccessfulLogin( json, req, res, next );
73 80 }
74 81 else {

0 comments on commit ae31801

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