This repository was archived by the owner on Aug 4, 2018. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathadmin.js
More file actions
108 lines (92 loc) · 3.04 KB
/
Copy pathadmin.js
File metadata and controls
108 lines (92 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(function($) {
var registering = false;
$u2f_reg = $("#u2f-register");
$u2f_reg.click(function() {
if( registering ) {
return false;
} else {
registering = true;
}
u2f_data.request = JSON.parse(u2f_data.request);
u2f_data.sigs = JSON.parse(u2f_data.sigs);
setTimeout(function() {
console.log("Register: ", u2f_data.request);
$u2f_reg.text('Now insert (and tap) your Security Key')
.removeClass('button-primary')
.append('<div class="circle">')
.children(".circle")
.append('<div class="semicircle">')
.append('<div class="semicircle">')
.append('<div class="semicircle">')
.append('<div class="semicircle">');
u2f.register([u2f_data.request], u2f_data.sigs, function(data) {
console.log("Register callback", data);
$u2f_reg.text('Please Wait')
.append('<div class="circle">')
.children(".circle")
.append('<div class="semicircle">')
.append('<div class="semicircle">')
.append('<div class="semicircle">')
.append('<div class="semicircle">');
$.post(
u2f_data.ajax_url,
{
action: "u2f_register",
data: data
}
)
.done(function( data, textStatus, jqXHR ){
console.log('Ajax Response', jqXHR );
if( data.success ) {
history.pushState('', '', location.href + '&u2f_status=registered');
console.log('Registered successfully');
$u2f_reg.text('Registered');
/**
* TODO
*
* * Update List Table
*/
} else {
history.pushState('', '', location.href + '&u2f_status=failed');
console.log('Error occured');
$u2f_reg.text('Failed');
if( data.errorCode ) {
var reasons = {
1: 'Some error occurred.',
2: 'The request cannot be processed.',
3: 'Client configuration is not supported.',
4: 'The presented device is not eligible for this request.',
5: 'You probably did not find your security key. Timeout.',
}
var code = data.errorText.match(/Error Code: (\d)/i)[1];
alert(
'Sorry, we are failed to register your security key.\n'
+ ( reasons[ code ] ? ' * Reason: ' + reasons[ code ] + '\n' : null )
+ ' * Error Code: ' + data.errorCode + '\n'
+ ' * Status Message, Browser-side Error Code: ' + data.errorText
);
}
}
})
.fail(function( jqXHR, textStatus, errorThrown ){
history.pushState('', '', location.href + '&u2f_status=failed');
console.log('Ajax Response(Bad HTTP Status)', jqXHR );
$u2f_reg.text('Failed');
alert(
'Sorry, we are failed to register your security key. '
+ 'We have no detailed information. Please contact server administrator.'
);
})
.always(function( data_jqXHR, textStatus, jqXHR_errorThrown ){
registering = false;
});
});
}, 1000);
});
if(typeof u2f === 'undefined') {
$u2f_reg.text('Your browser doesn\'t support U2F API.')
.removeClass('button-primary')
.css('cursor', 'not-allowed')
.unbind('click');
}
})(jQuery);