App.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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: false,
  23. stations: []
  24. }
  25. },
  26. methods: {
  27. logout() {
  28. this.socket.emit('users.logout');
  29. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  30. location.reload();
  31. }
  32. },
  33. ready: function () {
  34. lofig.get('socket.url', res => {
  35. let socket = this.socket = io(window.location.protocol + '//' + res);
  36. socket.on("ready", status => this.loggedIn = status);
  37. socket.emit("stations.index", data => {
  38. if (data.status === "success") this.stations = data.stations;
  39. });
  40. });
  41. },
  42. events: {
  43. 'register': function () {
  44. let { register: { email, username, password } } = this;
  45. this.socket.emit('users.register', email, username, password, grecaptcha.getResponse(), (result) => {
  46. console.log(result);
  47. location.reload();
  48. });
  49. },
  50. 'login': function () {
  51. let { login: { email, password } } = this;
  52. this.socket.emit('users.login', email, password, (result) => {
  53. console.log(result);
  54. if (result.status === 'success') {
  55. let date = new Date();
  56. date.setTime(new Date().getTime() + (2*365*24*60*60*1000));
  57. document.cookie = "SID=" + result.sessionId + "; expires="+ date.toGMTString() +"; path=/";
  58. location.reload();
  59. } else {
  60. //TODO Error toast
  61. }
  62. });
  63. },
  64. 'joinStation': function (id) {
  65. this.socket.emit('stations.join', id, (result) => {
  66. this.stations.find(station => station.id === id).users = result.userCount;
  67. });
  68. },
  69. 'leaveStation': function () {
  70. this.socket.emit('stations.leave', (result) => {
  71. //this.stations.find(station => station.id === id).users = result.userCount;
  72. });
  73. }
  74. }
  75. }
  76. </script>