<form action="sysUser/update?callbackType=closeCurrent" method="post" autocomplete="off" class="pageForm required-validate" onsubmit="return validateCallback(this, ${(target?has_content&&'dialog'=target)?then('dialogAjaxDone','navTabAjaxDone')});">
    <input type="hidden" name="_csrf" value="<@tools.csrfToken admin=true/>"/>
    <div class="formBar card">
        <ul>
            <li><button type="submit" class="buttonActive" title="ctrl+s"><@t.page 'button.save'/></button></li>
            <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
        </ul>
    </div>
    <div class="card">
        <div class="pageFormContent" layoutH>
            <dl class="nowrap">
                <dt><@t.page 'user.nickname'/>:</dt>
                <dd><input class="required" name="nickname" type="text" size="20" maxlength="30" value="${(admin.nickname)!}"/></dd>
            </dl>
            <dl class="nowrap">
                <dt><@t.page 'cover'/>:</dt>
                <dd>
                    <input name="cover" class="preview" value="${(admin.cover)!}" maxlength="300" size="50" type="text"/>
                    <a class="btnAttach" href="common/upload.html?field=cover&fileTypes=image" lookupGroup="" width="1000" height="600"><@t.page 'cover'/></a>
                    <a class="view icon-eye-open" ref="cover" data-prefix="${getFileUploadPrefix()}" href="javascript:void(0);" target="_blank"><@t.page 'button.view'/></a>
                </dd>
            </dl>
            <dl class="nowrap">
                <dt><@t.page 'email'/>:</dt>
                <dd><input name="email" type="text" size="30" maxlength="50" value="${(admin.email)!}"/></dd>
            </dl>
            <dl class="nowrap">
                <dt><@t.page 'login.2fa'/>:</dt>
                <dd>
                    <a class="button bindbtn unbind" href="otpSetting/unbind?_csrf=<@tools.csrfToken admin=true/>" target="ajaxTodo" callback="${(target?has_content&&'dialog'=target)?then('$.pdialog.closeCurrent()','navTab.reloadFlag(\'myself/profile\')')}"><@t.page 'button.unbind'/></a>
                    <a class="button bindbtn bind" href="myself/otpsettings.html" target="dialog" mask="true"><@t.page 'button.bind'/></a>
                </dd>
            </dl>
            <dl class="nowrap">
                <dt><@t.page 'password'/>:</dt>
                <dd>
                    <a class="button" href="myself/password.html" target="dialog" width="450" height="320" mask="true"><@t.page 'change_password'/></a>
                </dd>
            </dl>
            <dl class="nowrap">
                <dt><@t.page 'login.fingerprint'/>:</dt>
                <dd>
                    <div class="image-list">
                        <a href="javascript:void(0)" class="addfingerprint">
                            <i class="thumb bi bi-plus-circle-dotted"></i>
                            <p><@t.page 'button.add'/></p>
                        </a>
                    </div>
                </dd>
            </dl>
        </div>
    </div>
</form>
<script src="${base}/resource/plugins/webauthn/webauthn-simple-app.js"></script>
<script>
$.ajax({
    url:'otpSetting/check',
    type: 'POST',
    dataType: "json",
    async: false,
    success: function (result) {
        $('.bindbtn', ${(target?has_content&&'dialog'=target)?then('$.pdialog.getCurrent()','navTab.getCurrentPanel()')}).hide();
        if(result){
            $('.bind', ${(target?has_content&&'dialog'=target)?then('$.pdialog.getCurrent()','navTab.getCurrentPanel()')}).show();
        } else {
            $('.unbind', ${(target?has_content&&'dialog'=target)?then('$.pdialog.getCurrent()','navTab.getCurrentPanel()')}).show();
        }
    }
});
function hideFingerprint(){
    $(".addfingerprint", ${(target?has_content&&'dialog'=target)?then('$.pdialog.getCurrent()','navTab.getCurrentPanel()')}).parent().hide();
}
var btnAddFingerprint=$('.addfingerprint', ${(target?has_content&&'dialog'=target)?then('$.pdialog.getCurrent()','navTab.getCurrentPanel()')}).on("click",function(){
    window.webAuthnApp.register().then(()=>{
        loadFingerprint();
    }).catch((err)=>{
        alertMsg.error(err.message)
    });
    return false;
});
function loadFingerprint(){
    btnAddFingerprint.parent().prevAll().remove();
    $.ajax({
        url:'webauthn/getCredentials',
        type: 'GET',
        dataType: "json",
        async: false,
        success: function (result) {
            if(result&&result.credentials){
                $.each(result.credentials,function(i,value){
                    initLink($("<div class=\"image-list\"><i class=\"thumb bi bi-fingerprint\"></i><p><a href=\"webauthn/deleteCredential?credentialId="+encodeURIComponent(value)+"\" target=\"ajaxTodo\" callback=\"${(target?has_content&&'dialog'=target)?then('$.pdialog.closeCurrent()','navTab.reloadFlag(\'myself/profile\')')}\"><@t.page 'button.delete'/></a></p></div>").insertBefore(btnAddFingerprint.parent()));
                });
            }
        }
    });
}
if(!window.webAuthnApp){
    $(document).on("webauthn-not-supported", (err) => {
        hideFingerprint();
    });
    window.webAuthnApp=new WebAuthnApp({
        username : "${admin.name}",
        registerChallengeEndpoint : "${base+adminContextPath}/webauthn/attestation/options",
        registerResponseEndpoint : "${base+adminContextPath}/webauthn/attestation/result"
    });
}
loadFingerprint();
</script>