App.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div>
  3. <router-view></router-view>
  4. <what-is-new></what-is-new>
  5. </div>
  6. </template>
  7. <script>
  8. import WhatIsNew from './components/WhatIsNew.vue';
  9. export default {
  10. replace: false,
  11. data() {
  12. return {
  13. register: {
  14. email: "",
  15. username: "",
  16. password: ""
  17. },
  18. login: {
  19. email: "",
  20. password: ""
  21. },
  22. loggedIn: false
  23. }
  24. },
  25. methods: {
  26. logout: function () {
  27. this.socket.emit('users.logout');
  28. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  29. location.reload();
  30. }
  31. },
  32. ready() {
  33. let _this = this;
  34. lofig.folder = '../config/default.json';
  35. lofig.get('socket.url', function(res) {
  36. let socket = _this.socket = io(window.location.protocol + '//' + res);
  37. socket.on("ready", status => _this.loggedIn = status);
  38. });
  39. },
  40. events: {
  41. 'register': function () {
  42. let { register: { email, username, password } } = this;
  43. this.socket.emit('users.register', email, username, password, grecaptcha.getResponse(), (result) => {
  44. // Need to somehow execute this on Home.vue
  45. // Toast.methods.addToast(`User ${username} has been registered`, 2000);
  46. setTimeout(location.reload(), 2500);
  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. let mergedStations = this.stations.community.concat(this.stations.official);
  65. this.socket.emit('stations.join', id, result => {
  66. mergedStations.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. components: { WhatIsNew }
  76. }
  77. </script>