App.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.get('socket.url', function(res) {
  35. let socket = _this.socket = io(window.location.protocol + '//' + res);
  36. socket.on("ready", status => _this.loggedIn = status);
  37. socket.on("SomeRoomMessage", function() {
  38. console.log("SOME ROOM MESSAGE!");
  39. });
  40. });
  41. },
  42. events: {
  43. 'register': function () {
  44. let { register: { email, username, password } } = this;
  45. this.socket.emit('users.register', email, username, 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: { WhatIsNew }
  78. }
  79. </script>