YANG QIA 84cfa82304
feat: security (#5923)
* feat: password policy

* feat: password validator

* fix(inbox): i18n of channel title

* feat: atomic counter

* fix: bug

* fix: bloom

* chore: i18n

* fix: counter

* fix: build

* fix: bug

* fix: z-index

* fix: export

* test: add redis cache test

* fix: test

* fix: test

* fix: test

* fix: bug

* fix: form reset

* fix: locale

* fix: version

* fix: separate cache for sub apps

* chore: update
2024-12-29 08:33:27 +08:00

65 lines
1.6 KiB
TypeScript

/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import React, { useEffect } from 'react';
import { Input, Row, Col, Button } from 'antd';
import { Password, useActionContext } from '@nocobase/client';
import { useField } from '@formily/react';
import { Field } from '@formily/core';
import { useUsersTranslation } from './locale';
import { generatePassword } from './utils';
export const PasswordField: React.FC = () => {
const { t } = useUsersTranslation();
const field = useField<Field>();
const [visible, setVisible] = React.useState(false);
const ctx = useActionContext();
useEffect(() => {
if (ctx.visible) {
return;
}
field.reset();
}, [field, ctx.visible]);
useEffect(() => {
if (!field.value) {
return;
}
field.validate();
}, [field.value]);
return (
<Row gutter={10}>
<Col span={18}>
<Password
checkStrength={true}
visibilityToggle={{
visible,
onVisibleChange: setVisible,
}}
value={field.value}
onChange={(e: any) => field.setValue(e.target.value)}
autoComplete="off"
/>
</Col>
<Col span={4}>
<Button
onClick={() => {
field.setValue(generatePassword());
setVisible(true);
}}
>
{t('Random password')}
</Button>
</Col>
</Row>
);
};