@@ -271,30 +271,32 @@ App.prototype = {
271271 }
272272 } . bind ( this ) ) ;
273273 } ,
274- httpRequestHandler : function ( request , response , callback ) {
275- if ( request . method == 'POST' && typeof ( request . query [ 'login-submit' ] ) != 'undefined' ) {
276- this . _completeWholeRequestInfo ( request , function ( reqInfo ) {
277- if ( this . _users . length ) {
278- this . _completeReqCredentialsAndTryToAuth ( reqInfo , response , callback ) ;
279- } else {
280- this . _loadCsvLoginData ( function ( users ) {
281- this . _users = users ;
282- this . _completeReqCredentialsAndTryToAuth ( reqInfo , response , callback ) ;
283- } . bind ( this ) ) ;
284- }
285- } . bind ( this ) ) ;
286- } else {
287- response . send ( '/* No autorization credentials sended. */' ) ;
288- callback ( ) ;
289- }
274+ HandleHttpRequest : function ( request , response ) {
275+ return new Promise ( function ( resolve , reject ) {
276+ if ( request . method == 'POST' && typeof ( request . query [ 'login-submit' ] ) != 'undefined' ) {
277+ this . _completeWholeRequestInfo ( request , function ( reqInfo ) {
278+ if ( this . _users . length ) {
279+ this . _completeReqCredentialsAndTryToAuth ( reqInfo , response , resolve ) ;
280+ } else {
281+ this . _loadCsvLoginData ( function ( users ) {
282+ this . _users = users ;
283+ this . _completeReqCredentialsAndTryToAuth ( reqInfo , response , resolve ) ;
284+ } . bind ( this ) ) ;
285+ }
286+ } . bind ( this ) ) ;
287+ } else {
288+ response . send ( '/* No autorization credentials sended. */' ) ;
289+ resolve ( ) ;
290+ }
291+ } . bind ( this ) ) ;
290292 } ,
291- _completeReqCredentialsAndTryToAuth : function ( reqInfo , response , callback ) {
293+ _completeReqCredentialsAndTryToAuth : function ( reqInfo , response , resolve ) {
292294 var request = reqInfo . request ,
293295 urlParts , data ;
294296 try {
295297 urlParts = Url . parse ( "http://localhost/?" + reqInfo . textBody , true ) ;
296298 data = urlParts . query ;
297- } catch ( e ) { }
299+ } catch ( e ) { }
298300 if ( typeof ( data ) != 'undefined' && data . user . length > 0 && data . pass . length > 0 ) {
299301
300302
@@ -309,20 +311,20 @@ App.prototype = {
309311 request . session . authorized = true ;
310312 request . session . save ( function ( ) {
311313 response . send ( '{"success":true,"id":' + this . _users [ data . user ] . id + '}' ) ;
312- callback ( ) ;
314+ resolve ( ) ;
313315 } . bind ( this ) ) ;
314316
315317 } else {
316318 response . send ( '{"success":false' ) ;
317- callback ( ) ;
319+ resolve ( ) ;
318320 }
319321 /***************************************************************************/
320322
321323
322324
323325 } else {
324326 response . send ( '{"success":false' ) ;
325- callback ( ) ;
327+ resolve ( ) ;
326328 }
327329 } ,
328330 _completeWholeRequestInfo : function ( request , callback ) {
0 commit comments