@@ -14,6 +14,9 @@ import DeviceInfo from 'react-native-device-info';
14
14
import { createStackNavigator , createSwitchNavigator , createAppContainer } from 'react-navigation' ;
15
15
import ListScreen from './ListScreen' ;
16
16
import AWSSignature from 'react-native-aws-signature' ;
17
+ import Loader from './Loader' ;
18
+ import WebviewScreen from './WebviewScreen' ;
19
+ import axios from 'axios' ;
17
20
18
21
Platform . select ( {
19
22
ios : 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu' ,
@@ -31,21 +34,18 @@ class HomeScreen extends Component<Props> {
31
34
username : '' ,
32
35
password : '' ,
33
36
loginStatus : false ,
37
+ loader : false
34
38
} ;
35
39
this . validate = this . validate . bind ( this ) ;
36
-
37
-
38
- const loginToken = AsyncStorage . getItem ( "loginToken" ) ;
39
- if ( loginToken == "1" ) {
40
+ this . validateGuid = this . validateGuid . bind ( this ) ;
41
+ // AsyncStorage.clear(async function(){
40
42
41
- this . setState ( { loginStatus : true } ) ;
42
- } else {
43
- this . setState ( { loginStatus : false } ) ;
44
- }
43
+ //});
44
+
45
45
//Alert.alert(JSON.stringify(userToken));
46
46
// This will switch to the App screen or Auth screen and this loading
47
47
// screen will be unmounted and thrown away.
48
- this . props . navigation . navigate ( this . state . loginStatus ? 'List' : 'App' ) ;
48
+
49
49
50
50
51
51
@@ -56,13 +56,52 @@ class HomeScreen extends Component<Props> {
56
56
static navigationOptions = {
57
57
header : null
58
58
}
59
+
60
+
61
+ validateGuid = async ( ) = > {
62
+ var thisobj = this ;
63
+ var loginToken = await AsyncStorage . getItem ( "loginToken" ) ;
64
+ await Alert . alert ( "login token " + JSON . stringify ( loginToken ) ) ;
65
+ //console.log('login token', loginToken);
66
+ if ( loginToken != "" ) {
67
+ DeviceInfo . getMACAddress ( ) . then ( mac => {
68
+ //Alert.alert("mac "+mac);
69
+
70
+ axios . get ( 'https://mdev.humaxdigital.com/HumaxMobile/NonAuth/AuthMobileApp.aspx?AppID=Mobile&MacAddress=' + mac + '&AuthKey=' + loginToken )
71
+ . then ( async function ( responseData ) {
72
+ await Alert . alert ( "login token " + responseData . data ) ;
73
+ //console.log('verify res', responseData);
74
+ if ( responseData . data ) {
75
+ thisobj . props . navigation . navigate ( 'List' ) ;
76
+ } else {
77
+
78
+ AsyncStorage . removeItem ( "loginToken" ) ;
79
+ thisobj . props . navigation . navigate ( 'App' ) ;
80
+ }
81
+ } ) ;
82
+
83
+ // "E5:12:D8:E5:69:97"
84
+
85
+ } ) ;
86
+
87
+
88
+ } else {
89
+
90
+ this . props . navigation . navigate ( 'App ') ;
91
+ }
92
+ }
59
93
_bootstrapAsync = async ( ) => {
94
+ this . setState ( {
95
+ loader :true
96
+ } )
60
97
const dname = DeviceInfo . getDeviceName ( ) ;
61
98
//const mac = DeviceInfo.getMACAddress();
62
99
const appName = DeviceInfo . getApplicationName ( ) ;
63
100
DeviceInfo . getMACAddress ( ) . then ( mac => {
101
+
102
+
64
103
// "E5:12:D8:E5:69:97"
65
- // console.log('mac', mac);
104
+ console . log ( 'mac' , mac ) ;
66
105
var payload = {
67
106
AppID : 'android' ,
68
107
MacAddress : mac ,
@@ -71,15 +110,17 @@ class HomeScreen extends Component<Props> {
71
110
PASS : this . state . password ,
72
111
} ;
73
112
var thisobj = this ;
74
- fetch ( 'https://mdev.humaxdigital.com/HumaxMobile/NonAuth/Login.aspx?AppID=Mobile&MacAddress=' + mac + '&DeviceName=' + appName + '&ID=' + this . state . username + '&PASS=' + this . state . password , {
75
- headers : {
76
- 'Accept' :'application/json'
77
- } ,
78
- } ) . then ( async function ( responseData ) {
113
+ // fetch('https://mdev.humaxdigital.com/HumaxMobile/NonAuth/Login.aspx?AppID=Mobile&MacAddress='+mac+'&DeviceName='+appName+'&ID='+this.state.username+'&PASS='+this.state.password,{
114
+ // headers: {
115
+ // 'Accept':'application/json'
116
+ // },
117
+ // })
118
+ axios . get ( 'https://mdev.humaxdigital.com/HumaxMobile/NonAuth/Login.aspx?AppID=Mobile&MacAddress=' + mac + '&DeviceName=' + appName + '&ID=' + this . state . username + '&PASS=' + this . state . password )
119
+ . then ( async function ( responseData ) {
79
120
80
- var token = responseData . _bodyInit . _data . blobId ;
121
+ var token = responseData . data ;
81
122
let fcmToken = await AsyncStorage . getItem ( 'fcmToken' ) ;
82
- console . log ( "first hit" ) ;
123
+ console . log ( "guid" , token ) ;
83
124
const path = '/production' ;
84
125
const url = 'https://5q6xg017b6.execute-api.us-east-1.amazonaws.com' + path ;
85
126
const credentials = {
@@ -119,59 +160,60 @@ class HomeScreen extends Component<Props> {
119
160
method : 'POST' ,
120
161
headers : auth_header ,
121
162
body : JSON . stringify ( {
163
+ "username" : thisobj . state . username ,
122
164
"tokenID" : fcmToken ,
123
165
"guid" : token ,
124
- "deviceType" : "android"
166
+ "deviceType" : "android" ,
167
+ "deviceModel" : appName ,
168
+ "macAddress" : mac
169
+
125
170
} )
126
171
} ) ;
172
+
127
173
//const url = 'https://' + '5q6xg017b6.execute-api.us-east-1.amazonaws.com/production';
128
-
174
+ console . log ( options ) ;
129
175
fetch ( url , options ) . then ( async function ( resp ) {
130
176
console . log ( "second hit" ) ;
131
177
const responseData = await resp . json ( ) ;
132
- await AsyncStorage . setItem ( 'loginToken' , "1" ) ;
178
+
133
179
await thisobj . setState ( { loginStatus : true } ) ;
134
- thisobj . props . navigation . navigate ( 'List' ) ;
180
+ //let resObj = JSON.stringify(responseData );
135
181
//console.log("AWS "+ JSON.stringify(responseData));
182
+ console . log ( responseData . body ) ;
183
+ if ( responseData . body == 'Success' ) {
184
+ console . log ( 'for setting instorage' , token ) ;
185
+ await AsyncStorage . setItem ( 'loginToken' , token ) ;
186
+ var getting = await AsyncStorage . getItem ( 'loginToken' ) ;
187
+ console . log ( 'from loacl storage' , getting ) ;
188
+ thisobj . props . navigation . navigate ( 'List' ) ;
189
+ }
136
190
137
191
} )
138
192
//code end
139
193
}
140
194
141
- // res => {
142
- // var token = res._bodyInit._data.blobId;
143
- // let fcmToken = AsyncStorage.getItem('fcmToken');
144
- // // console.log('uid response', token);
145
- // var awspayload = {
146
- // tokenID: fcmToken,
147
- // guid: token,
148
- // deviceType: 'android'
149
- // };
150
- // //fetch('https://5q6xg017b6.execute-api.us-east-1.amazonaws.com/production')
195
+
151
196
152
- // }
197
+
153
198
)
154
- // console.log('paylod', payload);
155
- } ) ;
156
199
157
- // console.log('device name', dname );
200
+ } ) ;
158
201
159
- // console.log('app name', appName);
160
- //const userToken = await AsyncStorage.getItem('userToken');
202
+
161
203
162
204
} ;
163
205
//On click of login btn
164
206
onLogin ( ) {
165
207
if ( this . validate ( ) ) {
166
208
const { username, password } = this . state ;
167
209
this . _bootstrapAsync ( ) ;
168
- // this.registerForPushNotificationsAsync();
169
- // Alert.alert('Credentials', `${username} + ${password}`);
170
210
}
171
211
else {
172
212
Alert . alert ( 'Both fields are required' ) ;
173
213
}
174
214
}
215
+
216
+
175
217
//Validate input field
176
218
validate ( ) {
177
219
const { username, password } = this . state ;
@@ -182,18 +224,23 @@ validate() {
182
224
return true ;
183
225
}
184
226
}
185
- async componentDidMount ( ) {
227
+ async componentDidMount ( ) {
228
+
186
229
this . checkLogin ( ) ;
187
230
this . checkPermission ( ) ;
188
231
this . createNotificationListeners ( ) ;
189
- }
232
+
233
+
234
+ }
190
235
191
236
////////////////////// Add these methods //////////////////////
192
237
193
238
//Remove listeners allocated in createNotificationListeners()
194
239
componentWillUnmount ( ) {
240
+
195
241
this . notificationListener ( ) ;
196
242
this . notificationOpenedListener ( ) ;
243
+
197
244
}
198
245
199
246
async createNotificationListeners ( ) {
@@ -286,13 +333,15 @@ showAlert(title, body) {
286
333
async checkLogin ( ) {
287
334
let loginToken = await AsyncStorage . getItem ( 'loginToken' ) ;
288
335
if ( loginToken ) {
336
+ this . validateGuid ( ) ;
289
337
this . setState ( { loginStatus : true } ) ;
290
338
}
291
339
else {
292
340
this . setState ( { loginStatus : false } ) ;
293
341
}
294
342
}
295
343
render ( ) {
344
+ const { loader} = this . state ;
296
345
return (
297
346
< View style = { styles . main } >
298
347
< Text style = { styles . heading } >
@@ -318,7 +367,7 @@ showAlert(title, body) {
318
367
onPress = { this . onLogin . bind ( this ) }
319
368
/>
320
369
</ View >
321
-
370
+ { loader && < Loader /> }
322
371
</ View >
323
372
</ View >
324
373
) ;
@@ -380,8 +429,8 @@ const styles = StyleSheet.create({
380
429
// marginBottom: 5,
381
430
// },
382
431
// });
383
- const ListStack = createStackNavigator ( { List : ListScreen } ) ;
384
- const AppStack = createStackNavigator ( { Home : HomeScreen } )
432
+ const ListStack = createStackNavigator ( { List : ListScreen , UrlPage : WebviewScreen } ) ;
433
+ const AppStack = createStackNavigator ( { Home : HomeScreen } ) ;
385
434
// const AuthStack = createStackNavigator({ SignIn: SignInScreen });
386
435
387
436
export default createAppContainer ( createSwitchNavigator (
0 commit comments