App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. import auth from './auth';
  16. export default {
  17. replace: false,
  18. data() {
  19. return {
  20. register: {
  21. email: "",
  22. username: "",
  23. password: ""
  24. },
  25. login: {
  26. email: "",
  27. password: ""
  28. },
  29. loggedIn: false,
  30. role: '',
  31. username: '',
  32. isRegisterActive: false,
  33. isLoginActive: false
  34. }
  35. },
  36. methods: {
  37. logout: function () {
  38. this.socket.emit('users.logout', (result) => {
  39. if (result.status === 'success') {
  40. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  41. location.reload();
  42. } else {
  43. Toast.methods.addToast(result.message, 4000);
  44. }
  45. });
  46. }
  47. },
  48. ready() {
  49. let _this = this;
  50. auth.getStatus((authenticated, role, username) => {
  51. _this.socket = window.socket;
  52. _this.loggedIn = authenticated;
  53. _this.role = role;
  54. _this.username = username;
  55. });
  56. },
  57. events: {
  58. 'register': function () {
  59. let { register: { email, username, password } } = this;
  60. let _this = this;
  61. this.socket.emit('users.register', username, email, password, /*grecaptcha.getResponse()*/null, result => {
  62. Toast.methods.addToast(`User ${username} has been registered`, 2000);
  63. _this.$router.go('/');
  64. location.reload();
  65. });
  66. },
  67. 'login': function () {
  68. let { login: { email, password } } = this;
  69. let _this = this;
  70. this.socket.emit('users.login', email, password, result => {
  71. if (result.status === 'success') {
  72. let date = new Date();
  73. date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
  74. document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
  75. Toast.methods.addToast(`You have been successfully logged in`, 2000);
  76. _this.$router.go('/');
  77. location.reload();
  78. } else {
  79. Toast.methods.addToast(result.message, 2000);
  80. }
  81. });
  82. },
  83. 'toggleModal': function (type) {
  84. switch(type) {
  85. case 'register':
  86. this.isRegisterActive = !this.isRegisterActive;
  87. break;
  88. case 'login':
  89. this.isLoginActive = !this.isLoginActive;
  90. break;
  91. }
  92. }
  93. /*'joinStation': function (id) {
  94. let mergedStations = this.stations.community.concat(this.stations.official);
  95. this.socket.emit('stations.join', id, result => {
  96. mergedStations.find(station => station.id === id).users = result.userCount;
  97. });
  98. },
  99. 'leaveStation': function () {
  100. this.socket.emit('stations.leave', result => {
  101. //this.stations.find(station => station.id === id).users = result.userCount;
  102. });
  103. }*/
  104. },
  105. components: { Toast, WhatIsNew, LoginModal, RegisterModal }
  106. }
  107. </script>