Skip to content

Commit

Permalink
fix: languages config, update-password
Browse files Browse the repository at this point in the history
  • Loading branch information
hibig committed Jun 25, 2024
1 parent bd6b3dc commit 9edce71
Show file tree
Hide file tree
Showing 21 changed files with 435 additions and 128 deletions.
6 changes: 4 additions & 2 deletions src/components/form-buttons/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useIntl } from '@umijs/max';
import { Button, Space } from 'antd';

type FormButtonsProps = {
Expand All @@ -18,6 +19,7 @@ const FormButtons: React.FC<FormButtonsProps> = ({
showOk = true,
htmlType = 'button'
}) => {
const intl = useIntl();
return (
<Space size={40} style={{ marginTop: '80px' }}>
{showOk && (
Expand All @@ -27,12 +29,12 @@ const FormButtons: React.FC<FormButtonsProps> = ({
style={{ width: '120px' }}
htmlType={htmlType}
>
{okText || '保存'}
{okText || intl.formatMessage({ id: 'common.button.save' })}
</Button>
)}
{showCancel && (
<Button onClick={onCancel} style={{ width: '98px' }}>
{cancelText || '取消'}
{cancelText || intl.formatMessage({ id: 'common.button.cancel' })}
</Button>
)}
</Space>
Expand Down
68 changes: 68 additions & 0 deletions src/components/password-validate/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
digitReg,
lowercaseReg,
specialCharacterReg,
uppercaseReg
} from '@/config';
import { CheckCircleFilled, CloseCircleFilled } from '@ant-design/icons';
import { useIntl } from '@umijs/max';
import { Space } from 'antd';

const PasswordValidate: React.FC<{ value: string }> = ({ value = '' }) => {
const intl = useIntl();

const renderIcon = ({ valid, text }: { valid: boolean; text: string }) => {
return (
<>
{valid ? (
<CheckCircleFilled style={{ color: 'green' }} />
) : (
<CloseCircleFilled style={{ color: 'red' }} />
)}
<span
className="m-l-5"
style={{ color: 'var(--ant-color-text-description)' }}
>
{text}
</span>
</>
);
};
return (
<Space direction="vertical" style={{ paddingTop: '10px' }}>
<span>
{renderIcon({
valid: uppercaseReg.test(value),
text: intl.formatMessage({ id: 'users.password.uppcase' })
})}
</span>
<span>
{renderIcon({
valid: lowercaseReg.test(value),
text: intl.formatMessage({ id: 'users.password.lowercase' })
})}
</span>

<span>
{renderIcon({
valid: digitReg.test(value),
text: intl.formatMessage({ id: 'users.password.number' })
})}
</span>
<span>
{renderIcon({
valid: value.length >= 6 && value.length <= 12,
text: intl.formatMessage({ id: 'users.password.length' })
})}
</span>
<span>
{renderIcon({
valid: specialCharacterReg.test(value),
text: intl.formatMessage({ id: 'users.password.special' })
})}
</span>
</Space>
);
};

export default PasswordValidate;
15 changes: 15 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ export const WatchEventType = {
UPDATE: 'MODIFIED',
DELETE: 'DELETED'
};

export const PasswordReg =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_])(?=\S+$).{6,12}$/;

export const uppercaseReg = /(?=.*[A-Z])/;

export const lowercaseReg = /(?=.*[a-z])/;

export const digitReg = /(?=.*\d)/;

export const specialCharacterReg = /(?=.*[\W_])/;

export const noSpaceReg = /(?=\S+$)/;

export const lengthReg = /^.{6,12}$/;
4 changes: 3 additions & 1 deletion src/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import menu from './en-US/menu';
import models from './en-US/models';
import playground from './en-US/playground';
import resources from './en-US/resources';
import users from './en-US/users';

export default {
...common,
...menu,
...models,
...playground,
...resources,
...apikeys
...apikeys,
...users
};
5 changes: 4 additions & 1 deletion src/locales/en-US/apikeys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export default {
'apikeys.title': 'API Keys',
'apikeys.table.apikeys': 'keys',
'apikeys.button.create': 'New API Key',
'apikeys.form.expiretime': 'Expiration',
'apikeys.table.name': 'Key Name'
'apikeys.table.name': 'Key Name',
'apikeys.table.save.tips':
'Make sure to copy your key immediately. You will not be able to see it again.'
};
5 changes: 4 additions & 1 deletion src/locales/en-US/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,8 @@ export default {
'common.settings.language': 'Language',
'common.delete.confirm':
'Are you sure you want to delete the selected {type}?',
'common.filter.name': 'Filter by name'
'common.filter.name': 'Filter by name',
'common.form.password': 'Password',
'common.form.username': 'Username',
'common.login.rember': 'Remember me'
};
22 changes: 22 additions & 0 deletions src/locales/en-US/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
'users.title': 'Users',
'users.button.create': 'Create User',
'users.form.edit': 'Edit User',
'users.form.create': 'Create User',
'users.table.username': 'User Name',
'users.table.role': 'Role',
'users.form.fullname': 'Full Name',
'users.table.user': 'users',
'users.form.admin': 'Admin',
'users.form.user': 'User',
'users.form.newpassword': 'New Password',
'users.form.currentpassword': 'Current Password',
'users.form.updatepassword': 'Modify Password',
'users.form.rule.password':
'Contains uppercase and lowercase letters, numbers, and special characters, 6 to 12 characters in length, no spaces allowed.',
'users.password.uppcase': 'At least one uppercase letter',
'users.password.lowercase': 'At least one lowercase letter',
'users.password.number': 'At least one number',
'users.password.special': 'At least one special character',
'users.password.length': 'Length between 6 and 12 characters'
};
6 changes: 4 additions & 2 deletions src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import menu from './en-US/menu';
import apikeys from './zh-CN/apikeys';
import common from './zh-CN/common';
import menu from './zh-CN/menu';
import models from './zh-CN/models';
import playground from './zh-CN/playground';
import resources from './zh-CN/resources';
import users from './zh-CN/users';

export default {
...common,
...menu,
...models,
...playground,
...resources,
...apikeys
...apikeys,
...users
};
4 changes: 3 additions & 1 deletion src/locales/zh-CN/apikeys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export default {
'apikeys.title': 'API 密钥',
'apikeys.table.apikeys': '密钥',
'apikeys.button.create': '新建 API 密钥',
'apikeys.form.expiretime': '过期时间',
'apikeys.table.name': '密钥名称'
'apikeys.table.name': '密钥名称',
'apikeys.table.save.tips': '确保立即复制您的密钥。您将无法再次看到它!'
};
5 changes: 4 additions & 1 deletion src/locales/zh-CN/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,8 @@ export default {
'common.settings.instructions': '操作指引',
'common.settings.language': '语言',
'common.delete.confirm': '确定删除选中的{type}吗?',
'common.filter.name': '名称查询'
'common.filter.name': '名称查询',
'common.form.password': '密码',
'common.form.username': '用户名',
'common.login.rember': '记住我'
};
22 changes: 22 additions & 0 deletions src/locales/zh-CN/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
'users.title': '用户',
'users.button.create': '新建用户',
'users.form.edit': '编辑用户',
'users.form.create': '新建用户',
'users.table.username': '用户名',
'users.table.role': '角色',
'users.form.fullname': '全名',
'users.table.user': '用户',
'users.form.admin': '管理员',
'users.form.user': '普通用户',
'users.form.newpassword': '新密码',
'users.form.currentpassword': '当前密码',
'users.form.updatepassword': '修改密码',
'users.form.rule.password':
'包含大小写字母、数字和特殊字符,6至12个字符,不允许有空格',
'users.password.uppcase': '至少包含一个大写字母',
'users.password.lowercase': '至少包含一个小写字母',
'users.password.number': '至少包含一个数字',
'users.password.special': '至少包含一个特殊字符',
'users.password.length': '长度在6至12个字符之间'
};
43 changes: 38 additions & 5 deletions src/pages/api-keys/components/add-apikey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SealInput from '@/components/seal-form/seal-input';
import SealSelect from '@/components/seal-form/seal-select';
import { PageActionType } from '@/config/types';
import { SyncOutlined } from '@ant-design/icons';
import { useIntl } from '@umijs/max';
import { Form, Modal } from 'antd';
import { expirationOptions } from '../config';
import { FormData } from '../config/types';
Expand All @@ -23,6 +24,7 @@ const AddModal: React.FC<AddModalProps> = ({
onCancel
}) => {
const [form] = Form.useForm();
const intl = useIntl();
const Suffix = (
<SyncOutlined
style={{
Expand Down Expand Up @@ -53,18 +55,49 @@ const AddModal: React.FC<AddModalProps> = ({
}
>
<Form name="addAPIKey" form={form} onFinish={onOk} preserve={false}>
<Form.Item<FormData> name="name" rules={[{ required: true }]}>
<SealInput.Input label="Name" required></SealInput.Input>
<Form.Item<FormData>
name="name"
rules={[
{
required: true,
message: intl.formatMessage(
{ id: 'common.form.rule.input' },
{
name: intl.formatMessage({ id: 'common.table.name' })
}
)
}
]}
>
<SealInput.Input
label={intl.formatMessage({ id: 'common.table.name' })}
required
></SealInput.Input>
</Form.Item>
<Form.Item<FormData> name="expires_in" rules={[{ required: true }]}>
<Form.Item<FormData>
name="expires_in"
rules={[
{
required: true,
message: intl.formatMessage(
{ id: 'common.form.rule.select' },
{
name: intl.formatMessage({ id: 'apikeys.form.expiretime' })
}
)
}
]}
>
<SealSelect
label="Expiration"
label={intl.formatMessage({ id: 'apikeys.form.expiretime' })}
required
options={expirationOptions}
></SealSelect>
</Form.Item>
<Form.Item<FormData> name="description" rules={[{ required: false }]}>
<SealInput.TextArea label="Description"></SealInput.TextArea>
<SealInput.TextArea
label={intl.formatMessage({ id: 'common.table.description' })}
></SealInput.TextArea>
</Form.Item>
</Form>
</Modal>
Expand Down
26 changes: 13 additions & 13 deletions src/pages/api-keys/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const Models: React.FC = () => {
};
const res = await createApisKey({ data: params });
setOpenAddModal(false);
message.success('successfully!');
message.success(intl.formatMessage({ id: 'common.message.success' }));
setDataSource([res, ...dataSource]);
setTotal(total + 1);
} catch (error) {
Expand All @@ -144,11 +144,14 @@ const Models: React.FC = () => {
const handleDelete = (row: ListItem) => {
Modal.confirm({
title: '',
content: 'Are you sure you want to delete the selected keys?',
content: intl.formatMessage(
{ id: 'common.delete.confirm' },
{ type: intl.formatMessage({ id: 'apikeys.table.apikeys' }) }
),
async onOk() {
console.log('OK');
await deleteApisKey(row.id);
message.success('successfully!');
message.success(intl.formatMessage({ id: 'common.message.success' }));
fetchData();
},
onCancel() {
Expand All @@ -160,10 +163,13 @@ const Models: React.FC = () => {
const handleDeleteBatch = () => {
Modal.confirm({
title: '',
content: 'Are you sure you want to delete the selected keys?',
content: intl.formatMessage(
{ id: 'common.delete.confirm' },
{ type: intl.formatMessage({ id: 'apikeys.table.apikeys' }) }
),
async onOk() {
await handleBatchRequest(rowSelection.selectedRowKeys, deleteApisKey);
message.success('successfully!');
message.success(intl.formatMessage({ id: 'common.message.success' }));
fetchData();
},
onCancel() {
Expand All @@ -172,12 +178,6 @@ const Models: React.FC = () => {
});
};

const handleEditUser = () => {
setOpenAddModal(true);
setAction(PageAction.EDIT);
setTitle('Edit User');
};

const renderSecrectKey = (text: string, record: ListItem) => {
const { value } = record;

Expand All @@ -187,7 +187,7 @@ const Models: React.FC = () => {
{value && (
<span>
<Tag color="error" style={{ padding: '10px 12px' }}>
确保立即复制您的个人访问密钥。您将无法再次看到它!
{intl.formatMessage({ id: 'apikeys.table.save.tips' })}
</Tag>
<span className="flex-center">
<Tooltip
Expand Down Expand Up @@ -299,7 +299,7 @@ const Models: React.FC = () => {
}}
/>
<Column
title="Operation"
title={intl.formatMessage({ id: 'common.table.operation' })}
key="operation"
render={(text, record: ListItem) => {
return (
Expand Down
7 changes: 7 additions & 0 deletions src/pages/login/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ export const accessToken = async () => {
method: 'POST'
});
};

export const updatePassword = async (params: any) => {
return request(`${AUTH_API}/update-password`, {
method: 'POST',
data: params
});
};
Loading

0 comments on commit 9edce71

Please sign in to comment.