forked from fcardinaux/mod_recaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
142 lines (100 loc) · 4.31 KB
/
README
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
130
131
132
133
134
135
136
137
138
139
mod_recaptcha Readme File
=========================
Author: François Cardinaux, CH 1207 Geneva (http://bit.ly/qTaona)
Overview of the current folder:
* The current folder is dedicated to the mod_recaptcha module for Zotonic
(http://www.zotonic.com)
* It contains all files that are necessary to this project
* There is no symlink of any sort to external resources
Credits
-------
The following references have been helpful to write this module:
* the reCaptcha API: http://code.google.com/apis/recaptcha/
* How to make HTTP post:
http://erlangexamples.com/2009/02/24/how-to-make-http-post/
* recaptcha-erlang: http://code.google.com/p/recaptcha-erlang/
Installation
------------
1. Copy this folder to /path/to/zotonic/modules/
2. Start Zotonic
3. Open your site with a web browser and log in as admin
4. Open the amnistration interface (http://<your site>/admin)
5. Enable the Recaptcha module: go "Modules", find the "Recaptcha" module and
click on "activate"
6. Go to "System" and click on "rescan modules"
Configuration
-------------
1. Go to http://www.google.com/recaptcha and follow the instructions to create
your Recaptcha keys (one public key and one private key)
2. Open the amnistration interface (http://<your site>/admin)
3. Go to "Config" and click on "make a new config setting"
Module: mod_recaptcha
Key: public_key
Value: <your public key>
4. Always in "Config", click on "make a new config setting" again
Module: mod_recaptcha
Key: private_key
Value: <your private key>
Using mod_recaptcha on signup forms
-----------------------------------
Edit your signup form template (typically signup.tpl) and add the following
line where you want the captcha to appear:
{% include "_captcha.tpl" %}
Using mod_recaptcha on other forms
----------------------------------
1. Edit your form template and add the following line where you want the
captcha to appear:
{% include "_captcha.tpl" %}
2. Add the following code to your form processing:
...
case mod_recaptcha:check_recaptcha(Context) of
ok ->
process_form(Context);
{error, Error} ->
display_error_message(Error)
end,
...
% Implementation not shown here
process_form(_Context) ->
todo.
% Implementation not shown here
display_error_message(_Error) ->
todo.
3. Recompile Zotonic
Disabling recaptcha with an observer
------------------------------------
Why
...
By default, recaptcha is enabled if and only if the module mod_recaptcha is
enabled.
In some situations however, you may want to disable recaptcha
programmatically, depending on some variables of your system. For instance,
suppose that you are starting a membership-based website, and that during
the initial period you want to restrict the use of your signup form to
invited people only. In this case, you don't want to annoy them with a
captcha, since their e-mail address is checked against a control list
anyway. However, you want that recaptcha remains enabled on other forms
of the site, e.g. your contact form.
How
...
The simplest way to program this is to use the observer
observe_recaptcha_enabled/3.
1. Edit your main site module (/path/to/zotonic/priv/sites/mysite/mysite.erl)
and add the following lines:
-export([observe_recaptcha_enabled/3]).
observe_recaptcha_enabled(recaptcha_enabled, Acc, Context) ->
case Acc of
true ->
InviationOnly = is_signup_upon_invitation_only(),
Path = m_req:get(path, Context),
case {InviationOnly, Path} of
{true, "/signup"} ->
false; % This disables recaptcha
_ ->
true
end;
_ -> Acc
end.
is_signup_upon_invitation_only() ->
true. % You may read this value from a configuration register
2. Recompile Zotonic