App.vue 2.0 KB

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