chg: moved recaptcha from claustra to core
This commit is contained in:
parent
62bd495564
commit
3f9d03a6f6
5 changed files with 59 additions and 4 deletions
45
code/Global/Recaptcha.js
Normal file
45
code/Global/Recaptcha.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// The Antville Project
|
||||||
|
// http://code.google.com/p/antville
|
||||||
|
//
|
||||||
|
// Copyright 2001–2014 by the Workers of Antville.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the ``License'');
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fileoverview Defines the Antville reCAPTCHA prototype.
|
||||||
|
* @see http://www.google.com/recaptcha
|
||||||
|
*/
|
||||||
|
|
||||||
|
Recaptcha = {};
|
||||||
|
|
||||||
|
Recaptcha.verify = function (data) {
|
||||||
|
var secret = getProperty('recaptcha.secret');
|
||||||
|
|
||||||
|
if (session.user || !secret) return;
|
||||||
|
|
||||||
|
var response = req.postParams['g-recaptcha-response'];
|
||||||
|
var ip = req.data.remotehost;
|
||||||
|
var mime = getURL('https://www.google.com/recaptcha/api/siteverify?secret=' + secret + '&response=' + response + '&remoteip=' + ip);
|
||||||
|
var json = JSON.parse(new java.lang.String(mime.content));
|
||||||
|
|
||||||
|
if (!json.success) {
|
||||||
|
throw Error(gettext('Do Androids dream of electric sheep?'));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Recaptcha.render = function(context, skin) {
|
||||||
|
var secret = getProperty('recaptcha.secret');
|
||||||
|
if (session.user || !context || !secret) return;
|
||||||
|
if (!skin) skin = '$Members#recaptcha';
|
||||||
|
return context.renderSkinAsString(skin);
|
||||||
|
};
|
|
@ -125,6 +125,7 @@
|
||||||
</div>
|
</div>
|
||||||
<% if <% root.termsStory %> is null then '' else <% members.skin $Members#terms %> %>
|
<% if <% root.termsStory %> is null then '' else <% members.skin $Members#terms %> %>
|
||||||
<% if <% root.privacyStory %> is null then '' then <% members.skin $Members#privacy %> %>
|
<% if <% root.privacyStory %> is null then '' then <% members.skin $Members#privacy %> %>
|
||||||
|
<% param.recaptcha prefix="<div class='uk-form-row'>" suffix="</div>" %>
|
||||||
<div class='uk-form-row uk-margin-top'>
|
<div class='uk-form-row uk-margin-top'>
|
||||||
<button class='uk-button uk-button-primary' type="submit" id="submit" name="register" value="1" tabindex=6>
|
<button class='uk-button uk-button-primary' type="submit" id="submit" name="register" value="1" tabindex=6>
|
||||||
<% gettext Register %>
|
<% gettext Register %>
|
||||||
|
@ -132,7 +133,7 @@
|
||||||
<a href='<% members.href login %>' class="uk-button uk-button-link" tabindex=7><% gettext Cancel %></a>
|
<a href='<% members.href login %>' class="uk-button uk-button-link" tabindex=7><% gettext Cancel %></a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<script type="text/javascript">
|
<script>
|
||||||
$('form#register').submit(function() {
|
$('form#register').submit(function() {
|
||||||
var token = '<% session.token %>';
|
var token = '<% session.token %>';
|
||||||
var password = $('#password').val();
|
var password = $('#password').val();
|
||||||
|
@ -165,7 +166,7 @@
|
||||||
<% if <% root.termsStory %> is null then '' else <% members.skin $Members#terms %> %>
|
<% if <% root.termsStory %> is null then '' else <% members.skin $Members#terms %> %>
|
||||||
<% if <% root.privacyStory %> is null then '' then <% members.skin $Members#privacy %> %>
|
<% if <% root.privacyStory %> is null then '' then <% members.skin $Members#privacy %> %>
|
||||||
<div class='uk-form-row uk-margin-top'>
|
<div class='uk-form-row uk-margin-top'>
|
||||||
<button class='uk-button uk-button-primary' type="submit"" name="accept" value="1" tabindex=6>
|
<button class='uk-button uk-button-primary' type="submit" name="accept" value="1" tabindex=6>
|
||||||
<% gettext Accept %>
|
<% gettext Accept %>
|
||||||
</button>
|
</button>
|
||||||
<a href='<% site.href %>' class="uk-button uk-button-link" tabindex=7><% gettext Cancel %></a>
|
<a href='<% site.href %>' class="uk-button uk-button-link" tabindex=7><% gettext Cancel %></a>
|
||||||
|
@ -257,3 +258,7 @@
|
||||||
<a href='?name=<% param.name encoding=form %>'><i class='uk-icon-plus'></i></a>
|
<a href='?name=<% param.name encoding=form %>'><i class='uk-icon-plus'></i></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<% #recaptcha %>
|
||||||
|
<div class='uk-margin-top g-recaptcha' data-sitekey='<% property recaptcha.sitekey %>'></div>
|
||||||
|
<script src='https://www.google.com/recaptcha/api.js?hl=<% site.locale %>'></script>
|
||||||
|
|
|
@ -88,6 +88,7 @@ Members.prototype.main_action = function() {
|
||||||
Members.prototype.register_action = function() {
|
Members.prototype.register_action = function() {
|
||||||
if (req.postParams.register) {
|
if (req.postParams.register) {
|
||||||
try {
|
try {
|
||||||
|
Recaptcha.verify(req.postParams);
|
||||||
if (root.termsStory && !req.postParams.terms) throw Error('Please accept the terms and conditions.');
|
if (root.termsStory && !req.postParams.terms) throw Error('Please accept the terms and conditions.');
|
||||||
if (root.privacyStory && !req.postParams.privacy) throw Error('Please accept the data privacy statement.');
|
if (root.privacyStory && !req.postParams.privacy) throw Error('Please accept the data privacy statement.');
|
||||||
var title = res.handlers.site.title;
|
var title = res.handlers.site.title;
|
||||||
|
@ -107,7 +108,8 @@ Members.prototype.register_action = function() {
|
||||||
session.data.token = User.getSalt();
|
session.data.token = User.getSalt();
|
||||||
res.data.action = this.href(req.action);
|
res.data.action = this.href(req.action);
|
||||||
res.data.title = gettext('Register');
|
res.data.title = gettext('Register');
|
||||||
res.data.body = this.renderSkinAsString('$Members#register');
|
var param = { recaptcha: Recaptcha.render(this) };
|
||||||
|
res.data.body = this.renderSkinAsString('$Members#register', param);
|
||||||
this._parent.renderSkin('Site#page');
|
this._parent.renderSkin('Site#page');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@
|
||||||
<textarea class='uk-width-1-1' rows="15" class="formText" wrap="virtual" name="text"><% request.text encoding="form" %></textarea>
|
<textarea class='uk-width-1-1' rows="15" class="formText" wrap="virtual" name="text"><% request.text encoding="form" %></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% param.recaptcha prefix="<div class='uk-form-row'>" suffix='</div>' %>
|
||||||
<div class='uk-form-row'>
|
<div class='uk-form-row'>
|
||||||
<button class='uk-button uk-button-primary' type="submit" id="submit" name="send" value="1" tabindex=4>
|
<button class='uk-button uk-button-primary' type="submit" id="submit" name="send" value="1" tabindex=4>
|
||||||
<% gettext Send %>
|
<% gettext Send %>
|
||||||
|
|
|
@ -192,6 +192,7 @@ Membership.prototype.contact_action = function() {
|
||||||
if (!req.postParams.text) {
|
if (!req.postParams.text) {
|
||||||
throw Error(gettext('Please enter the message text.'));
|
throw Error(gettext('Please enter the message text.'));
|
||||||
}
|
}
|
||||||
|
Recaptcha.verify(req.postParams);
|
||||||
this.notify(req.action, this.creator.email, session.user ?
|
this.notify(req.action, this.creator.email, session.user ?
|
||||||
gettext('[{0}] Message from user {1}', root.title, session.user.name) :
|
gettext('[{0}] Message from user {1}', root.title, session.user.name) :
|
||||||
gettext('[{0}] Message from anonymous user', root.title));
|
gettext('[{0}] Message from anonymous user', root.title));
|
||||||
|
@ -206,7 +207,8 @@ Membership.prototype.contact_action = function() {
|
||||||
|
|
||||||
res.data.action = this.href(req.action);
|
res.data.action = this.href(req.action);
|
||||||
res.data.title = gettext('Contact {0}', this.name);
|
res.data.title = gettext('Contact {0}', this.name);
|
||||||
res.data.body = this.renderSkinAsString('$Membership#contact');
|
var param = { recaptcha: Recaptcha.render(res.handlers.members) };
|
||||||
|
res.data.body = this.renderSkinAsString('$Membership#contact', param);
|
||||||
this.site.renderSkin('Site#page');
|
this.site.renderSkin('Site#page');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue