Don't try to make a request to get the totp status if its disabled
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kolaente 2020-06-15 10:44:47 +02:00
parent 0720f644d0
commit f10eaf9b28
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 82 additions and 31 deletions

View File

@ -1,5 +1,7 @@
<template>
<div class="loader-container" :class="{ 'is-loading': passwordUpdateService.loading || emailUpdateService.loading || totpService.loading }">
<div
class="loader-container"
:class="{ 'is-loading': passwordUpdateService.loading || emailUpdateService.loading || totpService.loading }">
<div class="card">
<header class="card-header">
<p class="card-header-title">
@ -12,22 +14,37 @@
<div class="field">
<label class="label" for="newPassword">New Password</label>
<div class="control">
<input class="input" type="password" id="newPassword" placeholder="The new password..."
v-model="passwordUpdate.newPassword" @keyup.enter="updatePassword"/>
<input
class="input"
type="password"
id="newPassword"
placeholder="The new password..."
v-model="passwordUpdate.newPassword"
@keyup.enter="updatePassword"/>
</div>
</div>
<div class="field">
<label class="label" for="newPasswordConfirm">New Password Confirmation</label>
<div class="control">
<input class="input" type="password" id="newPasswordConfirm" placeholder="Confirm your new password..."
v-model="passwordConfirm" @keyup.enter="updatePassword"/>
<input
class="input"
type="password"
id="newPasswordConfirm"
placeholder="Confirm your new password..."
v-model="passwordConfirm"
@keyup.enter="updatePassword"/>
</div>
</div>
<div class="field">
<label class="label" for="currentPassword">Current Password</label>
<div class="control">
<input class="input" type="password" id="currentPassword" placeholder="Your current password"
v-model="passwordUpdate.oldPassword" @keyup.enter="updatePassword"/>
<input
class="input"
type="password"
id="currentPassword"
placeholder="Your current password"
v-model="passwordUpdate.oldPassword"
@keyup.enter="updatePassword"/>
</div>
</div>
</form>
@ -53,15 +70,25 @@
<div class="field">
<label class="label" for="newEmail">New Email Address</label>
<div class="control">
<input class="input" type="email" id="newEmail" placeholder="The new email address..."
v-model="emailUpdate.newEmail" @keyup.enter="updateEmail"/>
<input
class="input"
type="email"
id="newEmail"
placeholder="The new email address..."
v-model="emailUpdate.newEmail"
@keyup.enter="updateEmail"/>
</div>
</div>
<div class="field">
<label class="label" for="currentPassword">Current Password</label>
<div class="control">
<input class="input" type="password" id="currentPassword" placeholder="Your current password"
v-model="emailUpdate.password" @keyup.enter="updateEmail"/>
<input
class="input"
type="password"
id="currentPassword"
placeholder="Your current password"
v-model="emailUpdate.password"
@keyup.enter="updateEmail"/>
</div>
</div>
</form>
@ -82,10 +109,17 @@
</p>
</header>
<div class="card-content">
<a class="button is-primary" v-if="!totpEnrolled && totp.secret === ''" @click="totpEnroll()" :class="{ 'is-loading': totpService.loading }">Enroll</a>
<a
class="button is-primary"
v-if="!totpEnrolled && totp.secret === ''"
@click="totpEnroll()"
:class="{ 'is-loading': totpService.loading }">
Enroll
</a>
<div class="content" v-else-if="totp.secret !== '' && !totp.enabled">
<p>
To finish your setup, use this secret in your totp app (Google Authenticator or similar): <strong>{{ totp.secret }}</strong><br/>
To finish your setup, use this secret in your totp app (Google Authenticator or similar):
<strong>{{ totp.secret }}</strong><br/>
After that, enter a code from your app below.
</p>
<p>
@ -95,8 +129,13 @@
<div class="field">
<label class="label" for="totpConfirmPasscode">Passcode</label>
<div class="control">
<input class="input" type="text" id="totpConfirmPasscode" placeholder="A code generated by your totp application"
v-model="totpConfirmPasscode" @keyup.enter="totpConfirm()"/>
<input
class="input"
type="text"
id="totpConfirmPasscode"
placeholder="A code generated by your totp application"
v-model="totpConfirmPasscode"
@keyup.enter="totpConfirm()"/>
</div>
</div>
<a class="button is-primary" @click="totpConfirm()">Confirm</a>
@ -112,8 +151,14 @@
<div class="field">
<label class="label" for="currentPassword">Please Enter Your Password</label>
<div class="control">
<input class="input" type="password" id="currentPassword" placeholder="Your current password"
v-model="totpDisablePassword" @keyup.enter="totpDisable" v-focus/>
<input
class="input"
type="password"
id="currentPassword"
placeholder="Your current password"
v-model="totpDisablePassword"
@keyup.enter="totpDisable"
v-focus/>
</div>
</div>
<a class="button is-danger" @click="totpDisable()">Disable two factor authentication</a>
@ -164,20 +209,7 @@
this.totpService = new TotpService()
this.totp = new TotpModel()
this.totpService.get()
.then(r => {
this.$set(this, 'totp', r)
this.totpSetQrCode()
})
.catch(e => {
// Error code 1016 means totp is not enabled, we don't need an error in that case.
if (e.response && e.response.data && e.response.data.code && e.response.data.code === 1016) {
this.totpEnrolled = false
return
}
this.error(e, this)
})
this.totpStatus()
},
computed: mapState({
totpEnabled: state => state.config.totpEnabled
@ -202,6 +234,25 @@
})
.catch(e => this.error(e, this))
},
totpStatus() {
if (!this.totpEnabled) {
return
}
this.totpService.get()
.then(r => {
this.$set(this, 'totp', r)
this.totpSetQrCode()
})
.catch(e => {
// Error code 1016 means totp is not enabled, we don't need an error in that case.
if (e.response && e.response.data && e.response.data.code && e.response.data.code === 1016) {
this.totpEnrolled = false
return
}
this.error(e, this)
})
},
totpSetQrCode() {
this.totpService.qrcode()
.then(qr => {