App.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div>
  3. <h1 v-if="!socketConnected" class="alert">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(true, () => {
  69. _this.socketConnected = true;
  70. });
  71. io.onConnectError(true, () => {
  72. _this.socketConnected = false;
  73. });
  74. io.onDisconnect(true, () => {
  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. lofig.get('cookie', cookie => {
  92. let date = new Date();
  93. date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
  94. document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; domain=${cookie.domain}; secure=${cookie.secure}; path=/`;
  95. location.reload();
  96. });
  97. } else _this.$router.go('/login');
  98. }, 4000);
  99. } else Toast.methods.addToast(result.message, 8000);
  100. });
  101. },
  102. 'login': function () {
  103. let { login: { email, password } } = this;
  104. let _this = this;
  105. this.socket.emit('users.login', email, password, result => {
  106. if (result.status === 'success') {
  107. lofig.get('cookie', cookie => {
  108. let date = new Date();
  109. date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
  110. document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; domain=${cookie.domain}; secure=${cookie.secure}; path=/`;
  111. Toast.methods.addToast(`You have been successfully logged in`, 2000);
  112. _this.$router.go('/');
  113. location.reload();
  114. });
  115. } else Toast.methods.addToast(result.message, 2000);
  116. });
  117. },
  118. 'toggleModal': function (type) {
  119. switch(type) {
  120. case 'register':
  121. this.isRegisterActive = !this.isRegisterActive;
  122. break;
  123. case 'login':
  124. this.isLoginActive = !this.isLoginActive;
  125. break;
  126. case 'createCommunityStation':
  127. this.isCreateCommunityStationActive = !this.isCreateCommunityStationActive;
  128. break;
  129. }
  130. },
  131. 'closeModal': function() {
  132. this.$broadcast('closeModal');
  133. }
  134. },
  135. components: { Toast, WhatIsNew, LoginModal, RegisterModal, CreateCommunityStation }
  136. }
  137. </script>
  138. <style type='scss'>
  139. #toast-container { z-index: 10000 !important; }
  140. html {
  141. overflow: auto !important;
  142. }
  143. .absolute-a {
  144. width: 100%;
  145. height: 100%;
  146. position: absolute;
  147. top: 0;
  148. left: 0;
  149. }
  150. .alert {
  151. padding: 20px;
  152. color: white;
  153. background-color: red;
  154. position: fixed;
  155. top: 50px;
  156. right: 50px;
  157. font-size: 2em;
  158. border-radius: 5px;
  159. z-index: 10000000;
  160. }
  161. .tooltip {
  162. position: relative;
  163. &:after {
  164. position: absolute;
  165. min-width: 80px;
  166. margin-left: -75%;
  167. text-align: center;
  168. padding: 7.5px 6px;
  169. border-radius: 2px;
  170. background-color: #323232;
  171. font-size: .9em;
  172. color: #fff;
  173. content: attr(data-tooltip);
  174. opacity: 0;
  175. transition: all .2s ease-in-out .1s;
  176. visibility: hidden;
  177. }
  178. &:hover:after {
  179. opacity: 1;
  180. visibility: visible;
  181. }
  182. }
  183. .tooltip-top {
  184. &:after {
  185. bottom: 150%;
  186. }
  187. &:hover {
  188. &:after { bottom: 120%; }
  189. }
  190. }
  191. .tooltip-bottom {
  192. &:after {
  193. top: 155%;
  194. }
  195. &:hover {
  196. &:after { top: 125%; }
  197. }
  198. }
  199. .tooltip-left {
  200. &:after {
  201. bottom: -10px;
  202. right: 130%;
  203. min-width: 100px;
  204. }
  205. &:hover {
  206. &:after { right: 110%; }
  207. }
  208. }
  209. .tooltip-right {
  210. &:after {
  211. bottom: -10px;
  212. left: 190%;
  213. min-width: 100px;
  214. }
  215. &:hover {
  216. &:after { left: 200%; }
  217. }
  218. }
  219. .button:focus, .button:active { border-color: #dbdbdb !important; }
  220. .input:focus, .input:active { border-color: #03a9f4 !important; }
  221. button.delete:focus { background-color: rgba(10, 10, 10, 0.3); }
  222. .tag { padding-right: 6px !important; }
  223. </style>