debian-mirror-gitlab/app/assets/javascripts/u2f/error.js

28 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-console, quotes, prefer-template, max-len */
/* global u2f */
2016-09-13 17:45:13 +05:30
(function() {
2017-08-17 22:00:37 +05:30
var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; };
2016-09-13 17:45:13 +05:30
this.U2FError = (function() {
2017-08-17 22:00:37 +05:30
function U2FError(errorCode, u2fFlowType) {
2016-09-13 17:45:13 +05:30
this.errorCode = errorCode;
this.message = bind(this.message, this);
this.httpsDisabled = window.location.protocol !== 'https:';
2017-08-17 22:00:37 +05:30
this.u2fFlowType = u2fFlowType;
2016-09-13 17:45:13 +05:30
}
U2FError.prototype.message = function() {
2017-08-17 22:00:37 +05:30
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.';
2016-09-13 17:45:13 +05:30
}
2017-08-17 22:00:37 +05:30
return "There was a problem communicating with your device.";
2016-09-13 17:45:13 +05:30
};
return U2FError;
})();
2017-08-17 22:00:37 +05:30
}).call(window);