plugins/yubikey/yubikey.js
changeset 6 4f85ab095cc8
parent 0 9d2c4f04a0d0
child 7 c8fc1493eacd
equal deleted inserted replaced
5:2114640729a5 6:4f85ab095cc8
    31 function yk_mb_construct(mp)
    31 function yk_mb_construct(mp)
    32 {
    32 {
    33   mp.innerHTML = '';
    33   mp.innerHTML = '';
    34   mp.style.textAlign = 'center';
    34   mp.style.textAlign = 'center';
    35   mp.innerHTML = '<h3>' + $lang.get('yubiauth_msg_please_touch_key') + '</h3>';
    35   mp.innerHTML = '<h3>' + $lang.get('yubiauth_msg_please_touch_key') + '</h3>';
       
    36   var progress = document.createElement('div');
       
    37   $(progress).addClass('yubikey_bar');
       
    38   var progimg = document.createElement('img');
       
    39   progimg.src = cdnPath + '/images/spacer.gif';
       
    40   progress.appendChild(progimg);
       
    41   mp.appendChild(progress);
    36   var ta = document.createElement('input');
    42   var ta = document.createElement('input');
    37   ta.submitted = false;
    43   ta.submitted = false;
    38   $(ta)
    44   $(ta)
    39     .css('background-color', 'transparent')
    45     .css('background-color', 'transparent')
    40     .css('border-width', '0px')
    46     .css('border-width', '0px')
    52         else if ( this.value.length == 44 && !this.submitted )
    58         else if ( this.value.length == 44 && !this.submitted )
    53         {
    59         {
    54           this.submitted = true;
    60           this.submitted = true;
    55           yk_handle_submit(this);
    61           yk_handle_submit(this);
    56         }
    62         }
       
    63         else
       
    64         {
       
    65           $('div.yubikey_bar > img', this.parentNode)
       
    66             .css('width', String(this.value.length * 2) + 'px')
       
    67             .css('background-position', String(this.value.length - 44) + 'px -88px');
       
    68         }
    57         e.preventDefault();
    69         e.preventDefault();
    58         e.stopPropagation();
    70         e.stopPropagation();
    59       });
    71       });
    60   mp.appendChild(ta);
    72   mp.appendChild(ta);
    61   setTimeout(function()
    73   setTimeout(function()
    64         {
    76         {
    65           ta.focus();
    77           ta.focus();
    66         }, 50);
    78         }, 50);
    67     }, 750);
    79     }, 750);
    68   var info = document.createElement('p');
    80   var info = document.createElement('p');
    69   info.innerHTML = $lang.get('yubiauth_msg_close_instructions');
    81   $(info)
       
    82     .html($lang.get('yubiauth_msg_close_instructions'))
       
    83     .css('margin-top', '0');
    70   mp.appendChild(info);
    84   mp.appendChild(info);
    71 }
    85 }
    72 
    86 
    73 function yk_handle_submit(ta)
    87 function yk_handle_submit(ta)
    74 {
    88 {
    76   {
    90   {
    77     setTimeout(function()
    91     setTimeout(function()
    78       {
    92       {
    79         yk_mb_construct(ta.parentNode);
    93         yk_mb_construct(ta.parentNode);
    80       }, 1000);
    94       }, 1000);
    81     ta.previousSibling.innerHTML = $lang.get('yubiauth_msg_invalid_chars');
    95     $('h3', ta.parentNode).text($lang.get('yubiauth_msg_invalid_chars'));
       
    96     $('div.yubikey_bar > img', this.parentNode).addClass('yubikey_bar_error');
    82     return false;
    97     return false;
    83   }
    98   }
    84   
    99   
    85   window.clearInterval(yk_interval);
   100   window.clearInterval(yk_interval);
    86   
   101   
   112   }
   127   }
   113 }
   128 }
   114 
   129 
   115 function yk_login_validate_reqs(ta)
   130 function yk_login_validate_reqs(ta)
   116 {
   131 {
   117   ta.parentNode.removeChild(ta.nextSibling);
   132   $(ta.parentNode).remove('p');
   118   yubikey_otp_current = ta.value;
   133   yubikey_otp_current = ta.value;
   119   
   134   
   120   ta.previousSibling.innerHTML = $lang.get('yubiauth_msg_validating_otp');
   135   $('h3', ta.parentNode).text($lang.get('yubiauth_msg_validating_otp'));
   121   
   136   
   122   ajaxPost(makeUrlNS('Special', 'Yubikey'), 'get_flags=' + ta.value.substr(0, 12), function(ajax)
   137   ajaxPost(makeUrlNS('Special', 'Yubikey'), 'get_flags=' + ta.value.substr(0, 12), function(ajax)
   123     {
   138     {
   124       if ( ajax.readyState == 4 && ajax.status == 200 )
   139       if ( ajax.readyState == 4 && ajax.status == 200 )
   125       {
   140       {
   127         if ( !check_json_response(ajax.responseText) )
   142         if ( !check_json_response(ajax.responseText) )
   128         {
   143         {
   129           handle_invalid_json(ajax.responseText);
   144           handle_invalid_json(ajax.responseText);
   130           return false;
   145           return false;
   131         }
   146         }
   132         ta.previousSibling.innerHTML = $lang.get('yubiauth_msg_otp_valid');
   147         $('h3', ta.parentNode).text($lang.get('yubiauth_msg_otp_valid'));
   133         var response = parseJSON(ajax.responseText);
   148         var response = parseJSON(ajax.responseText);
   134         if ( response.mode == 'error' )
   149         if ( response.mode == 'error' )
   135         {
   150         {
   136           alert('Yubikey server-side processing error: \n' + response.error);
   151           alert('Yubikey server-side processing error: \n' + response.error);
   137           return false;
   152           return false;