2025-05-06 06:45:49 +00:00
|
|
|
|
import ActionLink from '@/components/shared/ActionLink'
|
|
|
|
|
|
import PasswordInput from '@/components/shared/PasswordInput'
|
|
|
|
|
|
import Alert from '@/components/ui/Alert'
|
|
|
|
|
|
import Button from '@/components/ui/Button'
|
|
|
|
|
|
import { FormContainer, FormItem } from '@/components/ui/Form'
|
2025-06-28 21:34:28 +00:00
|
|
|
|
import { ROUTES_ENUM } from '@/routes/route.constant'
|
2025-08-12 08:39:06 +00:00
|
|
|
|
import { resetPassword } from '@/services/account.service'
|
2025-05-29 07:56:27 +00:00
|
|
|
|
import { useLocalization } from '@/utils/hooks/useLocalization'
|
2025-05-06 06:45:49 +00:00
|
|
|
|
import useTimeOutMessage from '@/utils/hooks/useTimeOutMessage'
|
|
|
|
|
|
import type { AxiosError } from 'axios'
|
|
|
|
|
|
import { Field, Form, Formik } from 'formik'
|
|
|
|
|
|
import { useState } from 'react'
|
2025-08-14 07:10:56 +00:00
|
|
|
|
import { Helmet } from 'react-helmet'
|
2025-05-06 06:45:49 +00:00
|
|
|
|
import { useNavigate, useSearchParams } from 'react-router-dom'
|
|
|
|
|
|
import * as Yup from 'yup'
|
|
|
|
|
|
|
|
|
|
|
|
type ResetPasswordFormSchema = {
|
|
|
|
|
|
password: string
|
|
|
|
|
|
confirmPassword: string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const validationSchema = Yup.object().shape({
|
|
|
|
|
|
password: Yup.string().required('Please enter your password'),
|
|
|
|
|
|
confirmPassword: Yup.string().oneOf([Yup.ref('password')], 'Your passwords do not match'),
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const ResetPassword = () => {
|
|
|
|
|
|
const disableSubmit = false
|
2025-08-11 06:34:44 +00:00
|
|
|
|
const signInUrl = ROUTES_ENUM.authenticated.login
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
|
|
|
|
|
const [searchParams] = useSearchParams()
|
|
|
|
|
|
const userId = searchParams.get('userId')
|
|
|
|
|
|
const resetToken = searchParams.get('resetToken')
|
2025-05-29 07:56:27 +00:00
|
|
|
|
const { translate } = useLocalization()
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
|
|
|
|
|
// bu olmadan da oluyor sanırım
|
|
|
|
|
|
// const result = useQuery({
|
|
|
|
|
|
// queryKey: ['verifyPasswordResetToken', userId, resetToken],
|
|
|
|
|
|
// queryFn: () => verifyPasswordResetToken(userId, resetToken),
|
|
|
|
|
|
// retry: false,
|
|
|
|
|
|
// refetchOnWindowFocus: false,
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
const [resetComplete, setResetComplete] = useState(false)
|
|
|
|
|
|
|
|
|
|
|
|
const [message, setMessage] = useTimeOutMessage()
|
|
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
|
|
|
|
|
|
|
const onSubmit = async (
|
|
|
|
|
|
values: ResetPasswordFormSchema,
|
|
|
|
|
|
setSubmitting: (isSubmitting: boolean) => void,
|
|
|
|
|
|
) => {
|
|
|
|
|
|
if (!userId || !resetToken) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const { password } = values
|
|
|
|
|
|
setSubmitting(true)
|
|
|
|
|
|
try {
|
|
|
|
|
|
const resp = await resetPassword(userId, resetToken, password)
|
|
|
|
|
|
if (resp.data) {
|
|
|
|
|
|
setSubmitting(false)
|
|
|
|
|
|
setResetComplete(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (errors) {
|
|
|
|
|
|
setMessage(
|
|
|
|
|
|
(errors as AxiosError<{ message: string }>)?.response?.data?.message ||
|
|
|
|
|
|
(errors as Error).toString(),
|
|
|
|
|
|
)
|
|
|
|
|
|
setSubmitting(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const onContinue = () => {
|
2025-08-11 06:34:44 +00:00
|
|
|
|
navigate(ROUTES_ENUM.authenticated.login)
|
2025-05-06 06:45:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div>
|
2025-08-14 07:10:56 +00:00
|
|
|
|
<Helmet
|
2025-09-13 11:46:34 +00:00
|
|
|
|
titleTemplate="%s | Sözsoft Kurs Platform"
|
2025-08-14 07:10:56 +00:00
|
|
|
|
title={translate('AbpAccount::' + 'ResetPassword')}
|
2025-09-13 11:46:34 +00:00
|
|
|
|
defaultTitle="Sözsoft Kurs Platform"
|
2025-08-14 07:10:56 +00:00
|
|
|
|
></Helmet>
|
2025-05-06 06:45:49 +00:00
|
|
|
|
<div className="mb-6">
|
|
|
|
|
|
{resetComplete ? (
|
|
|
|
|
|
<>
|
2025-05-29 07:56:27 +00:00
|
|
|
|
<h3 className="mb-1">{translate('::Abp.Account.ResetPassword.ResetDone')}</h3>
|
|
|
|
|
|
<p>{translate('::Abp.Account.ResetPassword.ResetDone.Message')}</p>
|
2025-05-06 06:45:49 +00:00
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<>
|
2025-05-29 07:56:27 +00:00
|
|
|
|
<h3 className="mb-1">{translate('::Abp.Account.ResetPassword.SetNewPassword')}</h3>
|
|
|
|
|
|
<p>{translate('::Abp.Account.ResetPassword.SetNewPassword.Message')}</p>
|
2025-05-06 06:45:49 +00:00
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{message && (
|
|
|
|
|
|
<Alert showIcon className="mb-4" type="danger">
|
|
|
|
|
|
{message}
|
|
|
|
|
|
</Alert>
|
|
|
|
|
|
)}
|
|
|
|
|
|
<Formik
|
|
|
|
|
|
initialValues={{
|
|
|
|
|
|
password: '',
|
|
|
|
|
|
confirmPassword: '',
|
|
|
|
|
|
}}
|
|
|
|
|
|
validationSchema={validationSchema}
|
|
|
|
|
|
onSubmit={(values, { setSubmitting }) => {
|
|
|
|
|
|
if (!disableSubmit) {
|
|
|
|
|
|
onSubmit(values, setSubmitting)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setSubmitting(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{({ touched, errors, isSubmitting }) => (
|
|
|
|
|
|
<Form>
|
|
|
|
|
|
<FormContainer>
|
|
|
|
|
|
{!resetComplete ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<FormItem
|
2025-05-29 07:56:27 +00:00
|
|
|
|
label={translate('::Abp.Account.Password')}
|
2025-05-06 06:45:49 +00:00
|
|
|
|
invalid={errors.password && touched.password}
|
|
|
|
|
|
errorMessage={errors.password}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Field
|
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
|
name="password"
|
2025-05-29 07:56:27 +00:00
|
|
|
|
placeholder={translate('::Abp.Account.Password')}
|
2025-05-06 06:45:49 +00:00
|
|
|
|
component={PasswordInput}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
<FormItem
|
2025-05-29 07:56:27 +00:00
|
|
|
|
label={translate('::Abp.Identity.Password.ConfirmPassword')}
|
2025-05-06 06:45:49 +00:00
|
|
|
|
invalid={errors.confirmPassword && touched.confirmPassword}
|
|
|
|
|
|
errorMessage={errors.confirmPassword}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Field
|
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
|
name="confirmPassword"
|
2025-05-29 07:56:27 +00:00
|
|
|
|
placeholder={translate('::Abp.Identity.Password.ConfirmPassword')}
|
2025-05-06 06:45:49 +00:00
|
|
|
|
component={PasswordInput}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
<Button block loading={isSubmitting} variant="solid" type="submit">
|
|
|
|
|
|
{isSubmitting ? 'Submitting...' : 'Submit'}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Button block variant="solid" type="button" onClick={onContinue}>
|
2025-05-29 07:56:27 +00:00
|
|
|
|
{translate('::Abp.Account.ResetPassword.Continue')}
|
2025-05-06 06:45:49 +00:00
|
|
|
|
</Button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="mt-4 text-center">
|
2025-05-29 07:56:27 +00:00
|
|
|
|
<span>{translate('::Abp.Account.Backto')} </span>
|
|
|
|
|
|
<ActionLink to={signInUrl}>{translate('::Abp.Account.SignIn')}</ActionLink>
|
2025-05-06 06:45:49 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</FormContainer>
|
|
|
|
|
|
</Form>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Formik>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default ResetPassword
|