Only show recaptcha for anonymous users, send token to API

This commit is contained in:
Jesse 2020-07-08 03:40:31 -04:00
parent 82596e8ee9
commit 58d2c273bb
No known key found for this signature in database
GPG key ID: 1A8AB3257B32D91F
3 changed files with 13 additions and 7 deletions

View file

@ -30,7 +30,7 @@ class UserRegistrationController {
user.email = e.detail.email; user.email = e.detail.email;
user.password = e.detail.password; user.password = e.detail.password;
const isLoggedIn = api.isLoggedIn(); const isLoggedIn = api.isLoggedIn();
user.save() user.save(e.detail.recaptchaToken)
.then(() => { .then(() => {
if (isLoggedIn) { if (isLoggedIn) {
return Promise.resolve(); return Promise.resolve();

View file

@ -107,7 +107,7 @@ class User extends events.EventTarget {
}); });
} }
save() { save(recaptchaToken) {
const files = []; const files = [];
const detail = { version: this._version }; const detail = { version: this._version };
const transient = this._orig._name; const transient = this._orig._name;
@ -131,6 +131,9 @@ class User extends events.EventTarget {
if (this._password) { if (this._password) {
detail.password = this._password; detail.password = this._password;
} }
if (!api.isLoggedIn()) {
detail.recaptchaToken = recaptchaToken;
}
let promise = this._orig._name let promise = this._orig._name
? api.put( ? api.put(

View file

@ -22,6 +22,9 @@ class RegistrationView extends events.EventTarget {
views.decorateValidator(this._formNode); views.decorateValidator(this._formNode);
this._formNode.addEventListener("submit", (e) => this._evtSubmit(e)); this._formNode.addEventListener("submit", (e) => this._evtSubmit(e));
this.setRecaptchaToken = this.setRecaptchaToken.bind(this); this.setRecaptchaToken = this.setRecaptchaToken.bind(this);
// Show the recaptcha for anonymous users.
if (!api.isLoggedIn())
this.renderRecaptcha(); this.renderRecaptcha();
} }