-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_recaptcha.pl
38 lines (34 loc) · 1009 Bytes
/
test_recaptcha.pl
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
:- module(test_recaptcha,
[
]).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_parameters)).
:- use_module(library(http/html_write)).
:- use_module(library(http/recaptcha)).
:- http_handler(root(test/recaptcha), captcha_form, []).
:- http_handler(root(test/callback), captcha_callback, []).
captcha_form(_Request) :-
reply_html_page(
plain,
title('Captcha test'),
\form).
form -->
{ http_link_to_id(captcha_callback, [], HREF)
},
html(h1('Test page for recaptcha configuration')),
html(form([method('POST'), action(HREF)],
[ \recaptcha([]),
input([name(name)]),
input(type(submit))
])).
captcha_callback(Request) :-
recaptcha_parameters(RecapthaParams),
http_parameters(Request,
RecapthaParams,
[form_data(Form)]),
format('Content-type: text/plain\n\n'),
print_term(Form, [output(current_output)]),
( recaptcha_verify(Request, RecapthaParams)
-> format('Welcome human!~n')
; format('Go away, alien!~n')
).