You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by sa...@apache.org on 2016/08/05 14:19:41 UTC
[14/37] incubator-milagro-mfa-js-lib git commit: Change bower package
name.
Change bower package name.
Project: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/commit/d0cbb296
Tree: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/tree/d0cbb296
Diff: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/diff/d0cbb296
Branch: refs/heads/add-documentation
Commit: d0cbb2965b4768ca96f64f8854848584dfb01072
Parents: 451dce6
Author: Boyan Bakov <bo...@certivox.com>
Authored: Tue Jan 5 14:38:40 2016 +0200
Committer: Boyan Bakov <bo...@certivox.com>
Committed: Wed Jan 13 16:35:48 2016 +0200
----------------------------------------------------------------------
bower.json | 32 ++++++++++++---------
lib/mpin.js | 88 ++++++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 88 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/d0cbb296/bower.json
----------------------------------------------------------------------
diff --git a/bower.json b/bower.json
index bf93c48..3e69a9c 100644
--- a/bower.json
+++ b/bower.json
@@ -1,14 +1,18 @@
-{
- "name": "Mpin lib",
- "version": "1.0.0",
- "description": "Mpin lib front-end project",
- "authors": [
- "Miracl ltd."
- ],
- "dependencies": {
- "clint": "https://builds.certivox.com/mpin_libs/js/latest/js.tar.gz"
- },
- "moduleType": "globals",
- "main": "lib/mpin.js",
- "homepage": "http://miracl.com"
-}
+{
+ "name": "mpinjs",
+ "version": "1.0.0",
+ "description": "Mpin lib front-end project",
+ "authors": [
+ "Miracl ltd."
+ ],
+ "dependencies": {
+ "clint": "https://builds.certivox.com/mpin_libs/js/latest/js.tar.gz"
+ },
+ "ignore": [
+ "**/*",
+ "!lib/mpin.js"
+ ],
+ "moduleType": "globals",
+ "main": "lib/mpin.js",
+ "homepage": "http://miracl.com"
+}
http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-js-lib/blob/d0cbb296/lib/mpin.js
----------------------------------------------------------------------
diff --git a/lib/mpin.js b/lib/mpin.js
index 865d057..f548cdf 100644
--- a/lib/mpin.js
+++ b/lib/mpin.js
@@ -6,9 +6,9 @@
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -42,7 +42,7 @@ var mpinjs = (function () {
}
this.opts = options;
- this.settings = {};
+ this.settings = {};
this.recover();
};
@@ -83,7 +83,7 @@ var mpinjs = (function () {
};
Mpin.prototype.startRegistration = function (userId, cb) {
- var _reqData = {}, self = this;
+ var _reqData = {}, self = this, _userState;
if (!userId) {
return cb ? cb(Errors.missingUserId, null) : {error: 1};
} else if (!this.checkUser(userId)) {
@@ -91,6 +91,12 @@ var mpinjs = (function () {
} else if (!this.settings.registerURL) {
return cb({code: Errors.missingParams.code, type: Errors.missingParams.type, message: "Missing registerURL"}, null);
}
+
+ //invalid
+ _userState = this.getUser(userId, "state");
+ if (_userState !== States.invalid) {
+ return cb(Errors.wrongFlow, null);
+ }
_reqData.url = this.generateUrl("register");
_reqData.type = "PUT";
@@ -99,6 +105,10 @@ var mpinjs = (function () {
mobile: 0
};
+ if (Users[userId].deviceId) {
+ _reqData.data.deviceName = Users[userId].deviceId;
+ }
+
this.request(_reqData, function (err, data) {
if (err) {
return cb(err, null);
@@ -188,12 +198,45 @@ var mpinjs = (function () {
};
//Put user / mpinId
- Mpin.prototype.restartRegistration = function (userId, deviceId, cb) {
- var err = null, data = {};
- cb(err, data);
- };
+ Mpin.prototype.restartRegistration = function (userId, cb) {
+ var _reqData = {}, self = this, _userState;
+ if (!userId) {
+ return cb ? cb(Errors.missingUserId, null) : {error: 1};
+ } else if (!this.checkUser(userId)) {
+ return cb(Errors.invalidUserId, null);
+ } else if (!this.settings.registerURL) {
+ return cb({code: Errors.missingParams.code, type: Errors.missingParams.type, message: "Missing registerURL"}, null);
+ }
+
+ _userState = this.getUser(userId, "state");
+ if (_userState !== States.start) {
+ return cb(Errors.wrongFlow, null);
+ }
+ _reqData.url = this.generateUrl("restart", {userId: userId});
+ _reqData.type = "PUT";
+ _reqData.data = {
+ userId: userId,
+ mobile: 0,
+ regOTT: Users[userId].regOTT
+ };
+
+ this.request(_reqData, function (err, data) {
+ if (err) {
+ return cb(err, null);
+ }
+
+ self.addToUser(userId, {regOTT: data.regOTT, mpinId: data.mpinId});
+
+ //force activate
+ if (data.active) {
+ self.addToUser(userId, {state: States.active});
+ }
+
+ cb && cb(null, true);
+ });
+ };
Mpin.prototype.startAuthentication = function (userId, cb) {
var _tp1Url, self = this, _userState;
@@ -217,9 +260,9 @@ var mpinjs = (function () {
this.request({url: _tp1Url}, function (err, data) {
if (err) {
if (err.status === 401 || err.status === 403 || err.status === 410) {
- return cb(Errors.userRevoked, null);
+ return cb(Errors.userRevoked, null);
}
-
+
return cb(err, null);
}
var _signature, _tp2Url, _timePermit1, _storageUrl;
@@ -243,9 +286,9 @@ var mpinjs = (function () {
if (storErr) {
_tp2Url = self.generateUrl('permit2', {userId: userId});
_tp2Url += "&signature=" + _signature;
-
+
self._getTimePermit2({userId: userId, permit1: _timePermit1, permit2Url: _tp2Url, date: data.date}, cb); //continue
-
+
return;
}
@@ -268,7 +311,7 @@ var mpinjs = (function () {
if (err2.status === 401 || err2.status === 403 || err2.status === 410) {
return cb(Errors.userRevoked, null);
}
-
+
return cb(err2, null);
}
@@ -438,10 +481,10 @@ var mpinjs = (function () {
returnData = {
accessNumber: data.accessNumber,
ttlSeconds: data.ttlSeconds,
- localTimeStart: data.localTimeStart/1000,
- localTimeEnd: data.localTimeEnd/1000
+ localTimeStart: data.localTimeStart / 1000,
+ localTimeEnd: data.localTimeEnd / 1000
};
-
+
cb && cb(null, returnData);
});
};
@@ -475,12 +518,13 @@ var mpinjs = (function () {
}, _requestPeriod);
return;
} else if (self.timeoutPeriod <= 0) {
+ delete self.timeoutPeriod;
cb && cb(Errors.timeoutFinish, null);
return;
}
+ } else {
+ self._authenticate({mpinResponse: data}, cb);
}
-
- self._authenticate({mpinResponse: data}, cb);
});
};
@@ -488,6 +532,10 @@ var mpinjs = (function () {
if (this.intervalID2) {
clearInterval(this.intervalID2);
}
+
+ if (this.timeoutPeriod) {
+ delete this.timeoutPeriod;
+ }
};
@@ -498,6 +546,10 @@ var mpinjs = (function () {
case "register":
url = this.settings.registerURL;
break;
+ case "restart":
+ url = this.settings.registerURL + "/";
+ url += Users[options.userId].mpinId;
+ break;
case "signature":
url = this.settings.signatureURL + "/";
url += Users[options.userId].mpinId;