App.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div>
  3. <router-view></router-view>
  4. <toast></toast>
  5. <what-is-new></what-is-new>
  6. <login-modal v-if="isLoginActive"></login-modal>
  7. <register-modal v-if="isRegisterActive"></register-modal>
  8. </div>
  9. </template>
  10. <script>
  11. import { Toast } from 'vue-roaster';
  12. import WhatIsNew from './components/Modals/WhatIsNew.vue';
  13. import LoginModal from './components/Modals/Login.vue';
  14. import RegisterModal from './components/Modals/Register.vue';
  15. export default {
  16. replace: false,
  17. data() {
  18. return {
  19. register: {
  20. email: "",
  21. username: "",
  22. password: ""
  23. },
  24. login: {
  25. email: "",
  26. password: ""
  27. },
  28. loggedIn: false,
  29. isRegisterActive: false,
  30. isLoginActive: false
  31. }
  32. },
  33. methods: {
  34. logout: function () {
  35. this.socket.emit('users.logout', (result) => {
  36. if (result.status === 'success') {
  37. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  38. location.reload();
  39. } else {
  40. Toast.methods.addToast(result.message, 4000);
  41. }
  42. });
  43. }
  44. },
  45. ready() {
  46. let _this = this;
  47. lofig.folder = '../config/default.json';
  48. lofig.get('socket.url', function(res) {
  49. let socket = _this.socket = io(window.location.protocol + '//' + res);
  50. socket.on("ready", status => _this.loggedIn = status);
  51. });
  52. },
  53. events: {
  54. 'register': function () {
  55. let { register: { email, username, password } } = this;
  56. this.socket.emit('users.register', username, email, password, /*grecaptcha.getResponse()*/null, result => {
  57. Toast.methods.addToast(`User ${username} has been registered`, 2000);
  58. setTimeout(location.reload(), 2500);
  59. });
  60. },
  61. 'login': function () {
  62. let { login: { email, password } } = this;
  63. this.socket.emit('users.login', email, password, result => {
  64. console.log(result);
  65. if (result.status === 'success') {
  66. let date = new Date();
  67. date.setTime(new Date().getTime() + (2*365*24*60*60*1000));
  68. document.cookie = "SID=" + result.SID + "; expires="+ date.toGMTString() +"; path=/";
  69. Toast.methods.addToast(`You have been successfully logged in`, 2000);
  70. setTimeout(location.reload(), 2500);
  71. } else {
  72. Toast.methods.addToast(result.message, 2000);
  73. }
  74. });
  75. },
  76. 'toggleModal': function (type) {
  77. switch(type) {
  78. case 'register':
  79. this.isRegisterActive = !this.isRegisterActive;
  80. break;
  81. case 'login':
  82. this.isLoginActive = !this.isLoginActive;
  83. break;
  84. }
  85. }
  86. /*'joinStation': function (id) {
  87. let mergedStations = this.stations.community.concat(this.stations.official);
  88. this.socket.emit('stations.join', id, result => {
  89. mergedStations.find(station => station.id === id).users = result.userCount;
  90. });
  91. },
  92. 'leaveStation': function () {
  93. this.socket.emit('stations.leave', result => {
  94. //this.stations.find(station => station.id === id).users = result.userCount;
  95. });
  96. }*/
  97. },
  98. components: { Toast, WhatIsNew, LoginModal, RegisterModal }
  99. }
  100. </script>