1(function ( $, config, webauthn ) { 2 $( window ).on( 'load', function () { 3 $( '#user_pass' ).prop( 'disabled', false ); 4 } ); 5 6 function renderNotice( type, message ) { 7 var $notice = $( '<div />' ); 8 $notice.addClass( 'notice notice-' + type ); 9 $( '<p />' ).text( message ).appendTo( $notice ); 10 11 $notice.insertBefore( '#loginform' ); 12 } 13 14 function clearNotices() { 15 $( '.notice' ).remove(); 16 } 17 18 $( function () { 19 var $loginForm = $( '#loginform' ), 20 $body = $( 'body' ); 21 22 $body.removeClass( 'no-js' ); 23 24 if ( !webauthn || !webauthn.isAvailable() ) { 25 $( '.itsec-pwls-login__link-wrap--webauthn' ).remove(); 26 } 27 28 $( document ).on( 'click', '.itsec-pwls-login-fallback__link-wrap--type-wp a', function ( e ) { 29 e.preventDefault(); 30 $body.removeClass( 'itsec-pwls-login--show' ).addClass( 'itsec-pwls-login--hide' ); 31 $loginForm.prop( 'action', config.passwordAction ); 32 $( '#user_login' ).prop( 'required', true ); 33 $( '#user_pass' ).prop( 'disabled', false ).prop( 'required', true ); 34 } ); 35 36 $( document ).on( 'click', '.itsec-pwls-login-fallback__link-wrap--type-ml a', function ( e ) { 37 e.preventDefault(); 38 $body.removeClass( 'itsec-pwls-login--hide' ).addClass( 'itsec-pwls-login--show' ); 39 $loginForm.prop( 'action', config.magicAction ); 40 $( '#user_login' ).prop( 'required', false ); 41 $( '#user_pass' ).prop( 'required', false ); 42 } ); 43 44 $( document ).on( 'click', '.itsec-pwls-login__submit-webauthn', function ( e ) { 45 if ( !webauthn ) { 46 return; 47 } 48 49 clearNotices(); 50 51 const $trigger = $( 'button[name="itsec_pwls_webauthn_login"]' ); 52 53 if ( $trigger.val() ) { 54 return; 55 } 56 57 e.preventDefault(); 58 59 const $user = $( 'input[name="itsec_magic_link_username"]' ); 60 webauthn.verifyCredential( $user.val() ).then( function ( response ) { 61 $user.val( response.user ); 62 $trigger.val( response.token ); 63 $trigger.prop( 'type', 'submit' ); 64 $trigger.click(); 65 } ).catch( function ( error ) { 66 renderNotice( 'error', error.message || config.i18n.error ); 67 } ); 68 } ); 69 if ( config.flow === 'method-first' ) { 70 $( '.itsec-pwls-login-fallback' ).insertAfter( '.submit' ); 71 $( document ).on( 'click', '.itsec-pwls-login__link', function ( e ) { 72 e.preventDefault(); 73 74 $loginForm.prop( 'action', config.magicAction ); 75 $( '#user_login' ).prop( 'required', false ); 76 $( '#user_pass' ).prop( 'required', false ); 77 $body.addClass( 'itsec-pwls-login-form' ); 78 79 var type = $( this ).parent().prop( 'class' ).indexOf( 'itsec-pwls-login__link-wrap--webauthn' ) !== -1 ? 'webauthn' : 'magic'; 80 var remove = type === 'webauthn' ? 'magic' : 'webauthn'; 81 $( '.itsec-pwls-login-wrap' ).html( $( '#tmpl-itsec-pwls-login-prompt-form' ).html() ); 82 $( '.itsec-pwls-login__submit-' + remove ).remove(); 83 } ); 84 85 if ( window.location.search.indexOf( 'itsec-pwls-modal=1' ) !== -1 ) { 86 $( '.itsec-pwls-login__link' ).click(); 87 } 88 } else { 89 $loginForm.hide(); 90 $loginForm.before( $( '#tmpl-itsec-pwls-login-user-form' ).html() ); 91 92 var $userForm = $( '#itsec-pwls-login-user-form' ).on( 'submit', function ( e ) { 93 e.preventDefault(); 94 95 var $btn = $( '#itsec-pwls-login-user-form__continue' ).prop( 'disabled', true ); 96 97 $.post( 98 config.ajaxUrl, 99 { 100 action: config.ajaxAction, 101 log : $( '#itsec-pwls-login-user-form__username' ).val(), 102 }, 103 function ( response ) { 104 if ( !response.success ) { 105 alert( response.data.message || config.i18n.error ); 106 107 return; 108 } 109 110 var $html = $( response.data.html ); 111 112 if ( ! webauthn || !webauthn.isAvailable() ) { 113 $( '.itsec-pwls-login__submit-webauthn', $html ).remove(); 114 } 115 116 $( '#user_login' ).parent().remove(); 117 $( '#user_pass' ).prop( 'required', false ); 118 119 $( 'input[name="itsec_pwls_login_user_first"]' ).remove(); 120 $( '#wp-submit' ).val( config.i18n.login ); 121 122 $body.removeClass( 'itsec-pwls-login--no-user' ).addClass( 'itsec-pwls-login--has-user' ); 123 $userForm.hide(); 124 $loginForm.show(); 125 $loginForm.prepend( $html ); 126 127 $( '.itsec-pwls-login-fallback' ).insertAfter( '.submit' ); 128 129 if ( response.data.methods.length > 0 ) { 130 $body.addClass( 'itsec-pwls-login--show itsec-pwls-login--is-available' ); 131 $loginForm.prop( 'action', config.magicAction ); 132 } else { 133 $( '#user_pass' ).prop( 'disabled', false ); 134 } 135 } ) 136 .always( function () { 137 $btn.prop( 'disabled', false ); 138 } ); 139 } ); 140 } 141 } ); 142})( jQuery, window['ITSECMagicLogin'], window.itsec && window.itsec.webauthn && window.itsec.webauthn.utils );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.