Merge branch 'feature/failed-login-error' into 'develop'
Visual feedback on failed login See merge request !49
This commit is contained in:
commit
ba4f7ef3ef
@ -1,13 +1,21 @@
|
|||||||
const LoginForm = {
|
const LoginForm = {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
user: {}
|
user: {},
|
||||||
|
authError: false
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
loggingIn () { return this.$store.state.users.loggingIn }
|
loggingIn () { return this.$store.state.users.loggingIn }
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
submit () {
|
submit () {
|
||||||
this.$store.dispatch('loginUser', this.user)
|
this.$store.dispatch('loginUser', this.user).then(
|
||||||
|
() => { this.$router.push('/main/friends')},
|
||||||
|
(error) => {
|
||||||
|
this.authError = error
|
||||||
|
this.user.username = ''
|
||||||
|
this.user.password = ''
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
<div class='form-group'>
|
<div class='form-group'>
|
||||||
<button :disabled="loggingIn" type='submit' class='btn btn-default base05 base01-background'>Submit</button>
|
<button :disabled="loggingIn" type='submit' class='btn btn-default base05 base01-background'>Submit</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="authError" class='form-group'>
|
||||||
|
<div class='error base05'>{{authError}}</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -39,6 +42,14 @@
|
|||||||
margin-top: 1.0em;
|
margin-top: 1.0em;
|
||||||
min-height: 28px;
|
min-height: 28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
border-radius: 5px;
|
||||||
|
text-align: center;
|
||||||
|
background-color: rgba(255, 48, 16, 0.65);
|
||||||
|
min-height: 28px;
|
||||||
|
line-height: 28px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
@ -67,6 +67,7 @@ const users = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
loginUser (store, userCredentials) {
|
loginUser (store, userCredentials) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
const commit = store.commit
|
const commit = store.commit
|
||||||
commit('beginLogin')
|
commit('beginLogin')
|
||||||
store.rootState.api.backendInteractor.verifyCredentials(userCredentials)
|
store.rootState.api.backendInteractor.verifyCredentials(userCredentials)
|
||||||
@ -94,12 +95,23 @@ const users = {
|
|||||||
store.rootState.api.backendInteractor.fetchFriends()
|
store.rootState.api.backendInteractor.fetchFriends()
|
||||||
.then((friends) => commit('addNewUsers', friends))
|
.then((friends) => commit('addNewUsers', friends))
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
// Authentication failed
|
||||||
|
commit('endLogin')
|
||||||
|
if (response.status === 401) {
|
||||||
|
reject('Wrong username or password')
|
||||||
|
} else {
|
||||||
|
reject('An error occurred, please try again')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
commit('endLogin')
|
commit('endLogin')
|
||||||
|
resolve()
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
commit('endLogin')
|
commit('endLogin')
|
||||||
|
reject('Failed to connect to server, try again')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user