diff --git a/src/app/api/auth.js b/src/app/api/auth.js index 40f384d..23fb782 100644 --- a/src/app/api/auth.js +++ b/src/app/api/auth.js @@ -1,20 +1,43 @@ -import { create } from "apisauce"; 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 }; diff --git a/src/app/auth/authClient.js b/src/app/auth/authClient.js index 0960d07..38370f3 100644 --- a/src/app/auth/authClient.js +++ b/src/app/auth/authClient.js @@ -1,7 +1,7 @@ import { create } from "apisauce"; const authClient = create({ - baseURL: "http://191.233.193.200:8080/users", + baseURL: "http://wpd.brazilsouth.cloudapp.azure.com:8080/users", }); export default authClient; diff --git a/src/app/screens/RegisterScreen.js b/src/app/screens/RegisterScreen.js index 5de907d..3837194 100644 --- a/src/app/screens/RegisterScreen.js +++ b/src/app/screens/RegisterScreen.js @@ -19,6 +19,7 @@ import SearchablePicker from "../components/SearchablePicker"; import { states, statesToCities } from "../assets/cities_states"; import { useFormikContext } from "formik"; import Checkbox from "../components/forms/CheckBox"; +import {signup} from "../api/auth"; const phoneRegex = RegExp( /^\(?[\(]?([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 (
{ 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} >