Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(Account): Allow password change when the original password is empty

haitao(lj)703ff79ed8ed
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts
index c41e9d50..29aa8a19 100644
--- a/ui/src/common/interface.ts
+++ b/ui/src/common/interface.ts
@@ -131,6 +131,7 @@ export interface UserInfoRes extends UserInfoBase {
language: string;
is_admin: boolean;
e_mail?: string;
+ have_password: boolean;
[prop: string]: any;
}
diff --git a/ui/src/components/SchemaForm/index.tsx b/ui/src/components/SchemaForm/index.tsx
index 960bef45..0ce80d20 100644
--- a/ui/src/components/SchemaForm/index.tsx
+++ b/ui/src/components/SchemaForm/index.tsx
@@ -319,9 +319,6 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (
}
onChange={handleSelectChange}
isInvalid={formData[key].isInvalid}>
- <option disabled selected>
- {t('select')}
- </option>
{properties[key].enum?.map((item, index) => {
return (
<option value={String(item)} key={String(item)}>
@@ -543,10 +540,14 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (
export const initFormData = (schema: JSONSchema): Type.FormDataType => {
const formData: Type.FormDataType = {};
Object.keys(schema.properties).forEach((key) => {
- const v = schema.properties[key]?.default;
- // TODO: set default value by property type
+ const prop = schema.properties[key];
+ let defaultVal = prop?.default;
+ if (typeof defaultVal === 'undefined' && Array.isArray(prop?.enum)) {
+ // eslint-disable-next-line prefer-destructuring
+ defaultVal = prop.enum[0];
+ }
formData[key] = {
- value: typeof v !== 'undefined' ? v : '',
+ value: defaultVal,
isInvalid: false,
errorMsg: '',
};
diff --git a/ui/src/pages/Users/Settings/Account/components/ModifyPass/index.tsx b/ui/src/pages/Users/Settings/Account/components/ModifyPass/index.tsx
index e0ae0991..ca5ad45d 100644
--- a/ui/src/pages/Users/Settings/Account/components/ModifyPass/index.tsx
+++ b/ui/src/pages/Users/Settings/Account/components/ModifyPass/index.tsx
@@ -6,11 +6,13 @@ import { useToast } from '@/hooks';
import type { FormDataType } from '@/common/interface';
import { modifyPassword } from '@/services';
import { handleFormError } from '@/utils';
+import { loggedUserInfoStore } from '@/stores';
const Index: FC = () => {
const { t } = useTranslation('translation', {
keyPrefix: 'settings.account',
});
+ const { user } = loggedUserInfoStore();
const [showForm, setFormState] = useState(false);
const toast = useToast();
const [formData, setFormData] = useState<FormDataType>({
@@ -42,8 +44,7 @@ const Index: FC = () => {
const checkValidated = (): boolean => {
let bol = true;
const { old_pass, pass, pass2 } = formData;
-
- if (!old_pass.value) {
+ if (!old_pass.value && user.have_password) {
bol = false;
formData.old_pass = {
value: '',
@@ -137,7 +138,6 @@ const Index: FC = () => {
required
type="password"
placeholder=""
- // value={formData.password.value}
isInvalid={formData.old_pass.isInvalid}
onChange={(e) =>
handleChange({
@@ -161,7 +161,6 @@ const Index: FC = () => {
required
type="password"
maxLength={32}
- // value={formData.password.value}
isInvalid={formData.pass.isInvalid}
onChange={(e) =>
handleChange({
@@ -185,7 +184,6 @@ const Index: FC = () => {
required
type="password"
maxLength={32}
- // value={formData.password.value}
isInvalid={formData.pass2.isInvalid}
onChange={(e) =>
handleChange({
diff --git a/ui/src/stores/userInfo.ts b/ui/src/stores/userInfo.ts
index b04ce32f..5f24a1fa 100644
--- a/ui/src/stores/userInfo.ts
+++ b/ui/src/stores/userInfo.ts
@@ -27,6 +27,7 @@ const initUser: UserInfoRes = {
mail_status: 1,
language: 'Default',
is_admin: false,
+ have_password: true,
};
const loggedUserInfoStore = create<UserInfoStore>((set) => ({