2018-03-06 22:50:40 +01:00
|
|
|
// Generated by CoffeeScript 1.12.7
|
2017-02-02 22:48:32 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
LemonLDAP::NG U2F registration script
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
2018-03-06 22:50:40 +01:00
|
|
|
var displayError, register, setMsg, unregister, verify;
|
2017-02-08 19:10:06 +01:00
|
|
|
|
|
|
|
setMsg = function(msg, level) {
|
|
|
|
$('#msg').html(window.translate(msg));
|
|
|
|
$('#color').removeClass('message-positive message-warning alert-success alert-warning');
|
|
|
|
$('#color').addClass("message-" + level);
|
|
|
|
if (level === 'positive') {
|
|
|
|
level = 'success';
|
|
|
|
}
|
|
|
|
return $('#color').addClass("alert-" + level);
|
|
|
|
};
|
2017-02-02 22:48:32 +01:00
|
|
|
|
2017-07-07 10:50:47 +02:00
|
|
|
displayError = function(j, status, err) {
|
|
|
|
var res;
|
|
|
|
console.log('Error', err);
|
|
|
|
res = JSON.parse(j.responseText);
|
|
|
|
if (res && res.error) {
|
|
|
|
res = res.error.replace(/.* /, '');
|
|
|
|
console.log('Returned error', res);
|
|
|
|
return setMsg(res, 'warning');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-02 22:48:32 +01:00
|
|
|
register = function() {
|
2017-02-08 19:10:06 +01:00
|
|
|
return $.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: portal + "u2fregister/register",
|
|
|
|
data: {},
|
|
|
|
dataType: 'json',
|
2017-07-07 10:50:47 +02:00
|
|
|
error: displayError,
|
2017-02-08 19:10:06 +01:00
|
|
|
success: function(ch) {
|
|
|
|
var request;
|
|
|
|
request = [
|
|
|
|
{
|
|
|
|
challenge: ch.challenge,
|
|
|
|
version: ch.version
|
|
|
|
}
|
|
|
|
];
|
|
|
|
setMsg('touchU2fDevice', 'positive');
|
|
|
|
$('#u2fPermission').show();
|
|
|
|
return u2f.register(ch.appId, request, [], function(data) {
|
|
|
|
$('#u2fPermission').hide();
|
|
|
|
if (data.errorCode) {
|
|
|
|
return setMsg('unableToGetU2FKey', 'warning');
|
|
|
|
} else {
|
|
|
|
return $.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: portal + "u2fregister/registration",
|
|
|
|
data: {
|
2018-03-06 22:50:40 +01:00
|
|
|
registration: JSON.stringify(data),
|
|
|
|
challenge: JSON.stringify(ch)
|
2017-02-08 19:10:06 +01:00
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(resp) {
|
|
|
|
if (resp.error) {
|
|
|
|
return setMsg('u2fFailed', 'warning');
|
|
|
|
} else if (resp.result) {
|
2017-02-20 18:30:58 +01:00
|
|
|
return setMsg('u2fRegistered', 'positive');
|
2017-02-08 19:10:06 +01:00
|
|
|
}
|
|
|
|
},
|
2017-07-07 10:50:47 +02:00
|
|
|
error: displayError
|
2017-02-08 19:10:06 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-02-21 09:23:41 +01:00
|
|
|
unregister = function() {
|
|
|
|
return $.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: portal + "u2fregister/unregister",
|
|
|
|
data: {},
|
|
|
|
dataType: 'json',
|
|
|
|
error: displayError,
|
|
|
|
success: function(ch) {
|
|
|
|
var request;
|
|
|
|
request = [
|
|
|
|
{
|
|
|
|
challenge: ch.challenge,
|
|
|
|
version: ch.version
|
|
|
|
}
|
|
|
|
];
|
|
|
|
setMsg('touchU2fDevice', 'positive');
|
|
|
|
$('#u2fPermission').show();
|
|
|
|
return u2f.register(ch.appId, request, [], function(data) {
|
|
|
|
$('#u2fPermission').hide();
|
|
|
|
if (data.errorCode) {
|
|
|
|
return setMsg('unableToGetU2FKey', 'warning');
|
|
|
|
} else {
|
|
|
|
return $.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: portal + "u2fregister/unregistration",
|
|
|
|
data: {
|
2018-03-06 23:00:27 +01:00
|
|
|
registration: JSON.stringify(data),
|
|
|
|
challenge: JSON.stringify(ch)
|
2018-02-21 09:23:41 +01:00
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(resp) {
|
|
|
|
if (resp.error) {
|
|
|
|
return setMsg('u2fFailed', 'warning');
|
|
|
|
} else if (resp.result) {
|
|
|
|
return setMsg('u2fUnregistered', 'positive');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: displayError
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-02-08 19:10:06 +01:00
|
|
|
verify = function() {
|
|
|
|
return $.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: portal + "u2fregister/verify",
|
|
|
|
data: {},
|
|
|
|
dataType: 'json',
|
2017-07-07 10:50:47 +02:00
|
|
|
error: displayError,
|
2017-02-08 19:10:06 +01:00
|
|
|
success: function(ch) {
|
|
|
|
var request;
|
|
|
|
request = [
|
|
|
|
{
|
|
|
|
keyHandle: ch.keyHandle,
|
|
|
|
version: ch.version
|
|
|
|
}
|
|
|
|
];
|
|
|
|
setMsg('touchU2fDevice', 'positive');
|
|
|
|
return u2f.sign(ch.appId, ch.challenge, request, function(data) {
|
|
|
|
if (data.errorCode) {
|
|
|
|
return setMsg('unableToGetU2FKey', 'warning');
|
|
|
|
} else {
|
|
|
|
return $.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: portal + "u2fregister/signature",
|
|
|
|
data: {
|
|
|
|
signature: JSON.stringify(data)
|
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(resp) {
|
|
|
|
if (resp.error) {
|
|
|
|
return setMsg('u2fFailed', 'warning');
|
|
|
|
} else if (resp.result) {
|
|
|
|
return setMsg('u2fSuccess', 'positive');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(j, status, err) {
|
|
|
|
return console.log('error', err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-02-03 18:14:13 +01:00
|
|
|
}
|
2017-02-02 22:48:32 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2017-02-08 19:10:06 +01:00
|
|
|
$('#u2fPermission').hide();
|
|
|
|
$('#register').on('click', register);
|
2018-02-21 09:23:41 +01:00
|
|
|
$('#unregister').on('click', unregister);
|
2018-03-06 22:50:40 +01:00
|
|
|
$('#verify').on('click', verify);
|
2017-02-08 19:10:06 +01:00
|
|
|
return $('#goback').attr('href', portal);
|
2017-02-02 22:48:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
}).call(this);
|