App.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. });
  38. },
  39. events: {
  40. 'register': function () {
  41. let { register: { email, username, password } } = this;
  42. this.socket.emit('users.register', email, username, password, grecaptcha.getResponse(), (result) => {
  43. // Need to somehow execute this on Home.vue
  44. // Toast.methods.addToast(`User ${username} has been registered`, 2000);
  45. setTimeout(location.reload(), 2500);
  46. });
  47. },
  48. 'login': function () {
  49. let { login: { email, password } } = this;
  50. this.socket.emit('users.login', email, password, (result) => {
  51. console.log(result);
  52. if (result.status === 'success') {
  53. let date = new Date();
  54. date.setTime(new Date().getTime() + (2*365*24*60*60*1000));
  55. document.cookie = "SID=" + result.sessionId + "; expires="+ date.toGMTString() +"; path=/";
  56. location.reload();
  57. } else {
  58. //TODO Error toast
  59. }
  60. });
  61. }
  62. /*'joinStation': function (id) {
  63. let mergedStations = this.stations.community.concat(this.stations.official);
  64. this.socket.emit('stations.join', id, result => {
  65. mergedStations.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. components: { WhatIsNew }
  75. }
  76. </script>