|
|
|
|
@@ -23,48 +23,61 @@ import {
|
|
|
|
|
import * as sessionRoutes from '../../services/session';
|
|
|
|
|
import LocalStorage from "../../LocalStorage";
|
|
|
|
|
|
|
|
|
|
function validateEmail(email: string) {
|
|
|
|
|
const re =
|
|
|
|
|
/^((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))$/;
|
|
|
|
|
return re.test(String(email).toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Page: React.FC = () => {
|
|
|
|
|
const history = useHistory();
|
|
|
|
|
const [email, setEmail] = useState<string>("matheusalb3213@gmail.com");
|
|
|
|
|
const [password, setPassword] = useState<string>("1234");
|
|
|
|
|
const [password, setPassword] = useState<string>("123456");
|
|
|
|
|
const [isError, setIsError] = useState<boolean>(false);
|
|
|
|
|
const [message, setMessage] = useState<string>("");
|
|
|
|
|
|
|
|
|
|
const handleLogin = async () => {
|
|
|
|
|
// validação de inputs
|
|
|
|
|
function validateEmail(email: string) {
|
|
|
|
|
const re =
|
|
|
|
|
/^((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))$/;
|
|
|
|
|
return re.test(String(email).toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const validateForm = () => {
|
|
|
|
|
if (!email) {
|
|
|
|
|
setMessage("Por favor, informe um e-mail válido");
|
|
|
|
|
setIsError(true);
|
|
|
|
|
return;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (validateEmail(email) === false) {
|
|
|
|
|
setMessage("E-mail inválido");
|
|
|
|
|
setIsError(true);
|
|
|
|
|
return;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!password || password.length < 6) {
|
|
|
|
|
if (!password) {
|
|
|
|
|
setMessage("Por favor, digite a sua senha");
|
|
|
|
|
setIsError(true);
|
|
|
|
|
return;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(password.length < 6) {
|
|
|
|
|
setMessage("A senha deve conter ao menos 6 dígitos");
|
|
|
|
|
setIsError(true);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleLogin = async () => {
|
|
|
|
|
if (!validateForm()) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const singinForm = {
|
|
|
|
|
email: email,
|
|
|
|
|
login: email,
|
|
|
|
|
password: password,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sessionRoutes.create(singinForm).then(response => {
|
|
|
|
|
// if (!response) return
|
|
|
|
|
|
|
|
|
|
const { token } = response
|
|
|
|
|
const { token } = response.token
|
|
|
|
|
|
|
|
|
|
LocalStorage.setToken(token);
|
|
|
|
|
|
|
|
|
|
|