App.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div>
  3. <router-view></router-view>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. replace: false,
  9. data() {
  10. return {
  11. register: {
  12. email: "",
  13. username: "",
  14. password: ""
  15. },
  16. login: {
  17. email: "",
  18. password: ""
  19. },
  20. likes: [],
  21. dislikes: [],
  22. loggedIn: true,
  23. stations: []
  24. }
  25. },
  26. methods: {
  27. logout() {
  28. $.ajax({
  29. method: "POST",
  30. url: "/users/logout",
  31. dataType: "json",
  32. complete: msg => {
  33. alert("Logged out!");
  34. location.reload();
  35. }
  36. });
  37. }
  38. },
  39. ready: function() {
  40. let local = this;
  41. local.socket = io();
  42. local.socket.on("ready", status => {
  43. local.loggedIn = status;
  44. });
  45. $.ajax({
  46. method: "POST",
  47. url: "/stations",
  48. contentType: "application/json; charset=utf-8",
  49. success: stations => {
  50. if (stations) this.stations = stations;
  51. },
  52. error: err => {
  53. if (err) console.log(err);
  54. }
  55. });
  56. },
  57. events: {
  58. 'register': function() {
  59. $.ajax({
  60. method: "POST",
  61. url: "/users/register",
  62. data: JSON.stringify({
  63. email: this.register.email,
  64. username: this.register.username,
  65. password: this.register.password,
  66. recaptcha: grecaptcha.getResponse()
  67. }),
  68. contentType: "application/json; charset=utf-8",
  69. dataType: "json",
  70. success: function (msg) {
  71. if (msg) console.log(msg);
  72. },
  73. error: function (err) {
  74. if (err) console.log(err);
  75. alert("Not registered!");
  76. }
  77. });
  78. },
  79. 'login': function() {
  80. $.ajax({
  81. method: "POST",
  82. url: "/users/login",
  83. data: JSON.stringify({
  84. email: this.login.email,
  85. password: this.login.password
  86. }),
  87. contentType: "application/json; charset=utf-8",
  88. dataType: "json",
  89. success: function (msg) {
  90. if (msg) console.log(msg);
  91. location.reload();
  92. //do something
  93. },
  94. error: function (err) {
  95. if (err) console.log(err);
  96. alert("Not logged in!");
  97. }
  98. });
  99. },
  100. 'joinStation': id => {
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="sass" scoped>
  106. #toasts {
  107. position: fixed;
  108. z-index: 100000;
  109. right: 5%;
  110. top: 10%;
  111. max-width: 90%;
  112. .toast {
  113. width: 100%;
  114. height: auto;
  115. padding: 10px 20px;
  116. border-radius: 3px;
  117. color: white;
  118. background-color: #424242;
  119. display: -webkit-flex;
  120. display: -ms-flexbox;
  121. display: flex;
  122. margin-bottom: 10px;
  123. font-size: 1.18em;
  124. font-weight: 400;
  125. box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16), 0 2px 10px 0 rgba(0,0,0,0.12);
  126. transition: all 0.25s ease;
  127. }
  128. .toast-remove {
  129. opacity: 0;
  130. margin-top: -50px;
  131. }
  132. .toast-add {
  133. opacity: 0;
  134. margin-top: 50px;
  135. }
  136. }
  137. </style>