TOTP (#109)
Fix not telling the user about invalid totp passcodes when logging in Add disabling totp authentication Add totp passcode when logging in Add totp settings Add general post method function Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/109
This commit is contained in:
parent
a75670e4f0
commit
99c10d49be
7 changed files with 220 additions and 31 deletions
|
|
@ -11,13 +11,19 @@ export default {
|
|||
infos: {},
|
||||
},
|
||||
|
||||
login(context, creds, redirect) {
|
||||
login(context, credentials, redirect = '') {
|
||||
localStorage.removeItem('token') // Delete an eventually preexisting old token
|
||||
|
||||
HTTP.post('login', {
|
||||
username: creds.username,
|
||||
password: creds.password
|
||||
})
|
||||
const data = {
|
||||
username: credentials.username,
|
||||
password: credentials.password
|
||||
}
|
||||
|
||||
if(credentials.totpPasscode) {
|
||||
data.totp_passcode = credentials.totpPasscode
|
||||
}
|
||||
|
||||
HTTP.post('login', data)
|
||||
.then(response => {
|
||||
// Save the token to local storage for later use
|
||||
localStorage.setItem('token', response.data.token)
|
||||
|
|
@ -25,28 +31,28 @@ export default {
|
|||
// Tell others the user is autheticated
|
||||
this.user.authenticated = true
|
||||
this.user.isLinkShareAuth = false
|
||||
const inf = this.getUserInfos()
|
||||
// eslint-disable-next-line
|
||||
console.log(inf)
|
||||
|
||||
// Hide the loader
|
||||
context.loading = false
|
||||
|
||||
// Redirect if nessecary
|
||||
if (redirect) {
|
||||
if (redirect !== '') {
|
||||
router.push({name: redirect})
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
// Hide the loader
|
||||
context.loading = false
|
||||
if (e.response) {
|
||||
if (e.response.data.code === 1017 && !credentials.totpPasscode) {
|
||||
context.needsTotpPasscode = true
|
||||
return
|
||||
}
|
||||
|
||||
context.errorMsg = e.response.data.message
|
||||
if (e.response.status === 401) {
|
||||
context.errorMsg = 'Wrong username or password.'
|
||||
}
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
context.loading = false
|
||||
})
|
||||
},
|
||||
|
||||
register(context, creds, redirect) {
|
||||
|
|
|
|||
Reference in a new issue