App.vue 1.9 KB

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