App.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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='isCCSActive'></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. ccs: {
  32. name: '',
  33. displayName: '',
  34. description: ''
  35. },
  36. loggedIn: false,
  37. role: '',
  38. username: '',
  39. isRegisterActive: false,
  40. isLoginActive: false,
  41. isCCSActive: false,
  42. serverDomain: ''
  43. }
  44. },
  45. methods: {
  46. logout: function () {
  47. this.socket.emit('users.logout', result => {
  48. if (result.status === 'success') {
  49. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  50. location.reload();
  51. } else Toast.methods.addToast(result.message, 4000);
  52. });
  53. },
  54. 'submitOnEnter': (cb, event) => {
  55. if (event.which == 13) b(); return false;
  56. },
  57. },
  58. ready() {
  59. let _this = this;
  60. auth.getStatus((authenticated, role, username) => {
  61. _this.socket = window.socket;
  62. _this.loggedIn = authenticated;
  63. _this.role = role;
  64. _this.username = username;
  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. 'ccs': function () {
  105. let _this = this;
  106. this.socket.emit('stations.createCommunity', {_id: _this.ccs.name, displayName: _this.ccs.displayName, description: _this.ccs.description}, result => {
  107. if (result.status === 'success') {
  108. Toast.methods.addToast(`You have added the station successfully`, 4000);
  109. } else {
  110. Toast.methods.addToast(result.message, 4000);
  111. }
  112. });
  113. },
  114. 'toggleModal': function (type) {
  115. switch(type) {
  116. case 'register':
  117. this.isRegisterActive = !this.isRegisterActive;
  118. break;
  119. case 'login':
  120. this.isLoginActive = !this.isLoginActive;
  121. break;
  122. case 'ccs':
  123. this.isCCSActive = !this.isCCSActive;
  124. break;
  125. }
  126. }
  127. /*'joinStation': function (id) {
  128. let mergedStations = this.stations.community.concat(this.stations.official);
  129. this.socket.emit('stations.join', id, result => {
  130. mergedStations.find(station => station.id === id).users = result.userCount;
  131. });
  132. },
  133. 'leaveStation': function () {
  134. this.socket.emit('stations.leave', result => {
  135. //this.stations.find(station => station.id === id).users = result.userCount;
  136. });
  137. }*/
  138. },
  139. components: { Toast, WhatIsNew, LoginModal, RegisterModal, CreateCommunityStation }
  140. }
  141. </script>