Only show recaptcha for anonymous users, send token to API
This commit is contained in:
parent
82596e8ee9
commit
58d2c273bb
3 changed files with 13 additions and 7 deletions
|
@ -30,7 +30,7 @@ class UserRegistrationController {
|
|||
user.email = e.detail.email;
|
||||
user.password = e.detail.password;
|
||||
const isLoggedIn = api.isLoggedIn();
|
||||
user.save()
|
||||
user.save(e.detail.recaptchaToken)
|
||||
.then(() => {
|
||||
if (isLoggedIn) {
|
||||
return Promise.resolve();
|
||||
|
|
|
@ -107,7 +107,7 @@ class User extends events.EventTarget {
|
|||
});
|
||||
}
|
||||
|
||||
save() {
|
||||
save(recaptchaToken) {
|
||||
const files = [];
|
||||
const detail = { version: this._version };
|
||||
const transient = this._orig._name;
|
||||
|
@ -131,13 +131,16 @@ class User extends events.EventTarget {
|
|||
if (this._password) {
|
||||
detail.password = this._password;
|
||||
}
|
||||
if (!api.isLoggedIn()) {
|
||||
detail.recaptchaToken = recaptchaToken;
|
||||
}
|
||||
|
||||
let promise = this._orig._name
|
||||
? api.put(
|
||||
uri.formatApiLink("user", this._orig._name),
|
||||
detail,
|
||||
files
|
||||
)
|
||||
uri.formatApiLink("user", this._orig._name),
|
||||
detail,
|
||||
files
|
||||
)
|
||||
: api.post(uri.formatApiLink("users"), detail, files);
|
||||
|
||||
return promise.then((response) => {
|
||||
|
|
|
@ -22,7 +22,10 @@ class RegistrationView extends events.EventTarget {
|
|||
views.decorateValidator(this._formNode);
|
||||
this._formNode.addEventListener("submit", (e) => this._evtSubmit(e));
|
||||
this.setRecaptchaToken = this.setRecaptchaToken.bind(this);
|
||||
this.renderRecaptcha();
|
||||
|
||||
// Show the recaptcha for anonymous users.
|
||||
if (!api.isLoggedIn())
|
||||
this.renderRecaptcha();
|
||||
}
|
||||
|
||||
renderRecaptcha() {
|
||||
|
|
Reference in a new issue