login.min.js 1.4 KB

1
  1. if(window!==top){top.location.href=location.href}layui.use(["request","form","button","yaml"],function(){var t=layui.jquery,n=layui.request,e=layui.form,i=layui.button,a=layui.yaml;var o=a.load("config/cool.config.yml").admin.url;var r;window.captcha=function(){t.get(n.getAdminServerUrl()+"/guest/captcha?"+Math.random(),function(e){if(e.success){t('[name="key"]').val(e.data.key);t("#captchaImage").attr("src",e.data.image)}})};layer.ready(function(){layui.data("server",null);layui.data("server",{key:"url",value:o});layui.data("server",{key:"login",value:location.href});t.get(n.getAdminServerUrl()+"/guest/pki",function(e){if(e.success){r=e.data}});window.captcha()});e.on("submit(login)",function(e){var a=i.load({elem:".login"});e.field.captcha=t("#getRegisterCaptcha").val();e.field.password=encrypt(e.field.password);n.http({url:"/login",data:e.field,type:"post",dataType:"json",sendToken:false,success:function(e){a.stop(function(){if(e.success){layui.data("server",{key:"accessToken",value:{name:"accessToken",value:e.data.accessToken}});i.load({elem:".login",time:200,done:function(){location.href="index.html"}})}else{layer.msg(e.msg,{icon:2,time:1500});captcha()}})}});return false});window.empty=function(e){t('[name="'+e+'"]').val("")};window.encrypt=function(e){if(r){var a=new JSEncrypt;a.setPublicKey("-----BEGIN PUBLIC KEY-----"+r+"-----END PUBLIC KEY-----");return a.encrypt(JSON.stringify(e))}else{layer.msg("password rsa error");return false}}});