App.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. userId: '',
  40. isRegisterActive: false,
  41. isLoginActive: false,
  42. isCCSActive: false,
  43. serverDomain: ''
  44. }
  45. },
  46. methods: {
  47. logout: function () {
  48. this.socket.emit('users.logout', result => {
  49. if (result.status === 'success') {
  50. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  51. location.reload();
  52. } else Toast.methods.addToast(result.message, 4000);
  53. });
  54. },
  55. 'submitOnEnter': (cb, event) => {
  56. if (event.which == 13) b(); return false;
  57. }
  58. },
  59. ready() {
  60. let _this = this;
  61. auth.getStatus((authenticated, role, username, userId) => {
  62. _this.socket = window.socket;
  63. _this.loggedIn = authenticated;
  64. _this.role = role;
  65. _this.username = username;
  66. _this.userId = userId;
  67. });
  68. lofig.get('serverDomain', res => {
  69. _this.serverDomain = res;
  70. });
  71. },
  72. events: {
  73. 'register': function () {
  74. let { register: { email, username, password } } = this;
  75. let _this = this;
  76. this.socket.emit('users.register', username, email, password, /*grecaptcha.getResponse()*/null, result => {
  77. Toast.methods.addToast(`You have successfully registered.`, 4000);
  78. setTimeout(() => {
  79. if (result.SID) {
  80. let date = new Date();
  81. date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
  82. document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
  83. location.reload();
  84. } else {
  85. _this.$router.go('/login');
  86. }
  87. }, 4000);
  88. });
  89. },
  90. 'login': function () {
  91. let { login: { email, password } } = this;
  92. let _this = this;
  93. this.socket.emit('users.login', email, password, result => {
  94. if (result.status === 'success') {
  95. let date = new Date();
  96. date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
  97. document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
  98. Toast.methods.addToast(`You have been successfully logged in`, 2000);
  99. _this.$router.go('/');
  100. location.reload();
  101. } else {
  102. Toast.methods.addToast(result.message, 2000);
  103. }
  104. });
  105. },
  106. 'ccs': function () {
  107. let _this = this;
  108. this.socket.emit('stations.createCommunity', {_id: _this.ccs.name, displayName: _this.ccs.displayName, description: _this.ccs.description}, result => {
  109. if (result.status === 'success') {
  110. Toast.methods.addToast(`You have added the station successfully`, 4000);
  111. } else {
  112. Toast.methods.addToast(result.message, 4000);
  113. }
  114. });
  115. },
  116. 'toggleModal': function (type) {
  117. switch(type) {
  118. case 'register':
  119. this.isRegisterActive = !this.isRegisterActive;
  120. break;
  121. case 'login':
  122. this.isLoginActive = !this.isLoginActive;
  123. break;
  124. case 'ccs':
  125. this.isCCSActive = !this.isCCSActive;
  126. break;
  127. }
  128. }
  129. },
  130. components: { Toast, WhatIsNew, LoginModal, RegisterModal, CreateCommunityStation }
  131. }
  132. </script>