FEATURE: use full screen login by default for social login methods (#7481)

This commit is contained in:
Arpit Jalan 2019-05-09 10:03:01 +05:30 committed by GitHub
parent 88650a1259
commit 427979e7e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 26 additions and 53 deletions

View File

@ -11,7 +11,6 @@ const Discourse = Ember.Application.extend({
_docTitle: document.title,
RAW_TEMPLATES: {},
__widget_helpers: {},
useFullScreenLogin: false,
customEvents: {
paste: "paste"
},

View File

@ -12,11 +12,7 @@ export default Ember.Component.extend({
@computed
buttons() {
return findAll(
this.siteSettings,
this.capabilities,
this.site.isMobileDevice
);
return findAll();
},
actions: {

View File

@ -186,7 +186,7 @@ export default Ember.Controller.extend(
// Determines whether at least one login button is enabled
@computed
hasAtLeastOneLoginButton() {
return findAll(this.siteSettings).length > 0;
return findAll().length > 0;
},
@on("init")

View File

@ -37,13 +37,7 @@ export default Ember.Controller.extend(
@computed
externalAuthsEnabled() {
return (
findLoginMethods(
this.siteSettings,
this.capabilities,
this.site.isMobileDevice
).length > 0
);
return findLoginMethods().length > 0;
},
@computed(

View File

@ -69,7 +69,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
// Determines whether at least one login button is enabled
@computed("canLoginLocalWithEmail")
hasAtLeastOneLoginButton(canLoginLocalWithEmail) {
return findAll(this.siteSettings).length > 0 || canLoginLocalWithEmail;
return findAll().length > 0 || canLoginLocalWithEmail;
},
@computed("loggingIn")
@ -212,8 +212,17 @@ export default Ember.Controller.extend(ModalFunctionality, {
return false;
},
externalLogin(loginMethod) {
loginMethod.doLogin();
externalLogin(loginMethod, { fullScreenLogin = false } = {}) {
const capabilities = this.capabilities;
// On Mobile, Android or iOS always go with full screen
if (
this.isMobileDevice ||
(capabilities && (capabilities.isIOS || capabilities.isAndroid))
) {
fullScreenLogin = true;
}
loginMethod.doLogin({ fullScreenLogin });
},
createAccount() {
@ -287,11 +296,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
@computed("authenticate")
authMessage(authenticate) {
if (Ember.isEmpty(authenticate)) return "";
const method = findAll(
this.siteSettings,
this.capabilities,
this.isMobileDevice
).findBy("name", authenticate);
const method = findAll().findBy("name", authenticate);
if (method) {
return method.get("message");
}

View File

@ -73,11 +73,7 @@ export default Ember.Controller.extend(
@computed("model.associated_accounts.[]")
authProviders(accounts) {
const allMethods = findAll(
this.siteSettings,
this.capabilities,
this.site.isMobileDevice
);
const allMethods = findAll();
const result = allMethods.map(method => {
return {
@ -109,11 +105,7 @@ export default Ember.Controller.extend(
if (secondFactorEnabled || !canCheckEmails || isAnonymous) {
return false;
}
return (
findAll(this.siteSettings, this.capabilities, this.site.isMobileDevice)
.length > 0
);
return findAll().length > 0;
},
@computed("showAllAuthTokens", "model.user_auth_tokens")
@ -256,7 +248,7 @@ export default Ember.Controller.extend(
},
connectAccount(method) {
method.doLogin(true);
method.doLogin({ reconnect: true, fullScreenLogin: false });
}
}
}

View File

@ -24,7 +24,7 @@ const LoginMethod = Ember.Object.extend({
);
},
doLogin(reconnect = false) {
doLogin({ reconnect = false, fullScreenLogin = true } = {}) {
const name = this.get("name");
const customLogin = this.get("customLogin");
@ -37,7 +37,7 @@ const LoginMethod = Ember.Object.extend({
authUrl += "?reconnect=true";
}
if (this.get("full_screen_login")) {
if (fullScreenLogin) {
document.cookie = "fsl=true";
window.location = authUrl;
} else {
@ -79,7 +79,7 @@ const LoginMethod = Ember.Object.extend({
let methods;
export function findAll(siteSettings, capabilities, isMobileDevice) {
export function findAll() {
if (methods) {
return methods;
}
@ -90,15 +90,6 @@ export function findAll(siteSettings, capabilities, isMobileDevice) {
methods.pushObject(LoginMethod.create(provider));
});
// On Mobile, Android or iOS always go with full screen
if (
isMobileDevice ||
(capabilities && (capabilities.isIOS || capabilities.isAndroid)) ||
Discourse.useFullScreenLogin
) {
methods.forEach(m => m.set("full_screen_login", true));
}
// exclude FA icon for Google, uses custom SVG
methods.forEach(m => m.set("isGoogle", m.get("name") === "google_oauth2"));

View File

@ -252,14 +252,12 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
},
_autoLogin(modal, modalClass, notAuto) {
const methods = findAll(
this.siteSettings,
getOwner(this).lookup("capabilities:main"),
this.site.isMobileDevice
);
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], {
fullScreenLogin: true
});
} else {
showModal(modal);
this.controllerFor("modal").set("modalClass", modalClass);

View File

@ -55,7 +55,6 @@ export default Discourse.Route.extend({
});
} else {
$.cookie("destination_url", window.location.href);
Discourse.useFullScreenLogin = true;
this.replaceWith("login");
}
}

View File

@ -72,7 +72,6 @@ export default Discourse.Route.extend({
} else {
// User is not logged in
$.cookie("destination_url", window.location.href);
Discourse.useFullScreenLogin = true;
self.replaceWith("login");
}
},