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, _docTitle: document.title,
RAW_TEMPLATES: {}, RAW_TEMPLATES: {},
__widget_helpers: {}, __widget_helpers: {},
useFullScreenLogin: false,
customEvents: { customEvents: {
paste: "paste" paste: "paste"
}, },

View File

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

View File

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

View File

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

View File

@ -69,7 +69,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
// Determines whether at least one login button is enabled // Determines whether at least one login button is enabled
@computed("canLoginLocalWithEmail") @computed("canLoginLocalWithEmail")
hasAtLeastOneLoginButton(canLoginLocalWithEmail) { hasAtLeastOneLoginButton(canLoginLocalWithEmail) {
return findAll(this.siteSettings).length > 0 || canLoginLocalWithEmail; return findAll().length > 0 || canLoginLocalWithEmail;
}, },
@computed("loggingIn") @computed("loggingIn")
@ -212,8 +212,17 @@ export default Ember.Controller.extend(ModalFunctionality, {
return false; return false;
}, },
externalLogin(loginMethod) { externalLogin(loginMethod, { fullScreenLogin = false } = {}) {
loginMethod.doLogin(); 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() { createAccount() {
@ -287,11 +296,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
@computed("authenticate") @computed("authenticate")
authMessage(authenticate) { authMessage(authenticate) {
if (Ember.isEmpty(authenticate)) return ""; if (Ember.isEmpty(authenticate)) return "";
const method = findAll( const method = findAll().findBy("name", authenticate);
this.siteSettings,
this.capabilities,
this.isMobileDevice
).findBy("name", authenticate);
if (method) { if (method) {
return method.get("message"); return method.get("message");
} }

View File

@ -73,11 +73,7 @@ export default Ember.Controller.extend(
@computed("model.associated_accounts.[]") @computed("model.associated_accounts.[]")
authProviders(accounts) { authProviders(accounts) {
const allMethods = findAll( const allMethods = findAll();
this.siteSettings,
this.capabilities,
this.site.isMobileDevice
);
const result = allMethods.map(method => { const result = allMethods.map(method => {
return { return {
@ -109,11 +105,7 @@ export default Ember.Controller.extend(
if (secondFactorEnabled || !canCheckEmails || isAnonymous) { if (secondFactorEnabled || !canCheckEmails || isAnonymous) {
return false; return false;
} }
return findAll().length > 0;
return (
findAll(this.siteSettings, this.capabilities, this.site.isMobileDevice)
.length > 0
);
}, },
@computed("showAllAuthTokens", "model.user_auth_tokens") @computed("showAllAuthTokens", "model.user_auth_tokens")
@ -256,7 +248,7 @@ export default Ember.Controller.extend(
}, },
connectAccount(method) { 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 name = this.get("name");
const customLogin = this.get("customLogin"); const customLogin = this.get("customLogin");
@ -37,7 +37,7 @@ const LoginMethod = Ember.Object.extend({
authUrl += "?reconnect=true"; authUrl += "?reconnect=true";
} }
if (this.get("full_screen_login")) { if (fullScreenLogin) {
document.cookie = "fsl=true"; document.cookie = "fsl=true";
window.location = authUrl; window.location = authUrl;
} else { } else {
@ -79,7 +79,7 @@ const LoginMethod = Ember.Object.extend({
let methods; let methods;
export function findAll(siteSettings, capabilities, isMobileDevice) { export function findAll() {
if (methods) { if (methods) {
return methods; return methods;
} }
@ -90,15 +90,6 @@ export function findAll(siteSettings, capabilities, isMobileDevice) {
methods.pushObject(LoginMethod.create(provider)); 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 // 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.get("name") === "google_oauth2"));

View File

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

View File

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

View File

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