App.vue 2.9 KB

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