Guest User

Untitled

a guest
Mar 16th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. chat-api$ http :3000/signup username=juan password=123
  2. HTTP/1.1 201 Created
  3. Cache-Control: max-age=0, private, must-revalidate
  4. Content-Type: application/json; charset=utf-8
  5. ETag: W/"01dfe24bd7415e252b5aee50e12198a3"
  6. Transfer-Encoding: chunked
  7. Vary: Origin
  8. X-Request-Id: a095148b-592a-4347-820f-63e1efa0e409
  9. X-Runtime: 0.347726
  10.  
  11. {
  12. "auth_token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJleHAiOjE1MjEzMTg4NDV9.45JDA7vk-K8gUzCB1xABKMifi-IWGoVESedKykGiqGo",
  13. "message": "Account created successfully"
  14. }
  15.  
  16. import axios from 'axios'
  17. const API_URL = process.env.API_URL || 'http://localhost:3000/'
  18.  
  19. export default axios.create({
  20. baseURL: API_URL,
  21. headers: {
  22. 'Content-Type': 'application/json',
  23. 'Authorization': 'Bearer ' + localStorage.auth_token
  24. }
  25. })
  26.  
  27. Access-Control-Allow-Methods:GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD
  28. Access-Control-Allow-Origin:http://localhost:8081
  29. Access-Control-Expose-Headers:
  30. Access-Control-Max-Age:1728000
  31. Cache-Control:max-age=0, private, must-revalidate
  32. Content-Type:application/json; charset=utf-8
  33. ETag:W/"fdac439f3ada9e343d0815bb49dff277"
  34. Transfer-Encoding:chunked
  35. Vary:Origin
  36. X-Request-Id:9e318050-ceca-480c-a847-d59f9ebb18b7
  37. X-Runtime:0.447976
  38.  
  39. Accept:application/json, text/plain, */*
  40. Accept-Encoding:gzip, deflate, br
  41. Accept-Language:en-US,en;q=0.9
  42. Authorization:Bearer undefined
  43. Connection:keep-alive
  44. Content-Length:44
  45. Content-Type:application/json
  46. Host:localhost:3000
  47. Origin:http://localhost:8081
  48. Referer:http://localhost:8081/
  49. User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.
  50.  
  51. {username: "tomatito", password: "123456"}
  52. password:"123456"username:"tomatito"
  53.  
  54. <script>
  55. export default {
  56. name: 'SignUp',
  57. data () {
  58. return {
  59. username: '',
  60. password: '',
  61. error: false
  62. }
  63. },
  64. methods: {
  65. signup () {
  66. this.$http.post('/signup', { username: this.username, password: this.password })
  67. .then(request => this.signupSuccessful(request))
  68. .catch(() => this.signupFailed())
  69. },
  70. signupSuccessful (req) {
  71. if (!req.data.token) {
  72. this.signupFailed()
  73. return
  74. }
  75. localStorage.token = req.data.token
  76. this.error = false
  77. this.$router.replace(this.$route.query.redirect || '/rooms')
  78. },
  79. signupFailed () {
  80. this.error = 'Sign up failed!'
  81. delete localStorage.token
  82. }
  83. }
  84. }
  85. </script>
Add Comment
Please, Sign In to add comment