aboutsummaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorFulgen301 <tokmajigeorge@gmail.com>2018-09-16 16:59:45 +0200
committerFulgen301 <tokmajigeorge@gmail.com>2018-09-16 16:59:45 +0200
commit08b551201fe72e71fd031a22542439d3e1b70169 (patch)
treef723e4f82804604ed3b32c551062a74fe9914004 /src/components
parent3262c3f172892309d1c174a8a319441e178c1a7f (diff)
downloadparry-ui-08b551201fe72e71fd031a22542439d3e1b70169.tar.gz
parry-ui-08b551201fe72e71fd031a22542439d3e1b70169.zip
Initial adapt to LegacyClonk
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ApiAuth.vue46
-rw-r--r--src/components/CommentVoter.vue2
-rw-r--r--src/components/UploadVoter.vue9
3 files changed, 21 insertions, 36 deletions
diff --git a/src/components/ApiAuth.vue b/src/components/ApiAuth.vue
index d2771c7..30c7e14 100644
--- a/src/components/ApiAuth.vue
+++ b/src/components/ApiAuth.vue
@@ -1,26 +1,16 @@
<template>
<div>
<div v-if="!$store.getters['user/loggedIn']">
- <div v-if="useLarryLogin" class="group">
- <h5>Larry Login</h5>
+ <div class="group">
+ <h5>Parry Login</h5>
<p v-if="authError" class="text-negative">
- <span v-if="typeof authError === 'object'">Email or password {{ authError['email or password'] }}</span>
+ <span v-if="typeof authError === 'object'">Username or password {{ authError['username or password'] }}</span>
<span v-else>{{ authError }}</span>
</p>
<div class="group">
- <q-input @keyup.enter="larryLogin" :error="authError !== undefined" v-model="email" name="user" float-label="Email" />
- <q-input @keyup.enter="larryLogin" :error="authError !== undefined" v-model="password" name="pass" type="password" float-label="Password" />
- <q-btn color="positive" @click="larryLogin" icon="fa-sign-in">Larry login</q-btn>
- </div>
- <div class="text-right">
- <q-btn color="tertiary" small outline @click="useLarryLogin = false">Log in via Clonkspot</q-btn>
- </div>
- </div>
- <div v-else class="group">
- <q-btn color="positive" @click="clonkspotLogin">Log in via Clonkspot</q-btn>
- <p class="text-negative" v-if="authFailed">Oups, something went wrong. Please try again</p>
- <div class="text-right">
- <q-btn color="tertiary" small outline @click="useLarryLogin = true">Log in via Larry</q-btn>
+ <q-input @keyup.enter="parryLogin" :error="authError !== undefined" v-model="username" name="user" float-label="Username" />
+ <q-input @keyup.enter="parryLogin" :error="authError !== undefined" v-model="password" name="pass" type="password" float-label="Password" />
+ <q-btn color="positive" @click="parryLogin" icon="fa-sign-in">Parry login</q-btn>
</div>
</div>
</div>
@@ -41,18 +31,17 @@
<script>
import {
- openURL,
LocalStorage,
} from 'quasar'
export default {
data () {
return {
- email: '',
+ username: '',
password: '',
authError: undefined,
token: null,
- useLarryLogin: false,
+ useParryLogin: true,
authWindow: null,
authFailed: false,
}
@@ -64,23 +53,18 @@
}
},
methods: {
- clonkspotLogin () {
- this.authWindow = openURL(`${this.$http.defaults.baseURL}/auth/clonkspot`)
- this.checkTokenLoop()
- },
- larryLogin () {
+ parryLogin () {
let that = this
let params = {
- user: {
- email: this.email,
- password: this.password,
- }
+ username: this.username,
+ password: this.password,
}
this.authError = undefined
- this.$http.post('/auth/login', params).then((response) => {
- that.$store.commit('user/setAuthToken', { authToken: response.data.user.token })
- that.email = ''
+ this.$http.post('/auth', params).then((response) => {
+ that.$store.commit('user/setAuthToken', { authToken: response.data.token })
+ that.username = ''
that.password = ''
+ setTimeout(() => this.$store.commit('user/logout'), Math.max(parseInt(response.data.expires) - Math.floor(Date.now() / 1000), 0) * 1000)
}).catch((error) => {
if (error.response && error.response.data) {
that.authError = error.response.data.errors
diff --git a/src/components/CommentVoter.vue b/src/components/CommentVoter.vue
index 4747571..ccb9e55 100644
--- a/src/components/CommentVoter.vue
+++ b/src/components/CommentVoter.vue
@@ -49,7 +49,7 @@
methods: {
vote (impact) {
let that = this
- this.$http.post(`/uploads/${this.comment.upload}/comments/${this.comment._id}/vote`, {impact: impact}).then(response => that.$emit('voted'))
+ this.$http.post(`/uploads/${this.comment.upload}/comments/${this.comment.id}/vote`, {impact: impact}).then(response => that.$emit('voted'))
},
},
}
diff --git a/src/components/UploadVoter.vue b/src/components/UploadVoter.vue
index e5d18ae..b929a45 100644
--- a/src/components/UploadVoter.vue
+++ b/src/components/UploadVoter.vue
@@ -45,16 +45,17 @@
},
computed: {
myVote () {
- if (!this.upload || !this.upload.voting || !Array.isArray(this.upload.voting.votes) || this.upload.voting.votes.length === 0) {
- return undefined
+ if (!this.upload.voting.vote) {
+ let that = this
+ this.$http.get(`/uploads/${this.upload.id}/vote`).then((response) => { this.upload.voting.vote = response.data })
}
- return this.upload.voting.votes[0]
+ return this.upload.voting.vote
},
},
methods: {
vote (impact) {
let that = this
- this.$http.post(`/uploads/${this.upload._id}/vote`, {impact: impact}).then(response => that.$emit('voted'))
+ this.$http.post(`/uploads/${this.upload.id}/vote`, {impact: impact}).then(response => that.$emit('voted'))
},
},
}