diff --git a/src/auth/SignIn.tsx b/src/auth/SignIn.tsx index 14a001b..b5de8ba 100644 --- a/src/auth/SignIn.tsx +++ b/src/auth/SignIn.tsx @@ -1,53 +1,68 @@ +import axios from 'axios'; import React from 'react'; import { View, Text, Button, TextInput } from 'react-native'; import { setUser } from '../redux/actions'; +import Toast from 'react-native-simple-toast'; export default class SignIn extends React.Component { - constructor(props: any) { - super(props); - this.state = { - username: '', - password: '' - } - this.updateUsername = this.updateUsername.bind(this); - this.updatePassword = this.updatePassword.bind(this); - this.signInFunction = this.signInFunction.bind(this); + constructor(props: any) { + super(props); + this.state = { + username: '', + password: '' } + this.updateUsername = this.updateUsername.bind(this); + this.updatePassword = this.updatePassword.bind(this); + this.signInFunction = this.signInFunction.bind(this); + } - async signInFunction() { - const data = new FormData(); - data.append("username", this.state.username); - data.append("password", this.state.password); - const signInResponse = await fetch( - 'https://notifysync.simailadjalim.fr/user', - { - method: 'POST', - body: data - } - ); - const signInJson = await signInResponse.json(); - if (signInJson.status === "ok") { - this.props.store.dispatch(setUser(signInJson.token)); - } else console.log(signInJson); - } + async signInFunction() { + const formdata = new FormData(); + formdata.append("username", this.state.username); + formdata.append("password", this.state.password); + axios.post("https://notifysync.simailadjalim.fr/user",{ + username:this.state.username, + password:this.state.password + },{headers: {'Content-Type': 'multipart/form-data'}}) + .then((response, status) => { + this.props.store.dispatch(setUser(response.data.token)); + }) + .catch(response =>{ + console.log("error:") + console.log(response.response.data.status); + Toast.show(response.response.data.status,Toast.SHORT); + }); + //console.log("test"); + //const signInJson = data; + //const signInResponse = await fetch( + // 'https://notifysync.simailadjalim.fr/user', + // { + // method: 'POST', + // body: formdata + // } + //); + //const signInJson = await signInResponse.json();:width:, + //if (status === 200){ + //} else console.log("prout" ,signInJson); + } - updateUsername(username: string) { - this.setState({ username: username }); - } + updateUsername(username: string) { + this.setState({ username: username }); + } - updatePassword(password: string) { - this.setState({ password: password }); - } + updatePassword(password: string) { + this.setState({ password: password }); + } - render(): React.ReactNode { - return ( - - Connexion - - -