Guest User

Untitled

a guest
Jul 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. handleSubmit(context) {
  2. let json = {
  3. username: this.state.username,
  4. password: this.state.password,
  5. }
  6. json = JSON.stringify(json)
  7. fetch(`/api/auth/token/`, {
  8. method: 'POST',
  9. headers: {
  10. 'Accept': 'application/json',
  11. 'Content-Type': 'application/json'
  12. },
  13. body: json,
  14. })
  15. .then(response => response.json())
  16. .then(response => this.loginSuccess(context, response))
  17. }
  18.  
  19. loginSuccess(context, response) {
  20. console.log('Login Success!')
  21. context.toggleLoginModal()
  22. context.toggleLoggedIn()
  23. context.setUsername(response.profile_username)
  24. context.setUserId(response.profile_id)
  25. }
  26.  
  27. .then(response => response.json())
  28. .then(response => this.loginSuccess(context, response))
  29.  
  30. .then(response => {
  31. response.status >= 200 && response.status < 300 ?
  32. this.loginSuccess(context, response.json())
  33. :
  34. console.log(response)
  35. })
Add Comment
Please, Sign In to add comment