App.vue 2.9 KB

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