frontend/src/components/Navbar.vue

739 lines
29 KiB
Vue
Raw Normal View History

2021-01-15 23:24:15 +11:00
<template>
<nav>
<b-modal :active="ajaxErrorModal" @update:active="value => ajaxErrorModal = value" :width="640" scroll="keep" style="z-index: 200">
<div class="modal-card" style="width: auto">
<header class="modal-card-head">
2021-01-16 17:06:35 +11:00
<p class="modal-card-title">{{$t('errorModalTitle')}}</p>
<button
type="button"
class="delete"
@click="$emit('close')"/>
</header>
<section class="modal-card-body media">
<p :key='error' v-for='error in this.$store.state.errors.errors' style='margin: 1rem;'>{{error}}</p>
</section>
<footer class="modal-card-foot">
<b-button
2021-01-16 17:06:35 +11:00
:label="$t('gotIt')"
2021-01-16 18:11:42 +11:00
@click="ajaxErrorModal = false" />
</footer>
</div>
</b-modal>
2021-01-15 23:24:15 +11:00
<b-modal :active="loginModal" @update:active="value => loginModal = value" :width="640" scroll="keep">
2021-01-16 17:06:35 +11:00
<form>
2021-01-15 23:24:15 +11:00
<div class="modal-card" style="width: auto">
<header class="modal-card-head">
2021-01-16 17:06:35 +11:00
<p class="modal-card-title">{{ $t('login.title') }}</p>
2021-01-15 23:24:15 +11:00
<button
type="button"
class="delete"
2021-01-16 18:11:42 +11:00
@click="loginModal = false"/>
2021-01-15 23:24:15 +11:00
</header>
<section class="modal-card-body">
2021-01-16 17:06:35 +11:00
<b-field :label="$t('login.loginUsername')">
2021-01-15 23:24:15 +11:00
<b-input
:value="login.username"
v-model="login.username"
2021-01-16 17:06:35 +11:00
:placeholder="$t('login.loginUsername')"
2021-01-15 23:24:15 +11:00
required>
</b-input>
</b-field>
2021-01-16 17:06:35 +11:00
<b-field :label="$t('login.loginPassword')">
2021-01-15 23:24:15 +11:00
<b-input
type="password"
:value="login.password"
v-model="login.password"
password-reveal
2021-01-16 17:06:35 +11:00
:placeholder="$t('login.loginPassword')"
2021-01-15 23:24:15 +11:00
required>
</b-input>
</b-field>
2021-01-16 17:06:35 +11:00
<b-checkbox v-model="login.doNotSaveToken">{{$t('login.doNotSaveAuth')}}</b-checkbox>
2021-01-15 23:24:15 +11:00
</section>
<footer class="modal-card-foot">
<b-button
@click="doLogin()"
2021-01-16 17:06:35 +11:00
:label="$t('login.login')"
2021-01-15 23:24:15 +11:00
:loading="login.loading"
type="is-primary" />
2021-01-16 15:33:33 +11:00
<b-button
2021-01-16 17:06:35 +11:00
:label="$t('close')"
2021-01-16 18:11:42 +11:00
@click="loginModal = false" />
<b-button
@click="registerModal = true; loginModal = false"
2021-01-16 17:06:35 +11:00
:label="$t('login.register')"
type="is-success" />
2021-01-15 23:24:15 +11:00
</footer>
</div>
2021-01-16 17:06:35 +11:00
</form>
2021-01-15 23:24:15 +11:00
</b-modal>
2021-01-17 00:20:05 +11:00
<b-modal :active="settingsModal" @update:active="value => settingsModal = value" :width="640" scroll="keep">
<form>
<div class="modal-card" style="width: auto">
<header class="modal-card-head">
<p class="modal-card-title">{{ $t('settings.title') }}</p>
<button
type="button"
class="delete"
@click="loginModal = false"/>
</header>
<section class="modal-card-body">
<b-tabs position="is-centered" class="block">
<b-tab-item :label="$t('settings.general.title')">
<h1 class="title">{{$t('settings.general.title')}}</h1>
<div>
<h1 class="subtitle">{{$t('settings.general.about')}}</h1>
<h4>
{{ $t('settings.general.description') }}
</h4>
<b-input type="textarea"
:placeholder="$t('settings.general.hi') + ' ' + $store.state.user.username"
maxlength="256"
v-model='settings.general.description.value'
:error='settings.general.description.error'
></b-input>
<b-button
class='button is-info'
:loading='settings.general.description.loading'
2021-01-21 00:08:04 +11:00
@click='saveDesc()'
2021-01-17 00:20:05 +11:00
>
{{$t('settings.general.saveDesc')}}
</b-button>
</div>
<div>
<h2>{{$t('settings.general.preferences')}}</h2>
<b-switch class="is-info" v-model="settings.general.preferences.developerMode">{{$t('settings.general.devMode')}}</b-switch><br>
<b-button
class='button is-info'
:loading='settings.general.preferences.loading'
2021-01-21 00:08:04 +11:00
@click='savePref()'
2021-01-17 00:20:05 +11:00
>
{{$t('settings.general.savePref')}}
</b-button>
</div>
</b-tab-item>
<b-tab-item :label="$t('settings.security.title')">
Debug
</b-tab-item>
<b-tab-item :label="$t('settings.privacy.title')">
Debug
</b-tab-item>
<b-tab-item :label="$t('settings.experiments.title')">
Debug
</b-tab-item>
<b-tab-item :label="$t('settings.about.title')">
<div>
<center>
<img src="https://cdn.kaverti.com/icon.png" width="10%">
<h1>Kaverti v{{this.$store.state.client.clientVersion}}</h1>
<p>Latest client version: v{{this.$store.state.client.latestClientVersion}}</p>
<p>API version: v{{this.$store.state.client.latestAPIVersion}}</p>
</center>
</div>
</b-tab-item>
</b-tabs>
</section>
2021-01-20 00:03:47 +11:00
<footer class="modal-card-foot">
<b-button
:label="$t('close')"
@click="settingsModal = false" />
</footer>
2021-01-17 00:20:05 +11:00
</div>
</form>
</b-modal>
<b-modal :active="updateModal" @update:active="value => updateModal = value" :width="640" scroll="keep">
<form>
<div class="modal-card" style="width: auto">
<header class="modal-card-head">
<p class="modal-card-title">{{$t('update.title')}}</p>
<button
type="button"
class="delete"
@click="registerModal = false"/>
</header>
<section class="modal-card-body has-text-centered">
<h1 class="subtitle">What's new in {{$store.state.client.clientVersion}}?</h1>
<ul>
<li>Marketplace</li>
<li>Pagination Component</li>
<li>Fix crashing when token is null</li>
<li>User list pagination</li>
<li>Marketplace Item</li>
</ul>
</section>
<footer class="modal-card-foot">
<b-button
:label="$t('close')"
@click="updateDismissed" />
</footer>
</div>
</form>
</b-modal>
2021-01-15 23:24:15 +11:00
<b-modal :active="registerModal" @update:active="value => registerModal = value" :width="640" scroll="keep">
2021-01-16 17:06:35 +11:00
<form>
2021-01-15 23:24:15 +11:00
<div class="modal-card" style="width: auto">
<header class="modal-card-head">
2021-01-16 17:06:35 +11:00
<p class="modal-card-title">{{$t('register.title')}}</p>
2021-01-15 23:24:15 +11:00
<button
type="button"
class="delete"
2021-01-16 18:11:42 +11:00
@click="registerModal = false"/>
2021-01-15 23:24:15 +11:00
</header>
<section class="modal-card-body">
2021-01-16 17:06:35 +11:00
<b-field :label="$t('register.username')">
2021-01-15 23:24:15 +11:00
<b-input
:value="register.username"
v-model="register.username"
2021-01-16 17:06:35 +11:00
:placeholder="$t('register.username')"
2021-01-15 23:24:15 +11:00
required>
</b-input>
</b-field>
2021-01-16 17:06:35 +11:00
<b-field :label="$t('register.email')">
2021-01-15 23:24:15 +11:00
<b-input
type="email"
:value="register.email"
v-model="register.email"
2021-01-16 17:06:35 +11:00
:placeholder="$t('register.email')"
2021-01-15 23:24:15 +11:00
required>
</b-input>
</b-field>
2021-01-16 17:06:35 +11:00
<b-field :label="$t('register.password')">
2021-01-15 23:24:15 +11:00
<b-input
type="password"
:value="register.password"
v-model="register.password"
password-reveal
2021-01-16 17:06:35 +11:00
:placeholder="$t('register.password')"
2021-01-15 23:24:15 +11:00
required>
</b-input>
</b-field>
2021-01-16 17:06:35 +11:00
<b-field :label="$t('register.confirm')">
2021-01-15 23:24:15 +11:00
<b-input
type="password"
:value="register.confirm"
v-model="register.confirm"
password-reveal
2021-01-16 17:06:35 +11:00
:placeholder="$t('register.confirm')"
2021-01-15 23:24:15 +11:00
required>
</b-input>
</b-field>
2021-01-16 17:06:35 +11:00
<b-checkbox v-model="register.agree">{{$t('register.agree')}} <router-link to="/legal/tos">{{$t('tos')}}</router-link></b-checkbox>
2021-01-15 23:24:15 +11:00
</section>
<footer class="modal-card-foot">
<b-button
@click="doRegister()"
2021-01-16 17:06:35 +11:00
:label="$t('register.text')"
2021-01-15 23:24:15 +11:00
:loading="register.loading"
type="is-primary" />
2021-01-16 15:33:33 +11:00
<b-button
2021-01-16 17:06:35 +11:00
:label="$t('close')"
2021-01-16 18:11:42 +11:00
@click="registerModal = false" />
<b-button
@click="registerModal = false; loginModal = true"
2021-01-16 17:06:35 +11:00
:label="$t('register.login')"
type="is-success" />
2021-01-15 23:24:15 +11:00
</footer>
</div>
2021-01-16 17:06:35 +11:00
</form>
2021-01-15 23:24:15 +11:00
</b-modal>
2021-01-18 00:05:28 +11:00
<section v-if='!$store.state.user.emailVerified && $store.state.user.username' class="hero is-danger">
<div class="hero-body" style="padding: 1rem 1rem !important;">
<div class="mobile-container">
<div class="container">
<p style="text-align: center;">{{$t('errors.emailVerify')}}</p>
</div>
</div>
</div>
</section>
2021-01-21 02:39:07 +11:00
<section v-if='$store.state.client.clientVersion !== $store.state.client.latestClientVersion && showOutdatedBanner' class="hero is-warning">
<div class="hero-body" style="padding: 1rem 1rem !important;">
<div class="mobile-container">
<div class="container">
<p style="text-align: center;">You are using an outdated version of Kaverti, please refresh.<button
type="button"
class="delete"
style="float: right;"
@click="showOutdatedBanner = false"/></p>
</div>
</div>
</div>
</section>
2021-01-15 23:24:15 +11:00
<b-navbar>
<template #brand>
<b-navbar-item tag="router-link" :to="{ path: '/' }">
<img
src="https://cdn.kaverti.com/logo.png"
alt="Kaverti Logo"
>
</b-navbar-item>
</template>
<template #start>
2021-01-17 00:20:05 +11:00
<b-navbar-item tag="router-link" to="/">
2021-01-16 17:06:35 +11:00
{{$t('navbar.home')}}
2021-01-15 23:24:15 +11:00
</b-navbar-item>
2021-01-20 00:03:47 +11:00
<b-navbar-item tag="router-link" to="/forums">
{{$t('navbar.forums')}}
</b-navbar-item>
2021-01-17 00:20:05 +11:00
<b-navbar-item tag="router-link" to="/marketplace">
2021-01-16 17:06:35 +11:00
{{$t('navbar.marketplace')}}
</b-navbar-item>
2021-01-17 00:20:05 +11:00
<b-navbar-item tag="router-link" to="/users">
{{$t('navbar.users')}}
</b-navbar-item>
<b-navbar-item tag="router-link" to="/teams">
2021-01-16 17:06:35 +11:00
{{$t('navbar.teams')}}
</b-navbar-item>
2021-01-17 00:20:05 +11:00
<b-navbar-item tag="router-link" to="/games">
2021-01-16 17:06:35 +11:00
{{$t('navbar.games')}}
2021-01-15 23:24:15 +11:00
</b-navbar-item>
<div v-if="$store.state.debug" class="navbar-item has-dropdown is-hoverable is-info">
<a class="navbar-link">
2021-01-16 17:06:35 +11:00
<p>{{$t('navbar.dev.title')}}</p>
2021-01-15 23:24:15 +11:00
</a>
<div class="navbar-dropdown">
2021-01-16 17:06:35 +11:00
<b-navbar-item tag="router-link" to="/debug">{{$t('navbar.dev.debug')}}</b-navbar-item>
<b-navbar-item @click="fakeUser()">{{$t('navbar.dev.fakeUser')}}</b-navbar-item>
2021-01-21 02:39:07 +11:00
<b-navbar-item @click="toggleBrokenRoute(true)">{{$t('navbar.dev.brokenRoute')}}</b-navbar-item>
2021-01-15 23:24:15 +11:00
</div>
</div>
2021-01-17 00:20:05 +11:00
<div v-if="$store.state.debug" class="navbar-item has-dropdown is-hoverable is-info">
<a class="navbar-link">
<p>{{$t('navbar.more.title')}}</p>
</a>
<div class="navbar-dropdown">
<b-navbar-item tag="a" href="https://twitter.com/Kaverti">{{$t('navbar.more.twitter')}}</b-navbar-item>
<b-navbar-item tag="a" href="https://discord.gg/Q3HAWFdBPK">{{$t('navbar.more.discord')}}</b-navbar-item>
<b-navbar-item tag="router-link" to="/roadmap">{{$t('navbar.more.roadmap')}}</b-navbar-item>
<b-navbar-item tag="a" href="soon">{{$t('navbar.more.documentation')}}</b-navbar-item>
<b-navbar-item tag="router-link" to="/downloads">{{$t('navbar.downloads')}}</b-navbar-item>
<b-navbar-item tag="router-link" to="/stats">{{$t('navbar.more.stats')}}</b-navbar-item>
2021-01-28 00:04:22 +11:00
<b-navbar-item tag="router-link" to="/blog">{{$t('navbar.more.blog')}}</b-navbar-item>
2021-01-17 00:20:05 +11:00
</div>
</div>
2021-01-15 23:24:15 +11:00
</template>
<template #end>
2021-01-21 02:39:07 +11:00
<b-navbar-item v-if="$store.state.user.username && !loading" @click="dailyReward">
2021-01-19 01:57:19 +11:00
<img src="https://cdn.kaverti.com/icons/koins.svg">{{$store.state.user.koins}}
2021-01-17 00:20:05 +11:00
</b-navbar-item>
2021-01-16 15:33:33 +11:00
<div v-if="!loading">
2021-01-28 00:04:22 +11:00
<b-navbar-item v-if="!$store.state.user.username" tag="div">
<div class="buttons">
<b-button @click="registerModal = true" class="button is-primary">
<strong>{{$t('navbar.register')}}</strong>
</b-button>
<b-button @click="loginModal = true" class="button is-light">
{{$t('navbar.login')}}
</b-button>
</div>
</b-navbar-item>
2021-01-16 15:33:33 +11:00
</div>
2021-01-28 00:04:22 +11:00
<b-navbar-dropdown class="is-hoverable" style="padding-right:15px" :label="$store.state.user.username" v-if="$store.state.user.username && !loading">
<b-navbar-item tag="router-link" :to="'/u/' + $store.state.user.username">{{$t('navbar.user.profile')}}</b-navbar-item>
<b-navbar-item @click="settingsModal = true">{{$t('navbar.user.settings')}}</b-navbar-item>
<b-navbar-item tag="router-link" to="/transactions">{{$t('navbar.user.transactions')}}</b-navbar-item>
<b-navbar-item tag="router-link" to="/character">{{$t('navbar.user.avatar')}}</b-navbar-item>
<b-navbar-item tag="router-link" to="/creations">{{$t('navbar.user.creations')}}</b-navbar-item>
<b-navbar-item tag="router-link" to="/downloads">{{$t('navbar.user.downloads')}}</b-navbar-item>
<b-navbar-item tag="router-link" to="/admin" v-if="$store.state.user.admin">{{$t('navbar.user.admin')}}</b-navbar-item>
<b-navbar-item tag="router-link" to="/friends"><b-tag class="is-info" rounded> 1</b-tag>&nbsp; {{$t('navbar.user.friends')}}</b-navbar-item>
<b-navbar-item @click="logout()">{{$t('navbar.user.logout')}}</b-navbar-item>
</b-navbar-dropdown>
2021-01-19 01:57:19 +11:00
<b-navbar-item v-if="loading">
<div class="fa-1x">
<i class="fas fa-circle-notch fa-spin"></i>&nbsp;
&nbsp;{{ $t('generic.loading') }}
</div>
</b-navbar-item>
2021-01-15 23:24:15 +11:00
</template>
</b-navbar>
2021-01-18 00:05:28 +11:00
<section v-if='$store.state.client.bannerText && $store.state.client.bannerEnabled && showBanner' class="hero is-info">
<div class="hero-body" style="padding: 1rem 1rem !important;">
<div class="mobile-container">
<div class="container">
<p style="text-align: center;">{{$store.state.client.bannerText}} <button
type="button"
class="delete"
style="float: right;"
@click="removeBannerId"/></p>
</div>
</div>
</div>
</section>
2021-01-15 23:24:15 +11:00
</nav>
</template>
<script>
import AjaxErrorHandler from '../../assets/js/errorHandler'
import axios from "axios";
2021-01-15 23:24:15 +11:00
export default {
data() {
return {
loginModal: false,
registerModal: false,
2021-01-16 15:33:33 +11:00
loading: true,
2021-01-17 00:20:05 +11:00
settingsModal: false,
2021-01-18 00:05:28 +11:00
showBanner: true,
2021-01-21 02:39:07 +11:00
showOutdatedBanner: true,
2021-01-19 03:00:49 +11:00
friendCount: 0,
updateModal: false,
2021-01-17 00:20:05 +11:00
settings: {
tab: 0,
general: {
description: {
value: '',
loading: false,
error: ''
},
preferences: {
theme: '',
developerMode: '',
loading: false,
error: ''
},
},
privacy: {
wall: false,
loading: false
},
experiments: {
theme: 'light',
loading: false,
error: '',
relationships: false,
wall: false,
marketplace: false,
teams: false,
newsettings: true,
corrupt: false,
local: []
},
account: {
showLogoutModal: false,
password: {
loading: false,
current: '',
new: '',
errors: {
'new password': '',
'current password': ''
}
},
email: {
loading: false,
loadingChange: false,
currentPassword: '',
new: '',
errors: {
'new password': '',
'email current password': ''
}
},
username: {username: '',
password: '',
errors: {
'username': '',
'password': '',
},
loading: false,
},
deleteAcc: {
loading: false,
password: '',
errors: {
'current password': ''
}
},
totp: {loading: false
},
deleteAccountLoading: false,
invalidateSessionLoading: false,
emailCheckDelete: false,
showLoginModal: false
}
},
2021-01-15 23:24:15 +11:00
login: {
username: '',
password: '',
2021-01-16 15:33:33 +11:00
loading: false,
doNotSaveToken: false,
2021-01-15 23:24:15 +11:00
},
register: {
username: '',
email: '',
password: '',
confirm: '',
agree: false,
loading: false
}
}
},
computed: {
ajaxErrorModal: {
get() {
return this.$store.state.errors.modal
},
set(val) {
this.$store.commit('setAjaxErrorsModalState', val)
}
},
},
2021-01-15 23:24:15 +11:00
methods: {
2021-01-21 02:39:07 +11:00
toggleBrokenRoute (val) {
this.$store.commit('brokenRoute', val)
},
2021-01-21 00:08:04 +11:00
savePref() {
this.preferences.error = ''
this.preferences.loading = true
this.axios
.put(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'users/preferences', {
developerMode: this.preferences.developerMode
})
.then(() => {
this.preferences.loading = false
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'userinfo')
.then(res => {
this.$store.commit('setUsername', res.data.username)
this.$store.commit('setEmail', res.data.email)
this.$store.commit('setEmailVerified', res.data.emailVerified)
this.$store.commit('setAdmin', res.data.admin)
this.$store.commit('setDevMode', res.data.developerMode)
})
})
.catch(e => {
this.preferences.loading = false
AjaxErrorHandler(this.$store)(e)
})
},
saveDesc() {
this.description.error = ''
this.description.loading = true
this.axios
.put(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'users/preferences', {
description: this.description.value
})
.then(() => {
this.description.loading = false
})
.catch(e => {
this.description.loading = false
AjaxErrorHandler(this.$store)(e)
})
},
2021-01-18 00:05:28 +11:00
getBannerId() {
if(localStorage.getItem(this.$store.state.client.bannerId)) {
this.showBanner = false
} else {
this.showBanner = true
}
},
updateDismissed() {
localStorage.setItem("update-" + this.$store.state.client.clientVersion, true)
this.updateModal = false
},
showUpdate() {
if(!localStorage.getItem("update-" + this.$store.state.client.clientVersion)) {
this.updateModal = true
} else {
this.updateModal = false
}
},
2021-01-18 00:05:28 +11:00
removeBannerId() {
localStorage.setItem(this.$store.state.client.bannerId, true)
this.$store.state.client.bannerEnabled = false
console.log(localStorage.getItem(this.$store.state.client.bannerId))
},
2021-01-15 23:24:15 +11:00
doRegister() {
this.register.loading = true
2021-01-18 00:05:28 +11:00
this.axios.post('/api/v1/passkey/register', {
2021-01-15 23:24:15 +11:00
username: this.register.username,
password: this.register.password,
email: this.register.email,
confirm: this.register.confirm,
agree: this.register.agree
}).then((res) => {
this.register.loading = false
2021-01-21 00:08:04 +11:00
this.registerModal = false
2021-01-15 23:24:15 +11:00
this.$store.commit('setToken', res.data.token)
2021-01-21 00:08:04 +11:00
localStorage.setItem('token', JSON.stringify(res.data.token));
this.getInfo()
2021-01-18 00:05:28 +11:00
this.$buefy.snackbar.open({message:this.$t('errors.registered'), type: 'is-info'})
2021-01-15 23:24:15 +11:00
}).catch(e => {
this.register.loading = false
AjaxErrorHandler(this.$store)(e, (error, errors) => {
let path = error.path
if (this.errors[path] !== undefined) {
this.errors[path] = error.message
} else {
errors.push(error.message)
}
})
})
},
doLogin() {
this.login.loading = true
this.axios.post('/api/v1/users/login', {
username: this.login.username,
password: this.login.password
2021-01-15 23:24:15 +11:00
}).then((res) => {
this.login.loading = false
2021-01-15 23:24:15 +11:00
this.$store.commit('setToken', res.data.token)
2021-01-16 15:33:33 +11:00
if (!this.login.doNotSaveToken) {
localStorage.setItem('token', JSON.stringify(res.data.token));
}
Object.assign(axios.defaults, {headers: {Authorization: this.$store.state.user.token}})
2021-01-16 15:33:33 +11:00
this.loginModal = false
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'userinfo')
.then(res => {
this.$store.commit('setUsername', res.data.username)
this.$store.commit('setEmail', res.data.email)
this.$store.commit('setEmailVerified', res.data.emailVerified)
this.$store.commit('setAdmin', res.data.admin)
this.$store.commit('setKoins', res.data.koins)
this.$store.commit('setID', res.data.id)
this.$store.commit('setBot', res.data.bot)
2021-01-18 00:05:28 +11:00
this.$buefy.snackbar.open({message:this.$t('errors.login'), type: 'is-info'})
2021-01-16 15:33:33 +11:00
}).catch(() => {
2021-01-16 18:11:42 +11:00
this.$buefy.snackbar.open({message:this.$t('errors.authFail'), type: 'is-warning'})
2021-01-16 15:33:33 +11:00
})
2021-01-15 23:24:15 +11:00
}).catch(e => {
this.login.loading = false
2021-01-16 15:33:33 +11:00
AjaxErrorHandler(this.$store)(e)
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'userinfo')
.then(res => {
this.$store.commit('setUsername', res.data.username)
this.$store.commit('setEmail', res.data.email)
this.$store.commit('setEmailVerified', res.data.emailVerified)
this.$store.commit('setAdmin', res.data.admin)
this.$store.commit('setKoins', res.data.koins)
this.$store.commit('setID', res.data.id)
this.$store.commit('setBot', res.data.bot)
}).catch(() => {
2021-01-16 18:11:42 +11:00
this.$buefy.snackbar.open({message:this.$t('errors.authFail'), type: 'is-warning'})
2021-01-16 15:33:33 +11:00
})
2021-01-15 23:24:15 +11:00
AjaxErrorHandler(this.$store)(e, (error, errors) => {
let path = error.path
if (this.errors[path] !== undefined) {
this.errors[path] = error.message
} else {
errors.push(error.message)
}
})
})
},
2021-01-18 00:05:28 +11:00
logout() {
localStorage.removeItem('token');
this.$store.commit('setToken', '')
Object.assign(axios.defaults, {headers: {Authorization: this.$store.state.user.token}})
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'userinfo')
.then(res => {
this.$store.commit('setUsername', res.data.username)
this.$store.commit('setEmail', res.data.email)
this.$store.commit('setEmailVerified', res.data.emailVerified)
this.$store.commit('setAdmin', res.data.admin)
this.$store.commit('setKoins', res.data.koins)
this.$store.commit('setID', res.data.id)
this.$store.commit('setBot', res.data.bot)
this.$buefy.snackbar.open({message:this.$t('errors.logout'), type: 'is-info'})
}).catch(() => {
this.$buefy.snackbar.open({message:this.$t('errors.logout'), type: 'is-info'})
})
},
fakeUser () {
this.$store.commit('fakeUser')
this.$buefy.snackbar.open(`WARNING: You have fake authenticated, you do not have authenticated API access. Use for debug purposes only.`)
Object.assign(axios.defaults, {headers: {Authorization: this.$store.state.user.token}})
2021-01-21 00:08:04 +11:00
},
2021-01-21 02:39:07 +11:00
dailyReward() {
this.axios.get(
process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'users/reward'
).then(res => {
this.$store.commit('setKoins', res.data.koins)
}).catch(e => {
AjaxErrorHandler(this.$store)(e)
})
},
2021-01-21 00:08:04 +11:00
getInfo() {
Object.assign(axios.defaults, {headers: {Authorization: this.$store.state.user.token}})
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'kaverti/state')
.then(res => {
2021-01-21 02:39:07 +11:00
this.$store.commit('setSettings', res.data.state)
this.$store.commit('setVersion', res.data.state.latestCanaryVersion)
this.$store.commit('setAPIVersion', res.data.apiVersion)
2021-01-21 00:08:04 +11:00
}).catch(() => {
this.$buefy.snackbar.open({message:this.$t('errors.down'), type: 'is-info'})
})
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'userinfo')
.then(res => {
this.$store.commit('setUsername', res.data.username)
this.$store.commit('setEmail', res.data.email)
this.$store.commit('setEmailVerified', res.data.emailVerified)
this.$store.commit('setAdmin', res.data.admin)
this.$store.commit('setKoins', res.data.koins)
this.$store.commit('setID', res.data.id)
this.$store.commit('setBot', res.data.bot)
this.$store.commit('setDescription', res.data.description)
this.$store.commit('setExecutive', res.data.executive)
this.settings.general.description.value = res.data.description
this.loading = false
}).catch(() => {
this.$buefy.snackbar.open({message:this.$t('errors.authFail'), type: 'is-warning'})
this.loading = false
})
2021-01-15 23:24:15 +11:00
}
2021-01-16 15:33:33 +11:00
},
mounted() {
2021-01-21 00:08:04 +11:00
Object.assign(axios.defaults, {headers: {Authorization: this.$store.state.user.token}})
2021-01-18 00:05:28 +11:00
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'kaverti/state')
.then(res => {
2021-01-21 02:39:07 +11:00
this.$store.commit('setSettings', res.data.state)
this.$store.commit('setVersion', res.data.state.latestCanaryVersion)
this.$store.commit('setAPIVersion', res.data.apiVersion)
2021-01-18 00:05:28 +11:00
}).catch(() => {
this.$buefy.snackbar.open({message:this.$t('errors.down'), type: 'is-info'})
})
2021-01-16 15:33:33 +11:00
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'userinfo')
.then(res => {
this.$store.commit('setUsername', res.data.username)
this.$store.commit('setEmail', res.data.email)
this.$store.commit('setEmailVerified', res.data.emailVerified)
this.$store.commit('setAdmin', res.data.admin)
this.$store.commit('setKoins', res.data.koins)
this.$store.commit('setID', res.data.id)
this.$store.commit('setBot', res.data.bot)
2021-01-21 00:08:04 +11:00
this.$store.commit('setDescription', res.data.description)
this.$store.commit('setExecutive', res.data.executive)
this.settings.general.description.value = res.data.description
2021-01-16 15:33:33 +11:00
this.loading = false
}).catch(() => {
2021-01-16 18:11:42 +11:00
this.$buefy.snackbar.open({message:this.$t('errors.authFail'), type: 'is-warning'})
2021-01-16 15:33:33 +11:00
this.loading = false
2021-01-18 00:05:28 +11:00
console.log(this.getBannerId())
2021-01-16 15:33:33 +11:00
})
2021-01-19 03:00:49 +11:00
if(this.$store.state.username) {
2021-01-21 02:39:07 +11:00
this.dailyReward()
2021-01-19 03:00:49 +11:00
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'relationships/getAllPendingCanAccept')
.then(res => {
this.friendCount = res.data.count
}).catch(() => {
this.$buefy.snackbar.open({message: this.$t('errors.authFail'), type: 'is-warning'})
this.loading = false
})
}
this.showUpdate()
2021-01-15 23:24:15 +11:00
}
}
</script>