Added isAuthenticate to differentiate between ineligible messages

This commit is contained in:
Luke "Jared" Bennett 2017-01-02 10:25:28 +00:00
parent 8dc2163ce5
commit 932bcb4d32
No known key found for this signature in database
GPG key ID: 402ED51FB5D306C2
3 changed files with 10 additions and 10 deletions

View file

@ -57,7 +57,7 @@
return function(response) {
var error;
if (response.errorCode) {
error = new U2FError(response.errorCode);
error = new U2FError(response.errorCode, 'authenticate');
return _this.renderError(error);
} else {
return _this.renderAuthenticated(JSON.stringify(response));

View file

@ -5,21 +5,21 @@
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
this.U2FError = (function() {
function U2FError(errorCode) {
function U2FError(errorCode, u2fFlowType) {
this.errorCode = errorCode;
this.message = bind(this.message, this);
this.httpsDisabled = window.location.protocol !== 'https:';
this.u2fFlowType = u2fFlowType;
}
U2FError.prototype.message = function() {
switch (false) {
case !(this.errorCode === u2f.ErrorCodes.BAD_REQUEST && this.httpsDisabled):
return "U2F only works with HTTPS-enabled websites. Contact your administrator for more details.";
case this.errorCode !== u2f.ErrorCodes.DEVICE_INELIGIBLE:
return "This device has already been registered with us.";
default:
return "There was a problem communicating with your device.";
if (this.errorCode === u2f.ErrorCodes.BAD_REQUEST && this.httpsDisabled) {
return 'U2F only works with HTTPS-enabled websites. Contact your administrator for more details.';
} else if (this.errorCode === u2f.ErrorCodes.DEVICE_INELIGIBLE) {
if (this.u2fFlowType === 'authenticate') return 'This device has not been registered with us.';
if (this.u2fFlowType === 'register') return 'This device has already been registered with us.';
}
return "There was a problem communicating with your device.";
};
return U2FError;

View file

@ -39,7 +39,7 @@
return function(response) {
var error;
if (response.errorCode) {
error = new U2FError(response.errorCode);
error = new U2FError(response.errorCode, 'register');
return _this.renderError(error);
} else {
return _this.renderRegistered(JSON.stringify(response));