DEV: Allow `doLogin` to be called with a set of parameters

This can be used for themes/plugins to specify additional URL parameters to be used when starting authentication. Example usage:

```
LoginMethod.findAll()[0].doLogin({params: {mydata: "myvalue"}});
```
This commit is contained in:
David Taylor 2020-01-08 16:13:12 +00:00
parent 502f154cfc
commit 4d5b142f1d
1 changed files with 10 additions and 2 deletions

View File

@ -21,7 +21,7 @@ const LoginMethod = EmberObject.extend({
return this.message_override || I18n.t(`login.${this.name}.message`);
},
doLogin({ reconnect = false } = {}) {
doLogin({ reconnect = false, params = {} } = {}) {
if (this.customLogin) {
this.customLogin();
return Promise.resolve();
@ -35,7 +35,15 @@ const LoginMethod = EmberObject.extend({
let authUrl = Discourse.getURL(`/auth/${this.name}`);
if (reconnect) {
authUrl += "?reconnect=true";
params["reconnect"] = true;
}
const paramKeys = Object.keys(params);
if (paramKeys.length > 0) {
authUrl += "?";
authUrl += paramKeys
.map(k => `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`)
.join("&");
}
return LoginMethod.buildPostForm(authUrl).then(form => form.submit());