Advertisement
Guest User

Untitled

a guest
May 21st, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. clearAndNavigate(screen) {
  2. this.props.navigation.dispatch(
  3. NavigationActions.reset({
  4. index: 0,
  5. actions: [
  6. NavigationActions.navigate({ routeName: screen })
  7. ]
  8. })
  9. );
  10. }
  11.  
  12. componentWillMount() {
  13. this.CheckUserLogin()
  14. }
  15.  
  16. async CheckUserLogin() {
  17. let user = await AsyncStorage.getItem('dataLogin')
  18. if (user !== null) {
  19. console.log(user)
  20. this.clearAndNavigate('Home')
  21. } else {
  22. this.setState({
  23. isLoading: false
  24. })
  25. }
  26. }
  27.  
  28. //for login\\\
  29. LoginUser = () =>{
  30. if (this.state.email == "") {
  31. ToastAndroid.show('Email can not be empty', ToastAndroid.SHORT)
  32. } else if (this.state.password == "") {
  33. ToastAndroid.show('Password can not be empty', ToastAndroid.SHORT)
  34. } else {
  35. this.setState({
  36. loading: false
  37. })
  38. axios({
  39. method: 'POST',
  40. url: 'http://192.168.214.2/Auth/user',
  41. data: {
  42. email : this.state.email,
  43. password : this.state.password
  44. },
  45. }).then(response => {
  46. if (response.data.status) {
  47. ToastAndroid.show('Welcome', ToastAndroid.SHORT)
  48. // this.storageAsyncStorage(response.data)
  49. // this.clearAndNavigate('Home')
  50. AsyncStorage.setItem('dataLogin', JSON.stringify(response.data))
  51. console.log(response.data);
  52. }else{
  53. ToastAndroid.show('Email Atau Password salah', ToastAndroid.SHORT)
  54. ToastAndroid.showWithGravityAndOffset('Please check your username and password',
  55. ToastAndroid.LONG, ToastAndroid.CENTER, 25, 50 );
  56. console.log(response.data);
  57. // ToastAndroid.show('sukses', ToastAndroid.SHORT)
  58. }
  59. }).catch(err => {
  60. this.setState({
  61. loading : false
  62. })
  63. })
  64. Keyboard.dismiss()
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement