REFACTOR: login-method model (#7703)

This commit is contained in:
Joffrey JAFFEUX 2019-06-05 12:35:41 +02:00 committed by GitHub
parent 80459d83a4
commit 1178f4865b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 14 deletions

View File

@ -13,7 +13,7 @@ const LoginMethod = Ember.Object.extend({
@computed @computed
message() { message() {
return this.message_override || I18n.t("login." + this.name + ".message"); return this.message_override || I18n.t(`login.${this.name}.message`);
}, },
doLogin({ reconnect = false, fullScreenLogin = true } = {}) { doLogin({ reconnect = false, fullScreenLogin = true } = {}) {
@ -23,7 +23,7 @@ const LoginMethod = Ember.Object.extend({
if (customLogin) { if (customLogin) {
customLogin(); customLogin();
} else { } else {
let authUrl = this.custom_url || Discourse.getURL("/auth/" + name); let authUrl = this.custom_url || Discourse.getURL(`/auth/${name}`);
if (reconnect) { if (reconnect) {
authUrl += "?reconnect=true"; authUrl += "?reconnect=true";
@ -45,7 +45,7 @@ const LoginMethod = Ember.Object.extend({
authUrl += "display=popup"; authUrl += "display=popup";
} }
const w = window.open( const windowState = window.open(
authUrl, authUrl,
"_blank", "_blank",
"menubar=no,status=no,height=" + "menubar=no,status=no,height=" +
@ -57,11 +57,11 @@ const LoginMethod = Ember.Object.extend({
",top=" + ",top=" +
top top
); );
const self = this;
const timer = setInterval(function() { const timer = setInterval(() => {
if (!w || w.closed) { if (!windowState || windowState.closed) {
clearInterval(timer); clearInterval(timer);
self.set("authenticate", null); this.set("authenticate", null);
} }
}, 1000); }, 1000);
} }
@ -72,18 +72,16 @@ const LoginMethod = Ember.Object.extend({
let methods; let methods;
export function findAll() { export function findAll() {
if (methods) { if (methods) return methods;
return methods;
}
methods = []; methods = [];
Discourse.Site.currentProp("auth_providers").forEach(provider => { Discourse.Site.currentProp("auth_providers").forEach(provider =>
methods.pushObject(LoginMethod.create(provider)); methods.pushObject(LoginMethod.create(provider))
}); );
// exclude FA icon for Google, uses custom SVG // exclude FA icon for Google, uses custom SVG
methods.forEach(m => m.set("isGoogle", m.get("name") === "google_oauth2")); methods.forEach(m => m.set("isGoogle", m.name === "google_oauth2"));
return methods; return methods;
} }