12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <template>
- <div>
- <router-view></router-view>
- </div>
- </template>
- <script>
- export default {
- replace: false,
- data() {
- return {
- register: {
- email: "",
- username: "",
- password: ""
- },
- login: {
- email: "",
- password: ""
- },
- likes: [],
- dislikes: [],
- loggedIn: false,
- stations: {
- official: [],
- community: []
- }
- }
- },
- methods: {
- logout: function () {
- this.socket.emit('users.logout');
- document.cookie = 'SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
- location.reload();
- }
- },
- ready: function () {
- lofig.get('socket.url', res => {
- let socket = this.socket = io(window.location.protocol + '//' + res);
- socket.on("ready", status => this.loggedIn = status);
- socket.emit("stations.index", data => {
- if (data.status === "success") data.stations.forEach(station => {
- if (station.type == 'official') this.stations.official.push(station);
- else this.stations.community.push(station);
- });
- });
- });
- },
- events: {
- 'register': function () {
- let { register: { email, username, password } } = this;
- this.socket.emit('users.register', email, username, password, grecaptcha.getResponse(), (result) => {
- console.log(result);
- location.reload();
- });
- },
- 'login': function () {
- let { login: { email, password } } = this;
- this.socket.emit('users.login', email, password, (result) => {
- console.log(result);
- if (result.status === 'success') {
- let date = new Date();
- date.setTime(new Date().getTime() + (2*365*24*60*60*1000));
- document.cookie = "SID=" + result.sessionId + "; expires="+ date.toGMTString() +"; path=/";
- location.reload();
- } else {
- //TODO Error toast
- }
- });
- },
- 'joinStation': function (id) {
- let mergedStations = this.stations.community.concat(this.stations.official);
- this.socket.emit('stations.join', id, result => {
- mergedStations.find(station => station.id === id).users = result.userCount;
- });
- },
- 'leaveStation': function () {
- this.socket.emit('stations.leave', result => {
- //this.stations.find(station => station.id === id).users = result.userCount;
- });
- }
- }
- }
- </script>
|