App.vue 2.8 KB

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