Skip to content

Commit

Permalink
feat(cxmt): ⚡ 基于 v4 同步 ui-components 私有改动
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoyafng committed Nov 19, 2024
1 parent f4f0cb5 commit 00ad577
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/guard-core-v4/src/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ export const GuardLoginView: React.FC<{ isResetPage?: boolean }> = ({
tab={computedTabName(
adI18n?.tab?.i18n?.[i18n.resolvedLanguage!] ||
adI18n?.tab?.default ||
t('login.adLogin')
t('login.accountLogin')
)}
>
<LoginWithAD
Expand Down
10 changes: 9 additions & 1 deletion packages/guard-core-v4/src/MFA/businessRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export enum MfaBusinessAction {
VerifyFace = 'verify-face',
AssociateFace = 'associate-face',
PasskeyBind = 'passkey-bind',
PasskeyVerify = 'passkey-verify'
PasskeyVerify = 'passkey-verify',
VerifyCloudEntify = 'verify-cloudentify'
}

export const authFlow = async (action: MfaBusinessAction, content: any) => {
Expand Down Expand Up @@ -257,6 +258,13 @@ export const useMfaBusinessRequest = () => {

// return AssociateFace(content)
return null
},
[MfaBusinessAction.VerifyCloudEntify]: (content: VerifyTotpContent) => {
if (isFlow) {
return authFlow(MfaBusinessAction.VerifyCloudEntify, content)
}
// TODO cxmt
return VerifyTotp(content)
}
}

Expand Down
103 changes: 103 additions & 0 deletions packages/guard-core-v4/src/MFA/core/cloudEntify.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { useTranslation } from 'react-i18next'
import { useAsyncFn } from 'react-use'
import { GuardMFAInitData, MFAConfig } from '../interface'
import SubmitButton from '../../SubmitButton'
import { VerifyCodeFormItem } from '../VerifyCodeInput/VerifyCodeFormItem'
import { VerifyCodeInput } from '../VerifyCodeInput'
import { MfaBusinessAction, useMfaBusinessRequest } from '../businessRequest'
import { Form } from 'shim-antd'
import { React } from 'shim-react'
const { useRef } = React

export interface VerifyMFATotpProps {
mfaToken: string
mfaLogin: any
changeModule: any
}

export const VerifyMFATotp: React.FC<VerifyMFATotpProps> = ({
mfaToken,
mfaLogin,
changeModule
}) => {
const { t } = useTranslation()

const [form] = Form.useForm()

const submitButtonRef = useRef<any>(null)

const businessRequest =
useMfaBusinessRequest()[MfaBusinessAction.VerifyCloudEntify]

const [, onFinish] = useAsyncFn(async () => {
submitButtonRef.current?.onSpin(true)

const mfaCode = form.getFieldValue('mfaCode')

const requestData = {
totp: mfaCode.join(''),
mfaToken
}

const { isFlowEnd, data, onGuardHandling } = await businessRequest(
requestData
)

submitButtonRef.current?.onSpin(false)

if (isFlowEnd) {
mfaLogin(200, data)
} else {
submitButtonRef.current.onError()

onGuardHandling?.()
}
}, [mfaToken])

return (
<>
<p className="authing-g2-mfa-title">{t('login.accPwdLoginVerify')}</p>
<p className="authing-g2-mfa-tips">{t('common.cloundEntifyCodes')}</p>
<Form
form={form}
onSubmitCapture={() => {}}
onFinish={onFinish}
onFinishFailed={() => submitButtonRef.current.onError()}
>
<VerifyCodeFormItem codeLength={6}>
<VerifyCodeInput
length={6}
showDivider={false}
gutter={'10px'}
onFinish={onFinish}
/>
</VerifyCodeFormItem>

<SubmitButton text={t('common.sure')} ref={submitButtonRef} />
</Form>
</>
)
}

export interface MFATotpProps {
changeModule: any
config: MFAConfig
initData: GuardMFAInitData
mfaLogin: any
}

export const MFACloudEntify: React.FC<MFATotpProps> = ({
changeModule,
initData,
mfaLogin
}) => {
return (
<>
<VerifyMFATotp
mfaToken={initData.mfaToken}
mfaLogin={mfaLogin}
changeModule={changeModule}
/>
</>
)
}
10 changes: 10 additions & 0 deletions packages/guard-core-v4/src/MFA/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { MFAFace } from './core/face'

import { MFATotp } from './core/totp'

import { MFACloudEntify } from './core/cloudEntify'

import { MFAMethods } from './mfaMethods'

import { GuardMFAInitData, MFAType } from './interface'
Expand Down Expand Up @@ -89,6 +91,14 @@ const ComponentsMapping: Record<MFAType, (props: any) => React.ReactNode> = {
passkeyEnabled={initData.passkeyEnabled}
mfaConfigsMap={mfaConfigsMap}
/>
),
[MFAType.CLOUDENTIFY]: ({ initData, config, changeModule, mfaLogin }) => (
<MFACloudEntify
changeModule={changeModule}
config={config}
initData={initData}
mfaLogin={mfaLogin}
/>
)
}

Expand Down
6 changes: 5 additions & 1 deletion packages/guard-core-v4/src/MFA/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export enum MFAType {
EMAIL = 'EMAIL',
TOTP = 'OTP',
FACE = 'FACE',
PASSKEY = 'PASSKEY'
PASSKEY = 'PASSKEY',
/**
* cxmt 飞天云信
*/
CLOUDENTIFY = 'CLOUDENTIFY'
}

export interface GuardMFAInitData {
Expand Down
6 changes: 5 additions & 1 deletion packages/guard-core-v4/src/MFA/mfaMethods/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const methodTitleMapping: Record<
},
[MFAType.TOTP]: {
title: () => i18n.t('common.OTPVerification'),
icon: 'authing-totp'
icon: 'authing-otp-fill'
},
[MFAType.FACE]: {
title: () => i18n.t('common.faceVerification'),
Expand All @@ -49,6 +49,10 @@ const methodTitleMapping: Record<
[MFAType.PASSKEY]: {
title: () => 'Passkey',
icon: 'authing-slideshow-3-line'
},
[MFAType.CLOUDENTIFY]: {
title: () => i18n.t('common.cloudEntifyVerify'),
icon: 'authing-totp'
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/guard-core-v4/src/SubmitButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { GuardButton } from '../GuardButton'
import { useGuardButtonState } from '../_utils/context'

import { ButtonProps } from 'shim-antd'
import { DefaultTFuncReturn } from 'i18next'

const { forwardRef, useState, useImperativeHandle, useEffect } = React

interface SubmitButtonProps extends ButtonProps {
text?: string
text?: string | DefaultTFuncReturn
className?: string
onClick?: any
disabled?: boolean
Expand Down
1 change: 1 addition & 0 deletions packages/guard-core-v4/src/Type/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ export interface ApplicationConfig {
validLoginMethods: Array<string> | null
validRegisterMethods: Array<string> | null
}

/** 是否开启自定义安全规则 */
customSecurityEnabled: boolean
/** 应用的人机验证策略,始终开启、不开启、设置条件触发 */
Expand Down
6 changes: 4 additions & 2 deletions packages/guard-core-v4/src/_utils/locales/en-us/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"feedback": "Need help ?",
"loginProtocolTips": "Please check the login protocol",
"registerProtocolTips": "Please check the registration agreement",
"accountLock": "The account is locked, please click the question mark below to give feedback",
"accountLock": "The account is locked. Please unlock it by yourself or contact the administrator.",
"corsErrorMessage": "The current domain name is not in the list of allowed domain names",
"corsErrorMessage2": "If you have any questions, you can <a href=\"https://docs.authing.cn/v2/guides/security/config-domain.html\">refer to the document</a>",
"totpGenerateCode": "Generate a new recovery code for you, please record this key safely",
Expand Down Expand Up @@ -229,5 +229,7 @@
"reVerify": "reverify",
"inviteExpired": "The current invitation link has expired. Please contact the relevant administrator to resend the invitation for you.",
"pageExpired": "The current page has expired. Please click the invitation link again to enter",
"inviteSuccess": "Successfully joined, please check your email. Please complete the login based on the information in the email."
"inviteSuccess": "Successfully joined, please check your email. Please complete the login based on the information in the email.",
"cloudEntifyVerify": "CloudEntify OTP Verification",
"cloundEntifyCodes": "Please enter the 6-digit security code you received"
}
3 changes: 2 additions & 1 deletion packages/guard-core-v4/src/_utils/locales/en-us/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@
"successTip": "Password reset succeeded",
"backLogin": "Seconds will automatically jump to the login page"
},
"wecomScanLogin": "Enterprise WeChat scan code to log in"
"wecomScanLogin": "Enterprise WeChat scan code to log in",
"accountLogin": "Account Login"
}
6 changes: 4 additions & 2 deletions packages/guard-core-v4/src/_utils/locales/ja-jp/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"feedback": "ヘルプ・お問い合わせ",
"loginProtocolTips": "ログインプロトコルにチェックを入れてください",
"registerProtocolTips": "登録プロトコルにチェックを入れてください",
"accountLock": "アカウントがロックされたら、下の疑問符をクリックしてフィードバックしてください",
"accountLock": "アカウントがロックされているので、セルフでロックを解除するか、管理者に連絡してロックを解除してください。",
"corsErrorMessage": "現在のドメイン名はアクセスが許可されているドメイン名のリストには含まれていない。",
"corsErrorMessage2": "質問があれば<a href=\"https://docs.authing.cn/v2/guides/security/config-domain.html\">ドキュメント参照</a>",
"totpGenerateCode": "この鍵を安全に記録してください",
Expand Down Expand Up @@ -229,5 +229,7 @@
"reVerify": "再検証",
"inviteExpired": "現在の招待リンクは無効です。関連管理者に連絡して招待を再開してください。",
"pageExpired": "現在のページは期限切れですので、招待リンクをもう一度クリックしてください",
"inviteSuccess": "正常に参加しました。メールを確認してください。メール内の情報に基づいてログインを完了してください。"
"inviteSuccess": "正常に参加しました。メールを確認してください。メール内の情報に基づいてログインを完了してください。",
"cloudEntifyVerify": "CloudEntify OTP パスワードの検証",
"cloundEntifyCodes": "受け取った6桁のセキュリティコードを入力してください"
}
3 changes: 2 additions & 1 deletion packages/guard-core-v4/src/_utils/locales/ja-jp/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@
"successTip": "パスワードのリセットに成功しました",
"backLogin": "秒ログインページが自動的にジャンプされます"
},
"wecomScanLogin": "エンタープライズ WeChat ログイン"
"wecomScanLogin": "エンタープライズ WeChat ログイン",
"accountLogin": "アカウントログイン"
}
6 changes: 4 additions & 2 deletions packages/guard-core-v4/src/_utils/locales/zh-cn/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"feedback": "问题反馈",
"loginProtocolTips": "请勾选登录协议",
"registerProtocolTips": "请勾选注册协议",
"accountLock": "账号被锁定,请点击下方问号进行反馈",
"accountLock": "账号被锁定,请自助解锁或联系管理员进行解锁。",
"corsErrorMessage": "当前域名不在允许访问的域名列表中。",
"corsErrorMessage2": "如果有疑问可以<a href=\"https://docs.authing.cn/v2/guides/security/config-domain.html\">参考文档</a>",
"totpGenerateCode": "为你生成一串新的恢复代码,请安全地记录这段密钥",
Expand Down Expand Up @@ -229,5 +229,7 @@
"reVerify": "重新验证",
"inviteExpired": "当前邀请链接已失效,请联系相关管理员为你重新发起邀请。",
"pageExpired": "当前页面已过期,请重新点击邀请链接进入",
"inviteSuccess": "已成功加入,敬请查收邮件。请根据邮件内的信息完成登录。"
"inviteSuccess": "已成功加入,敬请查收邮件。请根据邮件内的信息完成登录。",
"cloudEntifyVerify": "飞天云信 OTP 口令验证",
"cloundEntifyCodes": "请输入获取的 6 位数字安全码"
}
3 changes: 2 additions & 1 deletion packages/guard-core-v4/src/_utils/locales/zh-cn/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@
"successTip": "密码重置成功",
"backLogin": "秒后将自动跳转登录页"
},
"wecomScanLogin": "企业微信扫码登录"
"wecomScanLogin": "企业微信扫码登录",
"accountLogin": "账号登录"
}
6 changes: 4 additions & 2 deletions packages/guard-core-v4/src/_utils/locales/zh-tw/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"registerTab": "{{text}}註冊",
"SMS": "短信驗證碼驗證",
"account": "賬號",
"accountLock": "賬號被鎖定,請點擊下方問號進行反饋",
"accountLock": "帳號被鎖定,請自助解鎖或聯系管理員進行解鎖。",
"alreadyHasAcc": "已有賬號,",
"areaCodePhone": "區號 手機號碼",
"back": "返回",
Expand Down Expand Up @@ -227,5 +227,7 @@
"reVerify": "重新驗證",
"inviteExpired": "當前邀請連結已失效,請聯系相關管理員為你重新發起邀請。",
"pageExpired": "當前頁面已過期,請重新點擊邀請連結進入",
"inviteSuccess": "已成功加入,敬請查收郵件。 請根據郵件內的資訊完成登入。"
"inviteSuccess": "已成功加入,敬請查收郵件。 請根據郵件內的資訊完成登入。",
"cloudEntifyVerify": "飛天雲信 OTP 口令驗證",
"cloundEntifyCodes": "請輸入取得的 6 位數字安全碼"
}
3 changes: 2 additions & 1 deletion packages/guard-core-v4/src/_utils/locales/zh-tw/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@
"successTip": "密碼重置成功",
"backLogin": "秒後將自動跳轉登入頁"
},
"wecomScanLogin": "企業微信掃碼登入"
"wecomScanLogin": "企業微信掃碼登入",
"accountLogin": "賬號登錄"
}

0 comments on commit 00ad577

Please sign in to comment.