diff options
Diffstat (limited to 'src/components/ApiAuth.vue')
| -rw-r--r-- | src/components/ApiAuth.vue | 46 |
1 files changed, 15 insertions, 31 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 |
