App.vue 5.5 KB

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