App.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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');
  36. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  37. location.reload();
  38. }
  39. },
  40. ready() {
  41. let _this = this;
  42. lofig.folder = '../config/default.json';
  43. lofig.get('socket.url', function(res) {
  44. let socket = _this.socket = io(window.location.protocol + '//' + res);
  45. socket.on("ready", status => _this.loggedIn = status);
  46. });
  47. },
  48. events: {
  49. 'register': function () {
  50. let { register: { email, username, password } } = this;
  51. this.socket.emit('users.register', username, email, password, grecaptcha.getResponse(), result => {
  52. Toast.methods.addToast(`User ${username} has been registered`, 2000);
  53. setTimeout(location.reload(), 2500);
  54. });
  55. },
  56. 'login': function () {
  57. let { login: { email, password } } = this;
  58. this.socket.emit('users.login', email, password, result => {
  59. console.log(result);
  60. if (result.status === 'success') {
  61. let date = new Date();
  62. date.setTime(new Date().getTime() + (2*365*24*60*60*1000));
  63. document.cookie = "SID=" + result.SID + "; expires="+ date.toGMTString() +"; path=/";
  64. Toast.methods.addToast(`You have been successfully logged in`, 2000);
  65. setTimeout(location.reload(), 2500);
  66. } else {
  67. Toast.methods.addToast(result.message, 2000);
  68. }
  69. });
  70. },
  71. 'toggleModal': function (type) {
  72. switch(type) {
  73. case 'register':
  74. this.isRegisterActive = !this.isRegisterActive;
  75. break;
  76. case 'login':
  77. this.isLoginActive = !this.isLoginActive;
  78. break;
  79. }
  80. }
  81. /*'joinStation': function (id) {
  82. let mergedStations = this.stations.community.concat(this.stations.official);
  83. this.socket.emit('stations.join', id, result => {
  84. mergedStations.find(station => station.id === id).users = result.userCount;
  85. });
  86. },
  87. 'leaveStation': function () {
  88. this.socket.emit('stations.leave', result => {
  89. //this.stations.find(station => station.id === id).users = result.userCount;
  90. });
  91. }*/
  92. },
  93. components: { Toast, WhatIsNew, LoginModal, RegisterModal }
  94. }
  95. </script>