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,13 +131,16 @@ 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(
uri.formatApiLink("user", this._orig._name), uri.formatApiLink("user", this._orig._name),
detail, detail,
files files
) )
: api.post(uri.formatApiLink("users"), detail, files); : api.post(uri.formatApiLink("users"), detail, files);
return promise.then((response) => { return promise.then((response) => {

View file

@ -22,7 +22,10 @@ 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);
this.renderRecaptcha();
// Show the recaptcha for anonymous users.
if (!api.isLoggedIn())
this.renderRecaptcha();
} }
renderRecaptcha() { renderRecaptcha() {