update forgotPassword

This commit is contained in:
Alex Santos 2022-06-29 09:50:55 -03:00
parent dcf35c419b
commit 6ea0ac91b5
2 changed files with 38 additions and 14 deletions

View File

@ -40,13 +40,7 @@ export default function ForgotPassword() {
setOpenSnackSuccess(false); setOpenSnackSuccess(false);
}; };
function handleChangePassword() {
if (same) {
router.push('/')
} else {
null
}
}
useEffect(() => { useEffect(() => {
if (password == confirmPassword && password != '') { if (password == confirmPassword && password != '') {
@ -66,7 +60,7 @@ export default function ForgotPassword() {
} }
return ( return (
<ForgotPasswordView auth={rota} > <ForgotPasswordView auth={rota}>
<Head> <Head>
<title>Smart Energia</title> <title>Smart Energia</title>
</Head> </Head>
@ -103,7 +97,6 @@ export default function ForgotPassword() {
} }
export const getServerSideProps: GetServerSideProps = async (ctx) => { export const getServerSideProps: GetServerSideProps = async (ctx) => {
const apiClient = getAPIClient(ctx)
const { ['@smartAuth-token']: token } = parseCookies(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx)
const { ['user-name']: userName } = parseCookies(ctx) const { ['user-name']: userName } = parseCookies(ctx)
if (!token) { if (!token) {

View File

@ -10,12 +10,18 @@ import Alert from '@mui/material/Alert';
import { VerifyEmailContainer, VerifyEmailView } from '../styles/layouts/forgotPassword/verifyEmail'; import { VerifyEmailContainer, VerifyEmailView } from '../styles/layouts/forgotPassword/verifyEmail';
import RenderIf from '../utils/renderIf'; import RenderIf from '../utils/renderIf';
import Head from 'next/head'; import Head from 'next/head';
import { api } from '../services/api';
import { GetServerSideProps } from 'next';
import { parseCookies } from 'nookies';
export default function VerifyEmail() { export default function VerifyEmail() {
const [sent, setSent]=useState(false); const [sent, setSent]=useState(false);
const [code, setCode]=useState<string>('') const [code, setCode]=useState<string>('')
const [codeStatus, setCodeStatus]=useState<boolean>(null) const [codeStatus, setCodeStatus]=useState<boolean>(null)
const formData = new FormData();
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false);
const [openSnackError, setOpenSnackError] = useState<boolean>(false);
const [email, setEmail] = useState<any>();
const [values, setValues] = React.useState({ const [values, setValues] = React.useState({
password: '', password: '',
showPassword: false, showPassword: false,
@ -30,6 +36,15 @@ export default function VerifyEmail() {
setCodeStatus(null) setCodeStatus(null)
}, [rota]) }, [rota])
function handleSendEmail() {
formData.append('email', email)
api.post('/auth/forgot-password', formData).then(res => {
setOpenSnackSuccess(true)
}).catch(res => {
setOpenSnackError(true)
})
}
function verifyConfirmationCode() { function verifyConfirmationCode() {
if (code === '0000') { if (code === '0000') {
setTimeout(() => { setTimeout(() => {
@ -50,13 +65,10 @@ export default function VerifyEmail() {
<VerifyEmailContainer> <VerifyEmailContainer>
<h1>Bem-Vindo</h1> <h1>Bem-Vindo</h1>
<h2>Estratégias Inteligentes em<br /> Gestão de Energia</h2> <h2>Estratégias Inteligentes em<br /> Gestão de Energia</h2>
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Email" variant="outlined"/> <TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Email" variant="outlined"/>
<RenderIf isTrue={sent? false : true}> <RenderIf isTrue={sent? false : true}>
<LoginButton title='Enviar Email' onClick={() => setSent(true)} /> <LoginButton title='Enviar Email' onClick={() => handleSendEmail()} />
</RenderIf> </RenderIf>
<RenderIf isTrue={sent? true : false}> <RenderIf isTrue={sent? true : false}>
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Nova Senha" variant="outlined"/> <TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Nova Senha" variant="outlined"/>
<TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Codigo de verificação" variant="outlined" onChange={value => setCode(value.target.value)} /> <TextField id="outlined-basic" sx={{ m: 1, width: '90%' }}label="Codigo de verificação" variant="outlined" onChange={value => setCode(value.target.value)} />
@ -79,3 +91,22 @@ export default function VerifyEmail() {
</VerifyEmailView> </VerifyEmailView>
) )
} }
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const { ['@smartAuth-token']: token } = parseCookies(ctx)
const { ['user-name']: userName } = parseCookies(ctx)
if (!token) {
return {
redirect: {
destination: '/',
permanent: false
}
}
}
return {
props: {
userName
}
}
}