App.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. <create-community-station v-if='isCreateCommunityStationActive'></create-community-station>
  9. </div>
  10. </template>
  11. <script>
  12. import { Toast } from 'vue-roaster';
  13. import WhatIsNew from './components/Modals/WhatIsNew.vue';
  14. import LoginModal from './components/Modals/Login.vue';
  15. import RegisterModal from './components/Modals/Register.vue';
  16. import CreateCommunityStation from './components/Modals/CreateCommunityStation.vue';
  17. import auth from './auth';
  18. export default {
  19. replace: false,
  20. data() {
  21. return {
  22. register: {
  23. email: '',
  24. username: '',
  25. password: ''
  26. },
  27. login: {
  28. email: '',
  29. password: ''
  30. },
  31. loggedIn: false,
  32. role: '',
  33. username: '',
  34. userId: '',
  35. isRegisterActive: false,
  36. isLoginActive: false,
  37. isCreateCommunityStationActive: false,
  38. serverDomain: ''
  39. }
  40. },
  41. methods: {
  42. logout: function () {
  43. this.socket.emit('users.logout', result => {
  44. if (result.status === 'success') {
  45. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  46. location.reload();
  47. } else Toast.methods.addToast(result.message, 4000);
  48. });
  49. },
  50. 'submitOnEnter': (cb, event) => {
  51. if (event.which == 13) b(); return false;
  52. }
  53. },
  54. ready() {
  55. Toast.methods.addToast('Hiasd', 50000);
  56. Toast.methods.addToast('Hiasd', 50000);
  57. Toast.methods.addToast('Hiasd', 50000);
  58. let _this = this;
  59. auth.getStatus((authenticated, role, username, userId) => {
  60. _this.socket = window.socket;
  61. _this.loggedIn = authenticated;
  62. _this.role = role;
  63. _this.username = username;
  64. _this.userId = userId;
  65. });
  66. lofig.get('serverDomain', res => {
  67. _this.serverDomain = res;
  68. });
  69. },
  70. events: {
  71. 'register': function () {
  72. let { register: { email, username, password } } = this;
  73. let _this = this;
  74. this.socket.emit('users.register', username, email, password, /*grecaptcha.getResponse()*/null, result => {
  75. Toast.methods.addToast(`You have successfully registered.`, 4000);
  76. setTimeout(() => {
  77. if (result.SID) {
  78. let date = new Date();
  79. date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
  80. document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
  81. location.reload();
  82. } else {
  83. _this.$router.go('/login');
  84. }
  85. }, 4000);
  86. });
  87. },
  88. 'login': function () {
  89. let { login: { email, password } } = this;
  90. let _this = this;
  91. this.socket.emit('users.login', email, password, result => {
  92. if (result.status === 'success') {
  93. let date = new Date();
  94. date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
  95. document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
  96. Toast.methods.addToast(`You have been successfully logged in`, 2000);
  97. _this.$router.go('/');
  98. location.reload();
  99. } else {
  100. Toast.methods.addToast(result.message, 2000);
  101. }
  102. });
  103. },
  104. 'toggleModal': function (type) {
  105. switch(type) {
  106. case 'register':
  107. this.isRegisterActive = !this.isRegisterActive;
  108. break;
  109. case 'login':
  110. this.isLoginActive = !this.isLoginActive;
  111. break;
  112. case 'createCommunityStation':
  113. this.isCreateCommunityStationActive = !this.isCreateCommunityStationActive;
  114. break;
  115. }
  116. }
  117. },
  118. components: { Toast, WhatIsNew, LoginModal, RegisterModal, CreateCommunityStation }
  119. }
  120. </script>
  121. <style type='scss'>
  122. #toast-container { z-index: 10000 !important; }
  123. </style>