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
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 } = {}) {
@ -23,7 +23,7 @@ const LoginMethod = Ember.Object.extend({
if (customLogin) {
customLogin();
} else {
let authUrl = this.custom_url || Discourse.getURL("/auth/" + name);
let authUrl = this.custom_url || Discourse.getURL(`/auth/${name}`);
if (reconnect) {
authUrl += "?reconnect=true";
@ -45,7 +45,7 @@ const LoginMethod = Ember.Object.extend({
authUrl += "display=popup";
}
const w = window.open(
const windowState = window.open(
authUrl,
"_blank",
"menubar=no,status=no,height=" +
@ -57,11 +57,11 @@ const LoginMethod = Ember.Object.extend({
",top=" +
top
);
const self = this;
const timer = setInterval(function() {
if (!w || w.closed) {
const timer = setInterval(() => {
if (!windowState || windowState.closed) {
clearInterval(timer);
self.set("authenticate", null);
this.set("authenticate", null);
}
}, 1000);
}
@ -72,18 +72,16 @@ const LoginMethod = Ember.Object.extend({
let methods;
export function findAll() {
if (methods) {
return methods;
}
if (methods) return methods;
methods = [];
Discourse.Site.currentProp("auth_providers").forEach(provider => {
methods.pushObject(LoginMethod.create(provider));
});
Discourse.Site.currentProp("auth_providers").forEach(provider =>
methods.pushObject(LoginMethod.create(provider))
);
// 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;
}