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:
parent
a1df45c6bc
commit
cbef2ba151
|
@ -359,7 +359,7 @@ export default Controller.extend(
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
externalLogin(provider) {
|
externalLogin(provider) {
|
||||||
this.login.send("externalLogin", provider);
|
this.login.send("externalLogin", provider, { signup: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
createAccount() {
|
createAccount() {
|
||||||
|
|
|
@ -233,6 +233,7 @@ export default Controller.extend(
|
||||||
|
|
||||||
externalLogin(provider) {
|
externalLogin(provider) {
|
||||||
provider.doLogin({
|
provider.doLogin({
|
||||||
|
signup: true,
|
||||||
params: {
|
params: {
|
||||||
origin: window.location.href,
|
origin: window.location.href,
|
||||||
},
|
},
|
||||||
|
|
|
@ -267,13 +267,15 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
externalLogin(loginMethod) {
|
externalLogin(loginMethod, { signup = false } = {}) {
|
||||||
if (this.loginDisabled) {
|
if (this.loginDisabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set("loggingIn", true);
|
this.set("loggingIn", true);
|
||||||
loginMethod.doLogin().catch(() => this.set("loggingIn", false));
|
loginMethod
|
||||||
|
.doLogin({ signup: signup })
|
||||||
|
.catch(() => this.set("loggingIn", false));
|
||||||
},
|
},
|
||||||
|
|
||||||
createAccount() {
|
createAccount() {
|
||||||
|
|
|
@ -23,7 +23,7 @@ const LoginMethod = EmberObject.extend({
|
||||||
return this.message_override || I18n.t(`login.${this.name}.message`);
|
return this.message_override || I18n.t(`login.${this.name}.message`);
|
||||||
},
|
},
|
||||||
|
|
||||||
doLogin({ reconnect = false, params = {} } = {}) {
|
doLogin({ reconnect = false, signup = false, params = {} } = {}) {
|
||||||
if (this.customLogin) {
|
if (this.customLogin) {
|
||||||
this.customLogin();
|
this.customLogin();
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
@ -40,6 +40,10 @@ const LoginMethod = EmberObject.extend({
|
||||||
params["reconnect"] = true;
|
params["reconnect"] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (signup) {
|
||||||
|
params["signup"] = true;
|
||||||
|
}
|
||||||
|
|
||||||
const paramKeys = Object.keys(params);
|
const paramKeys = Object.keys(params);
|
||||||
if (paramKeys.length > 0) {
|
if (paramKeys.length > 0) {
|
||||||
authUrl += "?";
|
authUrl += "?";
|
||||||
|
|
|
@ -258,15 +258,17 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
|
||||||
const returnPath = encodeURIComponent(window.location.pathname);
|
const returnPath = encodeURIComponent(window.location.pathname);
|
||||||
window.location = getURL("/session/sso?return_path=" + returnPath);
|
window.location = getURL("/session/sso?return_path=" + returnPath);
|
||||||
} else {
|
} 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();
|
const methods = findAll();
|
||||||
|
|
||||||
if (!this.siteSettings.enable_local_logins && methods.length === 1) {
|
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 {
|
} else {
|
||||||
showModal(modal);
|
showModal(modal);
|
||||||
this.controllerFor("modal").set("modalClass", modalClass);
|
this.controllerFor("modal").set("modalClass", modalClass);
|
||||||
|
|
Loading…
Reference in New Issue