App.vue 3.4 KB

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