mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
FIX: Improve UX for second factor enforcement. (#7207)
This commit is contained in:
@ -39,24 +39,9 @@ export default Ember.Controller.extend({
|
|||||||
return findAll().length > 0;
|
return findAll().length > 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed(
|
@computed("currentUser")
|
||||||
"siteSettings.enforce_second_factor",
|
showEnforcedNotice(user) {
|
||||||
"currentUser",
|
return user && user.get("enforcedSecondFactor");
|
||||||
"currentUser.second_factor_enabled",
|
|
||||||
"currentUser.staff"
|
|
||||||
)
|
|
||||||
showEnforcedNotice(
|
|
||||||
enforce_second_factor,
|
|
||||||
user,
|
|
||||||
second_factor_enabled,
|
|
||||||
staff
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
user &&
|
|
||||||
!second_factor_enabled &&
|
|
||||||
(enforce_second_factor === "all" ||
|
|
||||||
(enforce_second_factor === "staff" && staff))
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleSecondFactor(enable) {
|
toggleSecondFactor(enable) {
|
||||||
|
@ -746,6 +746,15 @@ const User = RestModel.extend({
|
|||||||
} else {
|
} else {
|
||||||
$.removeCookie("text_size", { path: "/", expires: 1 });
|
$.removeCookie("text_size", { path: "/", expires: 1 });
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
@computed("second_factor_enabled", "staff")
|
||||||
|
enforcedSecondFactor(secondFactorEnabled, staff) {
|
||||||
|
const enforce = Discourse.SiteSettings.enforce_second_factor;
|
||||||
|
return (
|
||||||
|
!secondFactorEnabled &&
|
||||||
|
(enforce === "all" || (enforce === "staff" && staff))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -38,7 +38,9 @@
|
|||||||
disabled=loading
|
disabled=loading
|
||||||
label=disableButtonText}}
|
label=disableButtonText}}
|
||||||
|
|
||||||
|
{{#unless showEnforcedNotice}}
|
||||||
{{cancel-link route="preferences.account" args= model.username}}
|
{{cancel-link route="preferences.account" args= model.username}}
|
||||||
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
@ -86,7 +88,9 @@
|
|||||||
disabled=loading
|
disabled=loading
|
||||||
label=enableButtonText}}
|
label=enableButtonText}}
|
||||||
|
|
||||||
|
{{#unless showEnforcedNotice}}
|
||||||
{{cancel-link route="preferences.account" args= model.username}}
|
{{cancel-link route="preferences.account" args= model.username}}
|
||||||
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
@ -122,7 +126,9 @@
|
|||||||
|
|
||||||
{{resetPasswordProgress}}
|
{{resetPasswordProgress}}
|
||||||
|
|
||||||
|
{{#unless showEnforcedNotice}}
|
||||||
{{cancel-link route="preferences.account" args= model.username}}
|
{{cancel-link route="preferences.account" args= model.username}}
|
||||||
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -67,7 +67,10 @@ createWidget("header-notifications", {
|
|||||||
|
|
||||||
const unreadPMs = user.get("unread_private_messages");
|
const unreadPMs = user.get("unread_private_messages");
|
||||||
if (!!unreadPMs) {
|
if (!!unreadPMs) {
|
||||||
if (!user.get("read_first_notification")) {
|
if (
|
||||||
|
!user.get("read_first_notification") &&
|
||||||
|
!user.get("enforcedSecondFactor")
|
||||||
|
) {
|
||||||
contents.push(h("span.ring"));
|
contents.push(h("span.ring"));
|
||||||
if (!attrs.active && attrs.ringBackdrop) {
|
if (!attrs.active && attrs.ringBackdrop) {
|
||||||
contents.push(h("span.ring-backdrop-spotlight"));
|
contents.push(h("span.ring-backdrop-spotlight"));
|
||||||
|
@ -43,7 +43,8 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
:external_id,
|
:external_id,
|
||||||
:top_category_ids,
|
:top_category_ids,
|
||||||
:hide_profile_and_presence,
|
:hide_profile_and_presence,
|
||||||
:groups
|
:groups,
|
||||||
|
:second_factor_enabled
|
||||||
|
|
||||||
def groups
|
def groups
|
||||||
object.visible_groups.pluck(:id, :name).map { |id, name| { id: id, name: name.downcase } }
|
object.visible_groups.pluck(:id, :name).map { |id, name| { id: id, name: name.downcase } }
|
||||||
@ -219,4 +220,8 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
def include_external_id?
|
def include_external_id?
|
||||||
SiteSetting.enable_sso
|
SiteSetting.enable_sso
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def second_factor_enabled
|
||||||
|
object.totp_enabled?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user