App.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div>
  3. <router-view></router-view>
  4. <toast></toast>
  5. <what-is-new></what-is-new>
  6. </div>
  7. </template>
  8. <script>
  9. import { Toast } from 'vue-roaster';
  10. import WhatIsNew from './components/Modals/WhatIsNew.vue';
  11. export default {
  12. replace: false,
  13. data() {
  14. return {
  15. register: {
  16. email: "",
  17. username: "",
  18. password: ""
  19. },
  20. login: {
  21. email: "",
  22. password: ""
  23. },
  24. loggedIn: false
  25. }
  26. },
  27. methods: {
  28. logout: function () {
  29. this.socket.emit('users.logout');
  30. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  31. location.reload();
  32. }
  33. },
  34. ready() {
  35. let _this = this;
  36. lofig.folder = '../config/default.json';
  37. lofig.get('socket.url', function(res) {
  38. let socket = _this.socket = io(window.location.protocol + '//' + res);
  39. socket.on("ready", status => _this.loggedIn = status);
  40. });
  41. },
  42. events: {
  43. 'register': function () {
  44. let { register: { email, username, password } } = this;
  45. this.socket.emit('users.register', username, email, password, grecaptcha.getResponse(), (result) => {
  46. // Need to somehow execute this on Home.vue
  47. // Toast.methods.addToast(`User ${username} has been registered`, 2000);
  48. setTimeout(location.reload(), 2500);
  49. });
  50. },
  51. 'login': function () {
  52. let { login: { email, password } } = this;
  53. this.socket.emit('users.login', email, password, (result) => {
  54. console.log(result);
  55. if (result.status === 'success') {
  56. let date = new Date();
  57. date.setTime(new Date().getTime() + (2*365*24*60*60*1000));
  58. document.cookie = "SID=" + result.sessionId + "; expires="+ date.toGMTString() +"; path=/";
  59. location.reload();
  60. } else {
  61. //TODO Error toast
  62. }
  63. });
  64. }
  65. /*'joinStation': function (id) {
  66. let mergedStations = this.stations.community.concat(this.stations.official);
  67. this.socket.emit('stations.join', id, result => {
  68. mergedStations.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. components: { Toast, WhatIsNew }
  78. }
  79. </script>