Skip to content

Commit

Permalink
Include captcha service for request account
Browse files Browse the repository at this point in the history
  • Loading branch information
sMesHer committed May 23, 2011
1 parent d6247fe commit 513c16d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
38 changes: 38 additions & 0 deletions etherpad/src/etherpad/control/pro/account_control.js
Expand Up @@ -23,6 +23,7 @@ import("cache_utils.syncedWithCache");
import("etherpad.helpers");
import("etherpad.utils.*");
import("etherpad.sessions.getSession");
import("etherpad.sessions.getSessionId");
import("etherpad.pro.pro_accounts");
import("etherpad.pro.pro_accounts.getSessionProAccount");
import("etherpad.pro.domains");
Expand All @@ -34,6 +35,11 @@ import("etherpad.pad.padutils");
import("etherpad.pad.padusers");
import("etherpad.collab.collab_server");

jimport("java.awt.image.BufferedImage");
jimport("javax.imageio.ImageIO");
jimport("com.octo.captcha.service.image.ImageCaptchaService");
jimport("com.octo.captcha.service.image.DefaultManageableImageCaptchaService");

function onRequest() {
if (!getSession().tempFormData) {
getSession().tempFormData = {};
Expand Down Expand Up @@ -222,6 +228,26 @@ function render_sign_in_post() {
_redirectToPostSigninDestination();
}

function create_captcha()
{
if(!appjet.cache.captchaservice)
{
appjet.cache.captchaservice = new DefaultManageableImageCaptchaService();
}

captcha = appjet.cache.captchaservice.getImageChallengeForID(getSessionId());
return captcha;
}

function render_request_account_captcha_get() {
rendImage = create_captcha();
jos = new java.io.ByteArrayOutputStream();
ImageIO.write(rendImage, 'PNG', jos);

response.setContentType('image/png');
response.writeBytes(jos.toByteArray());
}

function render_request_account_get() {
_renderTemplate('requestaccount', {
domain: pro_utils.getFullProDomain(),
Expand All @@ -237,9 +263,21 @@ function render_request_account_post() {

var fullname = trim(request.params.fullname);
var email = trim(request.params.email).toLowerCase();
var captcha = request.params.captcha;

getSession().tempFormData.fullname = fullname;
getSession().tempFormData.email = email;
try {
isResponseCorrect = appjet.cache.captchaservice.validateResponseForID(getSessionId(), captcha);

if(!isResponseCorrect)
{
_redirOnError("Captcha is incorrect!");
}
} catch (e) {
//should not happen, may be thrown if the id is not valid
_redirOnError("Captcha is incorrect!");
}

var accountExists = pro_accounts.getAccountByEmail(email, domainId);
if(typeof accountExists == "undefined")
Expand Down
3 changes: 2 additions & 1 deletion etherpad/src/etherpad/pro/pro_accounts.js
Expand Up @@ -294,7 +294,8 @@ function requireAccount(message) {
(request.path == "/ep/account/guest-sign-in") ||
(request.path == "/ep/account/guest-knock") ||
(request.path == "/ep/account/forgot-password") ||
(request.path == "/ep/account/request-account")) {
(request.path == "/ep/account/request-account") ||
(request.path == "/ep/account/request-account-captcha")) {
return;
}

Expand Down
Expand Up @@ -42,7 +42,17 @@ limitations under the License. */ %><% helpers.includeJQuery() %>
%>" />
<%= helpers.clearFloats() %>
</div>


<img src="/ep/account/request-account-captcha" />
<%= helpers.clearFloats() %>
<div>
<label for="captcha" id="capcha-label">Captcha</label>
<input class="textin" type="text" name="captcha" id="captcha" value="" />
<%= helpers.clearFloats() %>
<div>

</div>


<button type="submit" class="bluebutton bluebutton120" id="signInButton">
Request
Expand Down
Binary file added infrastructure/lib/jcaptcha-1.0-all.jar
Binary file not shown.

0 comments on commit 513c16d

Please sign in to comment.