App.vue 3.5 KB

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