Atualizações
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
"@capacitor/haptics": "1.1.4",
|
"@capacitor/haptics": "1.1.4",
|
||||||
"@capacitor/keyboard": "1.2.2",
|
"@capacitor/keyboard": "1.2.2",
|
||||||
"@capacitor/status-bar": "1.0.8",
|
"@capacitor/status-bar": "1.0.8",
|
||||||
|
"@hookform/error-message": "^2.0.0",
|
||||||
"@ionic/react": "^6.0.0",
|
"@ionic/react": "^6.0.0",
|
||||||
"@ionic/react-router": "^6.0.0",
|
"@ionic/react-router": "^6.0.0",
|
||||||
"@testing-library/jest-dom": "^5.11.9",
|
"@testing-library/jest-dom": "^5.11.9",
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
"ionicons": "^5.4.0",
|
"ionicons": "^5.4.0",
|
||||||
"react": "^17.0.1",
|
"react": "^17.0.1",
|
||||||
"react-dom": "^17.0.1",
|
"react-dom": "^17.0.1",
|
||||||
|
"react-hook-form": "^7.30.0",
|
||||||
"react-router": "^5.2.0",
|
"react-router": "^5.2.0",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"typescript": "^4.1.3",
|
"typescript": "^4.1.3",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const sessionRoutesDefault = '/session';
|
const sessionRoutesDefault = '/sessions';
|
||||||
const sessionRoutes = {
|
const sessionRoutes = {
|
||||||
create: {
|
create: {
|
||||||
url: `${sessionRoutesDefault}/`
|
url: `${sessionRoutesDefault}/`
|
||||||
|
|||||||
@@ -23,48 +23,61 @@ import {
|
|||||||
import * as sessionRoutes from '../../services/session';
|
import * as sessionRoutes from '../../services/session';
|
||||||
import LocalStorage from "../../LocalStorage";
|
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 Page: React.FC = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [email, setEmail] = useState<string>("matheusalb3213@gmail.com");
|
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 [isError, setIsError] = useState<boolean>(false);
|
||||||
const [message, setMessage] = useState<string>("");
|
const [message, setMessage] = useState<string>("");
|
||||||
|
|
||||||
const handleLogin = async () => {
|
function validateEmail(email: string) {
|
||||||
// validação de inputs
|
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) {
|
if (!email) {
|
||||||
setMessage("Por favor, informe um e-mail válido");
|
setMessage("Por favor, informe um e-mail válido");
|
||||||
setIsError(true);
|
setIsError(true);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validateEmail(email) === false) {
|
if (validateEmail(email) === false) {
|
||||||
setMessage("E-mail inválido");
|
setMessage("E-mail inválido");
|
||||||
setIsError(true);
|
setIsError(true);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!password || password.length < 6) {
|
if (!password) {
|
||||||
setMessage("Por favor, digite a sua senha");
|
setMessage("Por favor, digite a sua senha");
|
||||||
setIsError(true);
|
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 = {
|
const singinForm = {
|
||||||
email: email,
|
login: email,
|
||||||
password: password,
|
password: password,
|
||||||
};
|
};
|
||||||
|
|
||||||
await sessionRoutes.create(singinForm).then(response => {
|
await sessionRoutes.create(singinForm).then(response => {
|
||||||
// if (!response) return
|
// if (!response) return
|
||||||
|
|
||||||
const { token } = response
|
const { token } = response.token
|
||||||
|
|
||||||
LocalStorage.setToken(token);
|
LocalStorage.setToken(token);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ let token: string | null;
|
|||||||
let header: AxiosRequestHeaders;
|
let header: AxiosRequestHeaders;
|
||||||
|
|
||||||
interface createData {
|
interface createData {
|
||||||
email: string,
|
login: string,
|
||||||
password: string,
|
password: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user