Guest User

Untitled

a guest
Jun 23rd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <template lang="pug">
  2. .container
  3. h1 {{msg}}
  4. pre {{token}}
  5. pre {{user}}
  6. .row
  7. .col-sm-6
  8. .form
  9. .form-group
  10. input.form-control(v-model="user.username")
  11. .form-group
  12. input.form-control(type="password" v-model="user.password")
  13. .form-group
  14. .btn.btn-success(@click="login") Click
  15. .form-group
  16. .btn.btn-primary(@click="check") Check
  17.  
  18. .col-sm-6
  19. form(methods="POST" action="/login")
  20. .form-group
  21. input.form-control(v-model="user.username" name="username")
  22. .form-group
  23. input.form-control(type="password" v-model="user.password" name="password")
  24. .form-group
  25. input(type="submit")
  26. </template>
  27.  
  28. <script>
  29. import axios from 'axios'
  30.  
  31. export default {
  32. name: 'app',
  33. data () {
  34. return {
  35. msg: 'Welcome to Your Vue.js App',
  36. user: {
  37. username: '',
  38. password: ''
  39. },
  40. currentUser: {},
  41. token: ''
  42. }
  43. },
  44. methods: {
  45. login () {
  46. console.log('loging....')
  47. console.log(this.user.username, this.user.password)
  48. axios.post('/login', {
  49. username: this.user.username,
  50. password: this.user.password,
  51. }).then(res => {
  52. this.token = res.data.token,
  53. this.currentUser = res.data.user
  54. console.log(res.data)
  55. }, err => {
  56. console.err(err)
  57. })
  58. },
  59. check () {
  60. let getCookie = (name) => {
  61. var matches = document.cookie.match(new RegExp(
  62. "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  63. ));
  64. return matches ? decodeURIComponent(matches[1]) : undefined;
  65. }
  66. let token = getCookie('token')
  67. if (token) {
  68. axios.get('/dashboard', {
  69. headers: {
  70. id: token
  71. }
  72. }).then(res => {
  73. console.log('eeeeeeeeeeeee', true)
  74. console.log(res.headers)
  75. return true
  76. }, err => {
  77. return false
  78. console.err(err)
  79. })
  80. } else {
  81. console.log(false)
  82. }
  83. }
  84. }
  85. }
  86. </script>
Add Comment
Please, Sign In to add comment