-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapi.tmpl
55 lines (49 loc) · 1.41 KB
/
api.tmpl
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
{{ define "content" }}
{{ if .alert }}
<div class="alert alert-{{ if .valid }}success{{ else }}danger{{ end }}" role="alert">
{{ .alert }}
</div>
{{ end }}
<form class="container" action="/?driver={{ .driver }}" method="POST" onsubmit="return false;">
<div class="form-group row">
<input type="text" class="form-control col-md-2" id="captcha" name="captcha">
<div class="col-md-10">
<input type="hidden" class="form-control col-md-2" id="captchaID" name="captcha_id">
<img src="" id="captchaIMG">
</div>
</div>
<div class="form-group row">
<button type="button" class="btn btn-primary" id="btnSubmit">Submit</button>
</div>
</form>
<script>
$(document).ready(function() {
var captcha = $('#captcha')
var captchaID = $('#captchaID')
var captchaIMG = $('#captchaIMG')
generate()
captchaIMG.click(function() {
generate()
})
function generate() {
captchaID.val('')
captchaIMG.attr('src', '')
$.post('/generate', function (resp) {
console.log(resp)
captchaID.val(resp.id)
captchaIMG.attr("src", resp.data)
}, 'json')
}
$('#btnSubmit').click(function() {
$.post('/validate', {
"captcha_id": captchaID.val(),
"captcha": captcha.val(),
}, function (resp) {
console.log(resp)
alert(resp.msg)
generate()
}, 'json')
})
})
</script>
{{ end }}