endpoints de hugo
This commit is contained in:
parent
ba98884667
commit
ffa909734f
510
package-lock.json
generated
510
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -9,12 +9,25 @@ function ForgotPassword() {
|
|||||||
setEmail(e.target.value);
|
setEmail(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (email) {
|
if (email) {
|
||||||
// Simulate sending email
|
try {
|
||||||
|
const response = await fetch("https://mock.apidog.com/m1/1053378-0-default/auth/v1/otp", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ email })
|
||||||
|
});
|
||||||
|
if (response.ok) {
|
||||||
setAlert("E-mail de verificação enviado!");
|
setAlert("E-mail de verificação enviado!");
|
||||||
// You can add your actual email logic here
|
console.log("Magic link enviado para:", email);
|
||||||
|
} else {
|
||||||
|
setAlert("Não foi possível enviar o e-mail. Tente novamente.");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setAlert("Erro ao enviar e-mail. Tente novamente.");
|
||||||
|
console.error("Falha ao enviar magic link:", error);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setAlert("Preencha o campo de e-mail!");
|
setAlert("Preencha o campo de e-mail!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
|
|
||||||
function Register() {
|
function Register() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [form, setForm] = useState({
|
const [form, setForm] = useState({
|
||||||
@ -14,11 +15,12 @@ function Register() {
|
|||||||
const [showPassword, setShowPassword] = useState(false);
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
setForm({ ...form, [e.target.name]: e.target.value });
|
setForm({ ...form, [e.target.name]: e.target.value });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLogin = (e) => {
|
const handleLogin = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (
|
if (
|
||||||
form.email &&
|
form.email &&
|
||||||
@ -31,13 +33,93 @@ function Register() {
|
|||||||
setAlert("As senhas não coincidem!");
|
setAlert("As senhas não coincidem!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// ...register logic...
|
try {
|
||||||
navigate('/secretaria/inicio');
|
const response = await fetch("https://mock.apidog.com/m1/1053378-0-default/auth/v1/otp", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: form.email,
|
||||||
|
username: form.username,
|
||||||
|
userType: form.userType,
|
||||||
|
password: form.password
|
||||||
|
})
|
||||||
|
});
|
||||||
|
if (response.ok) {
|
||||||
|
setAlert("Cadastro realizado! Verifique seu e-mail.");
|
||||||
|
console.log("Usuário cadastrado:", form.email);
|
||||||
|
} else {
|
||||||
|
setAlert("Não foi possível cadastrar. Tente novamente.");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setAlert("Erro ao cadastrar. Tente novamente.");
|
||||||
|
console.error("Falha ao cadastrar usuário:", error);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setAlert("Preencha todos os campos!");
|
setAlert("Preencha todos os campos!");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loginWithPassword = async (email, password) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('https://mock.apidog.com/m1/1053378-0-default/auth/v1/token?grant_type=password', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer <seu-token>',
|
||||||
|
'apikey': '<sua-api-key>',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: email,
|
||||||
|
password: password
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
console.log("Login bem-sucedido:", data);
|
||||||
|
setAlert("Login realizado com sucesso!");
|
||||||
|
} else {
|
||||||
|
console.error("Falha no login:", data);
|
||||||
|
setAlert(data.message || "E-mail ou senha incorretos.");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erro na chamada de login:", error);
|
||||||
|
setAlert("Ocorreu um erro de rede ao tentar fazer login.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const sendMagicLink = async (email) => {
|
||||||
|
const magicLinkEndpoint = "https://mock.apidog.com/m1/1053378-0-default/auth/v1/otp";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(magicLinkEndpoint, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer <seu-token>',
|
||||||
|
'apikey': '<sua-api-key>',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: email
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
console.log("Magic link enviado:", data);
|
||||||
|
setAlert("Magic link enviado para o seu e-mail! Verifique sua caixa de entrada.");
|
||||||
|
} else {
|
||||||
|
console.error("Falha ao enviar magic link:", data);
|
||||||
|
setAlert(data.message || "Não foi possível enviar o magic link.");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erro na chamada de envio de magic link:", error);
|
||||||
|
setAlert("Ocorreu um erro de rede ao enviar o magic link.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="mt-3 card-position">
|
<div className="mt-3 card-position">
|
||||||
@ -179,4 +261,5 @@ function Register() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default Register;
|
export default Register;
|
||||||
Loading…
x
Reference in New Issue
Block a user