DEV: Pass signup=true to auth providers when signup buttons used (#12337)

This allows auth provider plugins to behave differently for login / signup. Previously, there was no way for them to know which button had been used.

This change will be a no-op in the majority of cases. If auth plugins wish to make use of this new feature, they should check for ?signup=true in the URL. For example: https://github.com/discourse/discourse-oauth2-basic/pull/34
This commit is contained in:
David Taylor 2021-03-10 12:16:21 +00:00 committed by GitHub
parent a1df45c6bc
commit cbef2ba151
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 7 deletions

View File

@ -359,7 +359,7 @@ export default Controller.extend(
actions: {
externalLogin(provider) {
this.login.send("externalLogin", provider);
this.login.send("externalLogin", provider, { signup: true });
},
createAccount() {

View File

@ -233,6 +233,7 @@ export default Controller.extend(
externalLogin(provider) {
provider.doLogin({
signup: true,
params: {
origin: window.location.href,
},

View File

@ -267,13 +267,15 @@ export default Controller.extend(ModalFunctionality, {
return false;
},
externalLogin(loginMethod) {
externalLogin(loginMethod, { signup = false } = {}) {
if (this.loginDisabled) {
return;
}
this.set("loggingIn", true);
loginMethod.doLogin().catch(() => this.set("loggingIn", false));
loginMethod
.doLogin({ signup: signup })
.catch(() => this.set("loggingIn", false));
},
createAccount() {

View File

@ -23,7 +23,7 @@ const LoginMethod = EmberObject.extend({
return this.message_override || I18n.t(`login.${this.name}.message`);
},
doLogin({ reconnect = false, params = {} } = {}) {
doLogin({ reconnect = false, signup = false, params = {} } = {}) {
if (this.customLogin) {
this.customLogin();
return Promise.resolve();
@ -40,6 +40,10 @@ const LoginMethod = EmberObject.extend({
params["reconnect"] = true;
}
if (signup) {
params["signup"] = true;
}
const paramKeys = Object.keys(params);
if (paramKeys.length > 0) {
authUrl += "?";

View File

@ -258,15 +258,17 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
const returnPath = encodeURIComponent(window.location.pathname);
window.location = getURL("/session/sso?return_path=" + returnPath);
} else {
this._autoLogin("createAccount", "create-account");
this._autoLogin("createAccount", "create-account", { signup: true });
}
},
_autoLogin(modal, modalClass, notAuto) {
_autoLogin(modal, modalClass, notAuto, { signup = false } = {}) {
const methods = findAll();
if (!this.siteSettings.enable_local_logins && methods.length === 1) {
this.controllerFor("login").send("externalLogin", methods[0]);
this.controllerFor("login").send("externalLogin", methods[0], {
signup: signup,
});
} else {
showModal(modal);
this.controllerFor("modal").set("modalClass", modalClass);