App.vue 3.4 KB

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