123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <template>
- <div>
- <router-view></router-view>
- <toast></toast>
- <what-is-new></what-is-new>
- <login-modal v-if='isLoginActive'></login-modal>
- <register-modal v-if='isRegisterActive'></register-modal>
- <create-community-station v-if='isCCSActive'></create-community-station>
- </div>
- </template>
- <script>
- import { Toast } from 'vue-roaster';
- import WhatIsNew from './components/Modals/WhatIsNew.vue';
- import LoginModal from './components/Modals/Login.vue';
- import RegisterModal from './components/Modals/Register.vue';
- import CreateCommunityStation from './components/Modals/CreateCommunityStation.vue';
- import auth from './auth';
- export default {
- replace: false,
- data() {
- return {
- register: {
- email: '',
- username: '',
- password: ''
- },
- login: {
- email: '',
- password: ''
- },
- ccs: {
- name: '',
- displayName: '',
- description: ''
- },
- loggedIn: false,
- role: '',
- username: '',
- isRegisterActive: false,
- isLoginActive: false,
- isCCSActive: false,
- serverDomain: ''
- }
- },
- methods: {
- logout: function () {
- this.socket.emit('users.logout', result => {
- if (result.status === 'success') {
- document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
- location.reload();
- } else Toast.methods.addToast(result.message, 4000);
- });
- },
- 'submitOnEnter': (cb, event) => {
- if (event.which == 13) b(); return false;
- }
- },
- ready() {
- let _this = this;
- auth.getStatus((authenticated, role, username) => {
- _this.socket = window.socket;
- _this.loggedIn = authenticated;
- _this.role = role;
- _this.username = username;
- });
- lofig.get('serverDomain', res => {
- _this.serverDomain = res;
- });
- },
- events: {
- 'register': function () {
- let { register: { email, username, password } } = this;
- let _this = this;
- this.socket.emit('users.register', username, email, password, /*grecaptcha.getResponse()*/null, result => {
- Toast.methods.addToast(`You have successfully registered.`, 4000);
- setTimeout(() => {
- if (result.SID) {
- let date = new Date();
- date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
- document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
- location.reload();
- } else {
- _this.$router.go('/login');
- }
- }, 4000);
- });
- },
- 'login': function () {
- let { login: { email, password } } = this;
- let _this = this;
- this.socket.emit('users.login', email, password, result => {
- if (result.status === 'success') {
- let date = new Date();
- date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
- document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
- Toast.methods.addToast(`You have been successfully logged in`, 2000);
- _this.$router.go('/');
- location.reload();
- } else {
- Toast.methods.addToast(result.message, 2000);
- }
- });
- },
- 'ccs': function () {
- let _this = this;
- this.socket.emit('stations.createCommunity', {_id: _this.ccs.name, displayName: _this.ccs.displayName, description: _this.ccs.description}, result => {
- if (result.status === 'success') {
- Toast.methods.addToast(`You have added the station successfully`, 4000);
- } else {
- Toast.methods.addToast(result.message, 4000);
- }
- });
- },
- 'toggleModal': function (type) {
- switch(type) {
- case 'register':
- this.isRegisterActive = !this.isRegisterActive;
- break;
- case 'login':
- this.isLoginActive = !this.isLoginActive;
- break;
- case 'ccs':
- this.isCCSActive = !this.isCCSActive;
- break;
- }
- }
- },
- components: { Toast, WhatIsNew, LoginModal, RegisterModal, CreateCommunityStation }
- }
- </script>
|