mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 13:20:19 +08:00
feat: add user's MFA items (#3921)
This commit is contained in:
@ -536,7 +536,13 @@ func IsNeedPromptMfa(org *Organization, user *User) bool {
|
||||
if org == nil || user == nil {
|
||||
return false
|
||||
}
|
||||
for _, item := range org.MfaItems {
|
||||
|
||||
mfaItems := org.MfaItems
|
||||
|
||||
if len(user.MfaItems) > 0 {
|
||||
mfaItems = user.MfaItems
|
||||
}
|
||||
for _, item := range mfaItems {
|
||||
if item.Rule == "Required" {
|
||||
if item.Name == EmailType && !user.MfaEmailEnabled {
|
||||
return true
|
||||
|
@ -212,6 +212,7 @@ type User struct {
|
||||
|
||||
ManagedAccounts []ManagedAccount `xorm:"managedAccounts blob" json:"managedAccounts"`
|
||||
MfaAccounts []MfaAccount `xorm:"mfaAccounts blob" json:"mfaAccounts"`
|
||||
MfaItems []*MfaItem `xorm:"varchar(300)" json:"mfaItems"`
|
||||
NeedUpdatePassword bool `json:"needUpdatePassword"`
|
||||
IpWhitelist string `xorm:"varchar(200)" json:"ipWhitelist"`
|
||||
}
|
||||
@ -795,7 +796,7 @@ func UpdateUser(id string, user *User, columns []string, isAdmin bool) (bool, er
|
||||
}
|
||||
}
|
||||
if isAdmin {
|
||||
columns = append(columns, "name", "id", "email", "phone", "country_code", "type", "balance")
|
||||
columns = append(columns, "name", "id", "email", "phone", "country_code", "type", "balance", "mfa_items")
|
||||
}
|
||||
|
||||
columns = append(columns, "updated_time")
|
||||
|
@ -696,18 +696,27 @@ export const MfaRulePrompted = "Prompted";
|
||||
export const MfaRuleOptional = "Optional";
|
||||
|
||||
export function isRequiredEnableMfa(user, organization) {
|
||||
if (!user || !organization || !organization.mfaItems) {
|
||||
if (!user || !organization || (!organization.mfaItems && !user.mfaItems)) {
|
||||
return false;
|
||||
}
|
||||
return getMfaItemsByRules(user, organization, [MfaRuleRequired]).length > 0;
|
||||
}
|
||||
|
||||
export function getMfaItemsByRules(user, organization, mfaRules = []) {
|
||||
if (!user || !organization || !organization.mfaItems) {
|
||||
if (!user || !organization || (!organization.mfaItems && !user.mfaItems)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return organization.mfaItems.filter((mfaItem) => mfaRules.includes(mfaItem.rule))
|
||||
let mfaItems = organization.mfaItems;
|
||||
if (user.mfaItems && user.mfaItems.length !== 0) {
|
||||
mfaItems = user.mfaItems;
|
||||
}
|
||||
|
||||
if (mfaItems === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return mfaItems.filter((mfaItem) => mfaRules.includes(mfaItem.rule))
|
||||
.filter((mfaItem) => user.multiFactorAuths.some((mfa) => mfa.mfaType === mfaItem.name && !mfa.enabled));
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ import * as MfaBackend from "./backend/MfaBackend";
|
||||
import AccountAvatar from "./account/AccountAvatar";
|
||||
import FaceIdTable from "./table/FaceIdTable";
|
||||
import MfaAccountTable from "./table/MfaAccountTable";
|
||||
import MfaTable from "./table/MfaTable";
|
||||
|
||||
const {Option} = Select;
|
||||
|
||||
@ -926,6 +927,19 @@ class UserEditPage extends React.Component {
|
||||
</Col>
|
||||
</Row>
|
||||
);
|
||||
} else if (accountItem.name === "MFA items") {
|
||||
return (<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
{Setting.getLabel(i18next.t("general:MFA items"), i18next.t("general:MFA items - Tooltip"))} :
|
||||
</Col>
|
||||
<Col span={22} >
|
||||
<MfaTable
|
||||
title={i18next.t("general:MFA items")}
|
||||
table={this.state.user.mfaItems ?? []}
|
||||
onUpdateTable={(value) => {this.updateUserField("mfaItems", value);}}
|
||||
/>
|
||||
</Col>
|
||||
</Row>);
|
||||
} else if (accountItem.name === "Multi-factor authentication") {
|
||||
return (
|
||||
!this.isSelfOrAdmin() ? null : (
|
||||
|
@ -110,6 +110,7 @@ class AccountTable extends React.Component {
|
||||
{name: "Managed accounts", label: i18next.t("user:Managed accounts")},
|
||||
{name: "Face ID", label: i18next.t("user:Face ID")},
|
||||
{name: "MFA accounts", label: i18next.t("user:MFA accounts")},
|
||||
{name: "MFA items", label: i18next.t("general:MFA items")},
|
||||
];
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user