warn about wrong credentials, fix #9

This commit is contained in:
Jonathan Baecker 2020-05-12 18:07:53 +02:00
parent 439c0ec4c8
commit bd4b354f86
2 changed files with 25 additions and 8 deletions

View File

@ -8,18 +8,24 @@
<h1>ffplayout</h1>
</div>
<b-form class="login-form" @submit.prevent="login">
<p v-if="formError" class="error">
{{ formError }}
</p>
<b-form-group id="input-group-1" label="User:" label-for="input-user">
<b-form-input id="input-user" v-model="formUsername" type="text" required placeholder="Username" />
</b-form-group>
<b-form-group id="input-group-1" label="Password:" label-for="input-pass">
<b-form-input id="input-pass" v-model="formPassword" type="password" required placeholder="Password" />
</b-form-group>
<b-button type="submit" variant="primary">
Login
</b-button>
<b-row>
<b-col cols="3">
<b-button type="submit" variant="primary">
Login
</b-button>
</b-col>
<b-col cols="9">
<b-alert variant="danger" :show="showError" dismissible @dismissed="showError=false">
{{ formError }}
</b-alert>
</b-col>
</b-row>
</b-form>
</div>
</b-container>
@ -160,6 +166,7 @@ export default {
data () {
return {
showError: false,
formError: null,
formUsername: '',
formPassword: '',
@ -180,7 +187,7 @@ export default {
},
async login () {
try {
await this.$store.dispatch('auth/obtainToken', {
const status = await this.$store.dispatch('auth/obtainToken', {
username: this.formUsername,
password: this.formPassword
})
@ -188,6 +195,11 @@ export default {
this.formPassword = ''
this.formError = null
if (status === 401) {
this.formError = 'Wrong user or password!'
this.showError = true
}
this.checkLogin()
} catch (e) {
this.formError = e.message

View File

@ -33,6 +33,7 @@ export const actions = {
username,
password
}
let code = null
await this.$axios.post('auth/token/', payload)
.then((response) => {
commit('UPADTE_TOKEN', { token: response.data.access, refresh: response.data.refresh })
@ -47,10 +48,14 @@ export const actions = {
maxAge: 60 * 60 * 24 * 365,
sameSite: 'lax'
})
code = response.status
})
.catch((error) => {
console.log(error)
code = error.response.status
})
return code
},
async refreshToken ({ commit, state }) {
const payload = {