From 6e178e2eed061e6048b2a104616d4ab35c499b47 Mon Sep 17 00:00:00 2001 From: Jesse <2302541+Kangaroux@users.noreply.github.com> Date: Wed, 8 Jul 2020 05:08:54 -0400 Subject: [PATCH] Refactor recaptchaEnabled --- client/js/api.js | 2 +- client/js/models/user.js | 2 +- client/js/views/registration_view.js | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/client/js/api.js b/client/js/api.js index 21ec235d..2df1fdf1 100644 --- a/client/js/api.js +++ b/client/js/api.js @@ -113,7 +113,7 @@ class Api extends events.EventTarget { } recaptchaEnabled() { - return !!remoteConfig.enableRecaptcha; + return !this.isLoggedIn() && !!remoteConfig.enableRecaptcha; } hasPrivilege(lookup) { diff --git a/client/js/models/user.js b/client/js/models/user.js index e682f4b4..5efbf3ec 100644 --- a/client/js/models/user.js +++ b/client/js/models/user.js @@ -131,7 +131,7 @@ class User extends events.EventTarget { if (this._password) { detail.password = this._password; } - if (!api.isLoggedIn()) { + if (api.recaptchaEnabled) { detail.recaptchaToken = recaptchaToken; } diff --git a/client/js/views/registration_view.js b/client/js/views/registration_view.js index 4870c871..898d606c 100644 --- a/client/js/views/registration_view.js +++ b/client/js/views/registration_view.js @@ -9,17 +9,13 @@ const template = views.getTemplate("user-registration"); class RegistrationView extends events.EventTarget { constructor() { super(); - - // Show the recaptcha only for anonymous users. - const showRecaptcha = (!api.isLoggedIn() && api.recaptchaEnabled()); - this._hostNode = document.getElementById("content-holder"); views.replaceContent( this._hostNode, template({ userNamePattern: api.getUserNameRegex(), passwordPattern: api.getPasswordRegex(), - enableRecaptcha: showRecaptcha, + enableRecaptcha: api.recaptchaEnabled(), }) ); views.syncScrollPosition();