-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
login.js
executable file
·129 lines (122 loc) · 4.28 KB
/
login.js
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import axios from "axios"
import swal from 'sweetalert';
function getCaptchaInputValue(){
const inputs = document.querySelectorAll('input[isCaptchaInput]');
let v;
if(inputs.length>0){
v = inputs[0].value
}
if(!v){
v = localStorage.getItem("captcha_token")
}
return v;
}
const form = {
data() {
return {
username:null,
password:null,
csrf_token:null,
captcha:null
}
},
methods: {
submit(){
if(getCaptchaInputValue()){
this.captcha = getCaptchaInputValue()
}
axios.post("/admin/login",{username:this.username,password:this.password,_token:csrf_token,captcha:this.captcha})
.then(function(response){
var data = response.data
var content="";
if(data.success===false){
if(data.result instanceof Array){
data.result.forEach(element => {
content = content+element+"\n"
});
swal({
icon : "error",
title: "出错啦!",
text:content
});
}
}else{
// 登陆成功
swal({
icon : "success",
title: "Success",
text: data.result.msg
});
setTimeout(() => {
location.href=data.result.url
}, 1500);
}
})
.catch(function(error){
swal({
icon : "error",
title: "请求错误,详细查看控制台输出",
});
console.log(error)
})
}
},
}
Vue.createApp(form).mount("#form")
window.onloadTurnstileCallback = function () {
if (document.getElementById("captcha-container")) {
turnstile.render('#captcha-container', {
sitekey: captcha_config.cloudflare,
theme: system_theme,
callback: function (token) {
console.log('Captcha token: ' + token)
const captchaInputs = document.querySelectorAll('input[isCaptchaInput]');
captchaInputs.forEach(input => {
input.value = token;
});
localStorage.setItem("captcha_token", token)
const needCaptchaBtn = document.querySelectorAll('button[isNeedCaptcha]');
needCaptchaBtn.forEach((button) => {
button.removeAttribute('disabled');
});
},
});
}
}
window.onloadGoogleRecaptchaCallback = function () {
if (document.getElementById("captcha-container")) {
grecaptcha.render('captcha-container', {
'sitekey': captcha_config.recaptcha, //公钥
'theme': system_theme, //主题颜色,有light与dark两个值可选
'size': 'normal',//尺寸规则,有normal与compact两个值可选
'callback': function (response) {
console.log('Captcha token: ' + response)
const captchaInputs = document.querySelectorAll('input[isCaptchaInput]');
captchaInputs.forEach(input => {
input.value = response;
});
localStorage.setItem("captcha_token", response)
const needCaptchaBtn = document.querySelectorAll('button[isNeedCaptcha]');
needCaptchaBtn.forEach((button) => {
button.removeAttribute('disabled');
});
},
})
}
}
// 自动刷新验证码
document.addEventListener("DOMContentLoaded", function() {
const buttons = document.querySelectorAll("button[isNeedCaptcha]");
buttons.forEach(button => {
button.addEventListener("click", function() {
switch (captcha_config.service) {
case "google":
grecaptcha.reset();
break;
case "cloudflare":
turnstile.reset();
break;
}
});
});
});