Browse Source

API connection in register screen

master
GabrielTrettel 3 years ago
parent
commit
c71431878e
  1. 57
      src/app/api/auth.js
  2. 2
      src/app/auth/authClient.js
  3. 12
      src/app/screens/RegisterScreen.js

57
src/app/api/auth.js

@ -1,20 +1,43 @@
import { create } from "apisauce";
import authClient from "../auth/authClient"; import authClient from "../auth/authClient";
/*const login = (name, password) =>
authClient.post(`/login?username=${name}&password=${password}`);*/
function login(name, password) {
// NOTE: Change to API in future
if (name !== "1199998888" || password !== "qwertyui") {
return {
ok: false,
};
}
return {
ok: true,
data:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiVXN1w6FyaW8gVGVzdGUiLCJlbWFpbCI6InVzdWFyaW9AdGVzdGUuY29tLmJyIiwiaW5zdGl0dXRpb25OYW1lIjoiRS4gRS4gVmljZW50ZSBMZXBvcmFjZSIsImluc3RpdHV0aW9uVHlwZSI6IkVzY29sYSIsIklEIjoiMSJ9.dk-Nl5VLvAWhT_JUYREpJYYCc98s71SyHJwmwH55ZS4",
};
}
function login(name, password) {
return authClient.post(`/login?username=${name}&password=${password}`);
}
export default login;
function signup({
name,
number,
password,
dateofborn,
confirmPassword,
institutionName,
gender,
state,
city,
institution,
secQuestion,
secQuestionAns,
consent,
}) {
const body = JSON.stringify({
username: number,
nickname: name,
password: password,
dateofborn: dateofborn,
gender: gender,
state: state,
city: city,
institutiontype: institution,
institution: institutionName,
securityquestion: secQuestion,
securityanswer: secQuestionAns,
termsofusage: consent,
roles: ["ROLE_CLIENT"],
});
console.log(body);
return authClient.post(`/signup`, body);
}
export { login, signup };

2
src/app/auth/authClient.js

@ -1,7 +1,7 @@
import { create } from "apisauce"; import { create } from "apisauce";
const authClient = create({ const authClient = create({
baseURL: "http://191.233.193.200:8080/users",
baseURL: "http://wpd.brazilsouth.cloudapp.azure.com:8080/users",
}); });
export default authClient; export default authClient;

12
src/app/screens/RegisterScreen.js

@ -19,6 +19,7 @@ import SearchablePicker from "../components/SearchablePicker";
import { states, statesToCities } from "../assets/cities_states"; import { states, statesToCities } from "../assets/cities_states";
import { useFormikContext } from "formik"; import { useFormikContext } from "formik";
import Checkbox from "../components/forms/CheckBox"; import Checkbox from "../components/forms/CheckBox";
import {signup} from "../api/auth";
const phoneRegex = RegExp( const phoneRegex = RegExp(
/^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/ /^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/
@ -238,6 +239,11 @@ export default function RegisterScreen(props) {
} }
}; };
const handleSubmit = async (form) => {
const result = await signup({...form, dateofborn: date.format("DD/MM/yyyy")});
console.log(result);
};
return ( return (
<Screen style={styles.containter}> <Screen style={styles.containter}>
<Form <Form
@ -246,7 +252,6 @@ export default function RegisterScreen(props) {
number: "", number: "",
password: "", password: "",
confirmPassword: "", confirmPassword: "",
gender: "",
institutionName: "", institutionName: "",
gender: "", gender: "",
state: "", state: "",
@ -258,8 +263,9 @@ export default function RegisterScreen(props) {
}} }}
onSubmit={(form) => { onSubmit={(form) => {
comparePassword(form.password, form.confirmPassword); comparePassword(form.password, form.confirmPassword);
console.log("cadastro ainda não implementado");
console.log("Forms values: \n" + JSON.stringify(form));
handleSubmit(form)
// console.log("cadastro ainda não implementado");
// console.log("Forms values: \n" + JSON.stringify(form));
}} }}
validationSchema={validationSchema} validationSchema={validationSchema}
> >

Loading…
Cancel
Save