Advertisement
Guest User

Untitled

a guest
May 19th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. export default class Login extends Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. email : '',
  6. password : '',
  7. loading : false,
  8. };
  9. this.LoginUser = this.LoginUser.bind(this);
  10.  
  11. }
  12.  
  13.  
  14. //for login\\\
  15. LoginUser = () =>{
  16. this.setState({
  17. loading: true
  18. });
  19. if (this.state.email == "") {
  20. ToastAndroid.show('nama Tidak Boleh Kosong', ToastAndroid.SHORT)
  21. } else if (this.state.password == "") {
  22. ToastAndroid.show('Password Tidak Boleh Kosong', ToastAndroid.SHORT)
  23. } else {
  24. this.setState({
  25. loading: false
  26. })
  27. axios({
  28. method: 'POST',
  29. url: 'http://192.168.214.2/Auth/user',
  30. // headers:{
  31. // Authorization : 'Bearer' + token
  32. // },
  33. data: {
  34. email : this.state.email,
  35. password : this.state.password
  36. },
  37. })
  38. .then(response => {
  39. if (response == 'Try Again') {
  40. ToastAndroid.show('Try Again, the input is empty', ToastAndroid.SHORT)
  41. } else {
  42. ToastAndroid.show('sukses', ToastAndroid.SHORT)
  43. this.props.navigation.dispatch(resetAction)
  44. // this.props.navigation.dispatch(goHome)
  45. // console.log(navigateAction)
  46. }
  47. })
  48. .catch((error) => {
  49. console.log(error)
  50. this.onLoginFail();
  51. });
  52. Keyboard.dismiss()
  53. }
  54. }
  55.  
  56. onLoginFail() {
  57. this.setState({
  58. loading: false
  59. });
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement