Skip to content

Commit

Permalink
fix: reset password
Browse files Browse the repository at this point in the history
Signed-off-by: MicroOps-cn <[email protected]>
  • Loading branch information
MicroOps-cn committed Feb 8, 2025
1 parent 4e2d171 commit 708ddca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/endpoint/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ func MakeResetUserPasswordEndpoint(s service.Service) endpoint.Endpoint {
} else {
return nil, errors.UnauthorizedError()
}
} else {
return nil, errors.LackParameterError("username")
}
} else {
return nil, errors.LackParameterError("token,id")
Expand Down
12 changes: 6 additions & 6 deletions public/src/pages/Account/ResetPassword/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ProFormText, LoginForm } from '@ant-design/pro-form';
import { Link } from '@umijs/max';

import styles from './index.less';
import { getQueryParam } from '@/utils/url';

const ResetPassword: React.FC = () => {
const rootIntl = useIntl();
Expand Down Expand Up @@ -66,15 +67,14 @@ const ResetPassword: React.FC = () => {
}}
onFinish={async (values) => {
try {
console.log(query, values);
setLoading(true);
if (
await handleResetPassword({
newPassword: values.newPassword,
oldPassword: values.oldPassword,
userId: query.userId as string | undefined,
token: query.token as string | undefined,
username: (query.username ?? values.username) as string | undefined,
userId: getQueryParam(query, "userId"),
token: getQueryParam(query, "token"),
username: getQueryParam(query, "username") ?? values.username,
})
) {
history.push(loginPath);
Expand All @@ -87,14 +87,14 @@ const ResetPassword: React.FC = () => {
}}
>
<ProFormText
name="username"
fieldProps={{
value: query.username as string | undefined,
value: getQueryParam(query, "username"),
size: 'large',
autoComplete: 'username',
disabled: Boolean(query.username),
prefix: <UserOutlined className={styles.prefixIcon} />,
}}
name={'username'}
placeholder={intl.t('username.placeholder', 'Please enter your username')}
rules={[
{
Expand Down
16 changes: 16 additions & 0 deletions public/src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { isArray, isString } from 'lodash';
import { ParsedQuery, parse } from 'query-string';

export function getQueryParam(query: ParsedQuery | string, key: string): string | undefined {
if (isString(query)) {
return getQueryParam(parse(query), key)
}
const val = query[key]
if (isArray(val)) {
if (val.length > 0) {
return val[0]
}
return undefined
}
return val ?? undefined
}

0 comments on commit 708ddca

Please sign in to comment.