App.vue 1.9 KB

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