mirror of https://gitee.com/answerdev/answer.git
fix: change password add verification code verification
This commit is contained in:
parent
fb8c1fbb5f
commit
547d035e42
|
@ -1072,8 +1072,15 @@ ui:
|
||||||
accepted: Accepted
|
accepted: Accepted
|
||||||
answered: answered
|
answered: answered
|
||||||
asked: asked
|
asked: asked
|
||||||
upvote: upvote
|
rank_type:
|
||||||
downvote: downvote
|
upvote: upvote
|
||||||
|
upvoted: upvoted
|
||||||
|
downvote: downvote
|
||||||
|
downvoted: downvoted
|
||||||
|
edit: edit
|
||||||
|
accept: accept
|
||||||
|
accepted: accepted
|
||||||
|
downvoted: downvoted
|
||||||
mod_short: Mod
|
mod_short: Mod
|
||||||
mod_long: Moderators
|
mod_long: Moderators
|
||||||
x_reputation: reputation
|
x_reputation: reputation
|
||||||
|
|
|
@ -161,7 +161,7 @@ export interface PasswordResetReq extends ImgCodeReq {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CheckImgReq {
|
export interface CheckImgReq {
|
||||||
action: 'login' | 'e_mail' | 'find_pass';
|
action: 'login' | 'e_mail' | 'find_pass' | 'modify_pass';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SetNoticeReq {
|
export interface SetNoticeReq {
|
||||||
|
|
|
@ -48,7 +48,9 @@ const Index: FC<Props> = ({ visible, data }) => {
|
||||||
{item.title}
|
{item.title}
|
||||||
</a>
|
</a>
|
||||||
<div className="d-flex align-items-center fs-14 text-secondary">
|
<div className="d-flex align-items-center fs-14 text-secondary">
|
||||||
<span>{item.reputation > 0 ? t('upvote') : t('downvote')}</span>
|
<span>
|
||||||
|
{t(item.rank_type, { keyPrefix: 'personal.rank_type' })}
|
||||||
|
</span>
|
||||||
<span className="split-dot" />
|
<span className="split-dot" />
|
||||||
<FormatTime time={item.created_at} className="me-4" />
|
<FormatTime time={item.created_at} className="me-4" />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import type * as Type from '@/common/interface';
|
||||||
import { useToast } from '@/hooks';
|
import { useToast } from '@/hooks';
|
||||||
import { getLoggedUserInfo, changeEmail, checkImgCode } from '@/services';
|
import { getLoggedUserInfo, changeEmail, checkImgCode } from '@/services';
|
||||||
import { handleFormError } from '@/utils';
|
import { handleFormError } from '@/utils';
|
||||||
import { PicAuthCodeModal } from '@/components/Modal';
|
import { PicAuthCodeModal } from '@/components';
|
||||||
|
|
||||||
const Index: FC = () => {
|
const Index: FC = () => {
|
||||||
const { t } = useTranslation('translation', {
|
const { t } = useTranslation('translation', {
|
||||||
|
@ -149,6 +149,7 @@ const Index: FC = () => {
|
||||||
|
|
||||||
if (imgCode.verify) {
|
if (imgCode.verify) {
|
||||||
setModalState(true);
|
setModalState(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
postEmail();
|
postEmail();
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,10 +5,11 @@ import { useTranslation } from 'react-i18next';
|
||||||
import classname from 'classnames';
|
import classname from 'classnames';
|
||||||
|
|
||||||
import { useToast } from '@/hooks';
|
import { useToast } from '@/hooks';
|
||||||
import type { FormDataType } from '@/common/interface';
|
import type { FormDataType, ImgCodeRes } from '@/common/interface';
|
||||||
import { modifyPassword } from '@/services';
|
import { modifyPassword, checkImgCode } from '@/services';
|
||||||
import { handleFormError } from '@/utils';
|
import { handleFormError } from '@/utils';
|
||||||
import { loggedUserInfoStore } from '@/stores';
|
import { loggedUserInfoStore } from '@/stores';
|
||||||
|
import { PicAuthCodeModal } from '@/components';
|
||||||
|
|
||||||
const Index: FC = () => {
|
const Index: FC = () => {
|
||||||
const { t } = useTranslation('translation', {
|
const { t } = useTranslation('translation', {
|
||||||
|
@ -34,6 +35,20 @@ const Index: FC = () => {
|
||||||
errorMsg: '',
|
errorMsg: '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const [showModal, setModalState] = useState(false);
|
||||||
|
const [imgCode, setImgCode] = useState<ImgCodeRes>({
|
||||||
|
captcha_id: '',
|
||||||
|
captcha_img: '',
|
||||||
|
verify: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const getImgCode = () => {
|
||||||
|
checkImgCode({
|
||||||
|
action: 'modify_pass',
|
||||||
|
}).then((res) => {
|
||||||
|
setImgCode(res);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleFormState = () => {
|
const handleFormState = () => {
|
||||||
setFormState((pre) => !pre);
|
setFormState((pre) => !pre);
|
||||||
|
@ -104,17 +119,22 @@ const Index: FC = () => {
|
||||||
return bol;
|
return bol;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = (event: FormEvent) => {
|
const postModifyPass = (event?: any) => {
|
||||||
event.preventDefault();
|
if (event) {
|
||||||
event.stopPropagation();
|
event.preventDefault();
|
||||||
if (!checkValidated()) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
modifyPassword({
|
const params: any = {
|
||||||
old_pass: formData.old_pass.value,
|
old_pass: formData.old_pass.value,
|
||||||
pass: formData.pass.value,
|
pass: formData.pass.value,
|
||||||
})
|
};
|
||||||
|
|
||||||
|
if (imgCode.verify) {
|
||||||
|
params.captcha_code = formData.captcha_code.value;
|
||||||
|
params.captcha_id = imgCode.captcha_id;
|
||||||
|
}
|
||||||
|
modifyPassword(params)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
setModalState(false);
|
||||||
toast.onShow({
|
toast.onShow({
|
||||||
msg: t('update_password', { keyPrefix: 'toast' }),
|
msg: t('update_password', { keyPrefix: 'toast' }),
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
|
@ -124,11 +144,31 @@ const Index: FC = () => {
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.isError) {
|
if (err.isError) {
|
||||||
const data = handleFormError(err, formData);
|
const data = handleFormError(err, formData);
|
||||||
|
if (!err.list.find((v) => v.error_field.indexOf('captcha') >= 0)) {
|
||||||
|
setModalState(false);
|
||||||
|
}
|
||||||
setFormData({ ...data });
|
setFormData({ ...data });
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
getImgCode();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSubmit = (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
if (!checkValidated()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imgCode.verify) {
|
||||||
|
setModalState(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
postModifyPass();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-5">
|
<div className="mt-5">
|
||||||
{showForm ? (
|
{showForm ? (
|
||||||
|
@ -220,11 +260,26 @@ const Index: FC = () => {
|
||||||
<Button
|
<Button
|
||||||
variant="outline-secondary"
|
variant="outline-secondary"
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={handleFormState}>
|
onClick={() => {
|
||||||
|
handleFormState();
|
||||||
|
getImgCode();
|
||||||
|
}}>
|
||||||
{t('change_pass_btn')}
|
{t('change_pass_btn')}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<PicAuthCodeModal
|
||||||
|
visible={showModal}
|
||||||
|
data={{
|
||||||
|
captcha: formData.captcha_code,
|
||||||
|
imgCode,
|
||||||
|
}}
|
||||||
|
handleCaptcha={handleChange}
|
||||||
|
clickSubmit={postModifyPass}
|
||||||
|
refreshImgCode={getImgCode}
|
||||||
|
onClose={() => setModalState(false)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue