App.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div>
  3. <h1 v-if="!socketConnected" class="socketNotConnected">Could not connect to the server.</h1>
  4. <router-view></router-view>
  5. <toast></toast>
  6. <what-is-new></what-is-new>
  7. <login-modal v-if='isLoginActive'></login-modal>
  8. <register-modal v-if='isRegisterActive'></register-modal>
  9. <create-community-station v-if='isCreateCommunityStationActive'></create-community-station>
  10. </div>
  11. </template>
  12. <script>
  13. import { Toast } from 'vue-roaster';
  14. import WhatIsNew from './components/Modals/WhatIsNew.vue';
  15. import LoginModal from './components/Modals/Login.vue';
  16. import RegisterModal from './components/Modals/Register.vue';
  17. import CreateCommunityStation from './components/Modals/CreateCommunityStation.vue';
  18. import auth from './auth';
  19. import io from './io';
  20. export default {
  21. replace: false,
  22. data() {
  23. return {
  24. register: {
  25. email: '',
  26. username: '',
  27. password: ''
  28. },
  29. login: {
  30. email: '',
  31. password: ''
  32. },
  33. loggedIn: false,
  34. role: '',
  35. username: '',
  36. userId: '',
  37. isRegisterActive: false,
  38. isLoginActive: false,
  39. isCreateCommunityStationActive: false,
  40. serverDomain: '',
  41. socketConnected: true
  42. }
  43. },
  44. methods: {
  45. logout: function () {
  46. let _this = this;
  47. _this.socket.emit('users.logout', result => {
  48. if (result.status === 'success') {
  49. document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  50. _this.$router.go('/');
  51. location.reload();
  52. } else Toast.methods.addToast(result.message, 4000);
  53. });
  54. },
  55. 'submitOnEnter': (cb, event) => {
  56. if (event.which == 13) cb();
  57. }
  58. },
  59. ready: function () {
  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. io.onConnect(() => {
  69. _this.socketConnected = true;
  70. });
  71. io.onConnectError(() => {
  72. _this.socketConnected = false;
  73. });
  74. io.onDisconnect(() => {
  75. _this.socketConnected = false;
  76. });
  77. lofig.get('serverDomain', res => {
  78. _this.serverDomain = res;
  79. });
  80. if (_this.$route.query.err) Toast.methods.addToast(_this.$route.query.err, 20000);
  81. },
  82. events: {
  83. 'register': function () {
  84. let { register: { email, username, password } } = this;
  85. let _this = this;
  86. this.socket.emit('users.register', username, email, password, grecaptcha.getResponse(), result => {
  87. if (result.status === 'success') {
  88. Toast.methods.addToast(`You have successfully registered.`, 4000);
  89. setTimeout(() => {
  90. if (result.SID) {
  91. let date = new Date();
  92. date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
  93. document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
  94. location.reload();
  95. } else _this.$router.go('/login');
  96. }, 4000);
  97. } else Toast.methods.addToast(result.message, 8000);
  98. });
  99. },
  100. 'login': function () {
  101. let { login: { email, password } } = this;
  102. let _this = this;
  103. this.socket.emit('users.login', email, password, result => {
  104. if (result.status === 'success') {
  105. let date = new Date();
  106. date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
  107. document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
  108. Toast.methods.addToast(`You have been successfully logged in`, 2000);
  109. _this.$router.go('/');
  110. location.reload();
  111. } else Toast.methods.addToast(result.message, 2000);
  112. });
  113. },
  114. 'toggleModal': function (type) {
  115. switch(type) {
  116. case 'register':
  117. this.isRegisterActive = !this.isRegisterActive;
  118. break;
  119. case 'login':
  120. this.isLoginActive = !this.isLoginActive;
  121. break;
  122. case 'createCommunityStation':
  123. this.isCreateCommunityStationActive = !this.isCreateCommunityStationActive;
  124. break;
  125. }
  126. },
  127. 'closeModal': function() {
  128. this.$broadcast('closeModal');
  129. }
  130. },
  131. components: { Toast, WhatIsNew, LoginModal, RegisterModal, CreateCommunityStation }
  132. }
  133. </script>
  134. <style type='scss'>
  135. #toast-container { z-index: 10000 !important; }
  136. html {
  137. overflow: auto !important;
  138. }
  139. .absolute-a {
  140. width: 100%;
  141. height: 100%;
  142. position: absolute;
  143. top: 0;
  144. left: 0;
  145. }
  146. .socketNotConnected {
  147. padding: 20px;
  148. color: white;
  149. background-color: red;
  150. position: fixed;
  151. top: 50px;
  152. right: 50px;
  153. font-size: 2em;
  154. border-radius: 5px;
  155. z-index: 10000000;
  156. }
  157. .tooltip {
  158. position: relative;
  159. &:after {
  160. position: absolute;
  161. min-width: 80px;
  162. margin-left: -75%;
  163. text-align: center;
  164. padding: 7.5px 6px;
  165. border-radius: 2px;
  166. background-color: #323232;
  167. font-size: .9em;
  168. color: #fff;
  169. content: attr(data-tooltip);
  170. opacity: 0;
  171. transition: all .2s ease-in-out .1s;
  172. visibility: hidden;
  173. }
  174. &:hover:after {
  175. opacity: 1;
  176. visibility: visible;
  177. }
  178. }
  179. .tooltip-top {
  180. &:after {
  181. bottom: 150%;
  182. }
  183. &:hover {
  184. &:after { bottom: 120%; }
  185. }
  186. }
  187. .tooltip-bottom {
  188. &:after {
  189. top: 155%;
  190. }
  191. &:hover {
  192. &:after { top: 125%; }
  193. }
  194. }
  195. .tooltip-left {
  196. &:after {
  197. bottom: -10px;
  198. right: 130%;
  199. min-width: 100px;
  200. }
  201. &:hover {
  202. &:after { right: 110%; }
  203. }
  204. }
  205. .tooltip-right {
  206. &:after {
  207. bottom: -10px;
  208. left: 190%;
  209. min-width: 100px;
  210. }
  211. &:hover {
  212. &:after { left: 200%; }
  213. }
  214. }
  215. .button:focus, .button:active { border-color: #dbdbdb !important; }
  216. .input:focus, .input:active { border-color: #03a9f4 !important; }
  217. button.delete:focus { background-color: rgba(10, 10, 10, 0.3); }
  218. .tag { padding-right: 6px !important; }
  219. </style>