Skip to content

Commit 658bd57

Browse files
author
Ervin
committed
Connection_page
1 parent 1bc020d commit 658bd57

File tree

5 files changed

+350
-137
lines changed

5 files changed

+350
-137
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ App/node_modules
22
.git
33
.idea
44
App/.expo
5-
package-lock.json
5+
package-lock.json
6+
.DS_Store

App/auth/Auth.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,48 @@
11
import { AsyncStorage } from "react-native";
22

3-
export const USER_KEY = "auth-demo-key";
3+
let USER_KEY = "";
4+
5+
export async function getToken(values) {
6+
7+
let token = await
8+
9+
fetch(`http://d2714e36.ngrok.io/api/login_check`, {
10+
11+
method: 'POST',
12+
headers: {
13+
Accept: 'application/json',
14+
'Content-Type': 'application/json',
15+
},
16+
body: JSON.stringify({
17+
"username": values.email,
18+
"password": values.password,
19+
})
20+
})
21+
.then(async resp => {
22+
23+
return resp.json()
24+
})
25+
.then(responseData => {
26+
27+
if (responseData.token) {
28+
USER_KEY = responseData.token
29+
onSignIn()
30+
return 200
31+
}
32+
else if (responseData.code === 401) {
33+
return 401
34+
}
35+
else if (responseData.code === 500) {
36+
return 500
37+
}
38+
39+
})
40+
.catch(err => {
41+
console.log(err)
42+
})
43+
44+
return token
45+
}
446

547
export const onSignIn = () => AsyncStorage.setItem(USER_KEY, "true");
648

App/view/Inscription.js

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,34 @@ export class Inscription extends Component {
2020
show: false,
2121
showError: false,
2222
showErrorEmail: false,
23-
loading: true,
23+
loading: false,
2424
user: '',
25-
usersEmail: []
25+
emailCheck: ''
2626
}
2727
}
2828

29-
componentDidMount() {
29+
async emailCheck(values) {
3030

31-
fetch(`http://398927b4.ngrok.io/api/users`, {
31+
this.setState({loading: true})
32+
33+
fetch(`http://d2714e36.ngrok.io/users/check/`+ values.email, {
3234

33-
method: 'GET',
35+
method: 'POST',
3436
headers: {
3537
Accept: 'application/json',
3638
'Content-Type': 'application/json',
3739
}
3840
})
39-
.then(resp => {
40-
return resp.json()
41+
.then(async resp => {
42+
if (resp.status === 302) {
43+
return resp.json()
44+
}
4145
})
4246
.then(responseData => {
43-
responseData.map(x => { this.state.usersEmail.push(x.email) })
44-
this.setState({loading: false})
47+
if (responseData) {
48+
this.setState({emailCheck: responseData.email})
49+
}
50+
this.registerCall(values)
4551
})
4652
.catch(err => {
4753
console.log(err)
@@ -50,27 +56,22 @@ export class Inscription extends Component {
5056

5157
async registerCall(values) {
5258

53-
this.setState({loading: true})
54-
55-
let { usersEmail } = this.state
59+
let { emailCheck } = this.state
60+
let check
5661

57-
let check = usersEmail.map(x => {
58-
59-
if (x === values.email) {
60-
return false
61-
}
62-
})
62+
if (emailCheck === values.email) {
63+
check = false
64+
} else {
65+
check = true
66+
}
6367

6468
if (check === false) {
6569
this.setState({showErrorEmail: true})
6670
this.setState({loading: false})
71+
return false
6772
}
6873

69-
let date = values.birthDate.replace('/', '-').replace('/', '-') + "T00:00:00"
70-
let birthDate = new Date(date)
71-
let weight = parseInt(values.poids)
72-
73-
fetch(`http://398927b4.ngrok.io/api/users`, {
74+
fetch(`http://d2714e36.ngrok.io/signup`, {
7475

7576
method: 'POST',
7677
headers: {
@@ -81,8 +82,8 @@ export class Inscription extends Component {
8182
"firstname": values.prenom,
8283
"lastname": values.nom,
8384
"email": values.email,
84-
"birthDate": birthDate,
85-
"weight": weight,
85+
"birthDate": values.birthDate,
86+
"weight": parseInt(values.poids),
8687
"password": values.password,
8788
})
8889

@@ -104,12 +105,13 @@ export class Inscription extends Component {
104105
this.setState({user: data.firstname})
105106
this.setState({ show:true })
106107
setTimeout(() => {
107-
this.setState({ show:false })
108+
// this.setState({ show:false })
108109
this.props.navigation.navigate('SignIn');
109110
}, 2000)
110111
}
111112
})
112113
.catch(err => {
114+
console.log(err)
113115
this.setState({showError: true})
114116
})
115117
}
@@ -130,8 +132,7 @@ export class Inscription extends Component {
130132
.lowercase('Majuscules non valides')
131133
.email('Veuillez entrer un email valide')
132134
.ensure()
133-
.required('Champ obligatoire')
134-
.notOneOf(this.state.usersEmail, 'Adresse email déjà existant'),
135+
.required('Champ obligatoire'),
135136

136137
password: yup.string()
137138
.label('Password')
@@ -177,9 +178,8 @@ export class Inscription extends Component {
177178

178179
<KeyboardAvoidingView
179180
contentContainerStyle={styles.keyboard}
180-
behavior={"padding"}
181-
enabled
182-
keyboardVerticalOffset={10}
181+
behavior={"height"}
182+
keyboardVerticalOffset={-10}
183183
>
184184

185185
{/* Modal : Inscription réussit */}
@@ -218,7 +218,7 @@ export class Inscription extends Component {
218218
theme="danger"
219219
title="Erreur"
220220
subtitle="Un problème est survenu sur le serveur, veuillez réessayer !"
221-
headerIconComponent={<Ionicons name="ios-alert" size={70} color="white" />}
221+
headerIconComponent={<Ionicons name="ios-alert" size={90} color="white" />}
222222
titleStyle={{ fontSize: 30 }}
223223
subtitleStyle={{ fontSize: 18}}
224224
>
@@ -243,7 +243,7 @@ export class Inscription extends Component {
243243
theme="danger"
244244
title="Erreur"
245245
subtitle="L' addresse email que vous avez entré existe déjà !"
246-
headerIconComponent={<Ionicons name="ios-alert" size={70} color="white" />}
246+
headerIconComponent={<Ionicons name="ios-alert" size={90} color="white" />}
247247
titleStyle={{ fontSize: 30 }}
248248
subtitleStyle={{ fontSize: 18}}
249249
>
@@ -285,7 +285,7 @@ export class Inscription extends Component {
285285
poids: '',
286286
}}
287287

288-
onSubmit={values => this.registerCall(values)}
288+
onSubmit={values => this.emailCheck(values)}
289289
validationSchema={validationSchema}
290290
>
291291

@@ -693,8 +693,7 @@ const styles = StyleSheet.create({
693693

694694
keyboard: {
695695

696-
marginBottom: 0,
697-
paddingBottom: 0
696+
marginBottom: 0
698697
},
699698

700699
headerLogo: {

0 commit comments

Comments
 (0)