This is an automated email from the ASF dual-hosted git repository.

brianspector pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-milagro-javascript.git

commit f1052009e4d92fee5e23ed1759c64bd1f4972c24
Author: Pavlin Angelov <[email protected]>
AuthorDate: Mon Jul 4 11:39:00 2016 +0300

    Make the js-lib to work with maas mobile flow (#5)
    
    * Make the js-lib to work with maas mobile flow
    
    The library now react on received data from the server ( based on status) 
and propagete when status
    changes to the client, so appropriate message can be shown to the user
    
    * Fix some namings
    
    Rename cb2 to cbStatus to better represent what is used for
    Fix variable name to meet naming convention
---
 lib/mpin.js | 43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/lib/mpin.js b/lib/mpin.js
index bbbed18..1ee8159 100644
--- a/lib/mpin.js
+++ b/lib/mpin.js
@@ -616,7 +616,7 @@ var mpinjs = (function () {
     });
   };
 
-  Mpin.prototype.waitForMobileAuth = function (timeoutSeconds, requestSeconds, 
cb) {
+  Mpin.prototype.waitForMobileAuth = function (timeoutSeconds, requestSeconds, 
cb, cbStatus) {
     var self = this, _reqData = {};
     if (!this.webOTT) {
       return cb({code: Errors.wrongFlow.code, type: Errors.wrongFlow.type, 
message: "Need to call getAccessNumber method before this."}, null);
@@ -624,6 +624,7 @@ var mpinjs = (function () {
       return cb({code: Errors.missingParams.code, type: 
Errors.missingParams.type, message: "Missing timeout/expiration period(in 
seconds)."}, null);
     }
 
+    self.mobileStatus = self.mobileStatus || '';
 
     if (typeof this.timeoutPeriod === "undefined") {
       this.timeoutPeriod = timeoutSeconds * 1000;
@@ -635,22 +636,34 @@ var mpinjs = (function () {
 
     this.request(_reqData, function (err, data) {
       var _requestPeriod;
+
       if (err) {
-        if (err.status === 401 && self.timeoutPeriod > 0) {
-          _requestPeriod = requestSeconds ? requestSeconds * 1000 : 3000;
-          self.timeoutPeriod -= _requestPeriod;
-
-          self.intervalID2 = setTimeout(function () {
-            self.waitForMobileAuth.call(self, timeoutSeconds, requestSeconds, 
cb);
-          }, _requestPeriod);
-          return;
-        } else if (self.timeoutPeriod <= 0) {
-          delete self.timeoutPeriod;
-          cb && cb(Errors.timeoutFinish, null);
-          return;
-        }
+        cb && cb(err, null);
       } else {
-        self._authenticate({mpinResponse: data}, cb);
+        authOTT = data.authOTT
+        delete data.authOTT
+
+        if(data.status === 'authenticate') {
+          cbStatus && cbStatus(data);
+          self._authenticate({mpinResponse: {authOTT: authOTT}}, cb);
+        } else {
+          if (self.timeoutPeriod > 0) {
+            _requestPeriod = requestSeconds ? requestSeconds * 1000 : 3000;
+            self.timeoutPeriod -= _requestPeriod;
+            if (data.status !== self.mobileStatus) {
+                self.mobileStatus = data.status;
+                cbStatus && cbStatus(data);
+            }
+            self.intervalID2 = setTimeout(function () {
+              self.waitForMobileAuth.call(self, timeoutSeconds, 
requestSeconds, cb, cbStatus);
+            }, _requestPeriod);
+            return;
+          } else if (self.timeoutPeriod <= 0) {
+            delete self.timeoutPeriod;
+            cb && cb(Errors.timeoutFinish, null);
+            return;
+          }
+        }
       }
     });
   };

Reply via email to