UX: Display warning message about social logins disabled when 2FA is enabled.

This commit is contained in:
Guo Xiang Tan 2018-03-02 14:22:08 +08:00
parent 50eb582fb2
commit d9b4b12694
5 changed files with 50 additions and 8 deletions

View File

@ -1,6 +1,7 @@
import { default as computed } from 'ember-addons/ember-computed-decorators';
import { default as DiscourseURL, userPath } from 'discourse/lib/url';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { LOGIN_METHODS } from 'discourse/models/login-method';
export default Ember.Controller.extend({
loading: false,
@ -20,6 +21,13 @@ export default Ember.Controller.extend({
return loading ? 'loading' : 'submit';
},
@computed
displayOAuthWarning() {
return LOGIN_METHODS.some(name => {
return this.siteSettings[`enable_${name}_logins`];
});
},
toggleSecondFactor(enable) {
if (!this.get('secondFactorToken')) return;
this.set('loading', true);

View File

@ -22,19 +22,21 @@ const LoginMethod = Ember.Object.extend({
let methods;
let preRegister;
export const LOGIN_METHODS = [
"google_oauth2",
"facebook",
"twitter",
"yahoo",
"instagram",
"github"
];
export function findAll(siteSettings, capabilities, isMobileDevice) {
if (methods) { return methods; }
methods = [];
[
"google_oauth2",
"facebook",
"twitter",
"yahoo",
"instagram",
"github"
].forEach(name => {
LOGIN_METHODS.forEach(name => {
if (siteSettings["enable_" + name + "_logins"]) {
const params = { name };
if (name === "google_oauth2") {

View File

@ -40,6 +40,10 @@
<div class="control-group">
<div class="controls">
{{{i18n 'user.second_factor.enable_description'}}}
{{#if displayOAuthWarning}}
{{i18n 'user.second_factor.oauth_enabled_warning'}}
{{/if}}
</div>
</div>

View File

@ -728,6 +728,7 @@ en:
requiring a one-time token in addition to your password. These tokens
can be generated on Android and iOS by <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2" target='_blank'>Google Authenticator</a>
and on Windows Phone by <a href="https://www.microsoft.com/en-us/store/p/authenticator/9wzdncrfj3rj" target='_blank'>Authenticator</a>.
oauth_enabled_warning: "Note that logins via social methods will be disabled once Two Factor Authentication has been enabled on your account."
change_about:
title: "Change About Me"

View File

@ -0,0 +1,27 @@
moduleFor("controller:preferences/second-factor");
QUnit.test("displayOAuthWarning when OAuth login methods are disabled", assert => {
let controller = this.subject({
siteSettings: {
enable_google_oauth2_logins: false
}
});
assert.equal(
controller.get('displayOAuthWarning'),
false
);
});
QUnit.test("displayOAuthWarning when OAuth login methods are enabled", assert => {
let controller = this.subject({
siteSettings: {
enable_google_oauth2_logins: true
}
});
assert.equal(
controller.get('displayOAuthWarning'),
true
);
});