Skip to content

Commit

Permalink
fix: incorrect status of enabled 2fa of user #577
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Sep 26, 2024
1 parent f2a586c commit 2f70703
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
18 changes: 12 additions & 6 deletions app/src/views/environment/Environment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ function batchUpgrade() {

<BatchUpgrader ref="refUpgrader" />

<FooterToolBar v-if="selectedNodes?.length > 0">
<AButton
type="primary"
@click="batchUpgrade"
<FooterToolBar>
<ATooltip
:title="$gettext('Please select at least one node to upgrade')"
placement="topLeft"
>
{{ $gettext('Upgrade') }}
</AButton>
<AButton
:disabled="selectedNodeIds.length === 0"
type="primary"
@click="batchUpgrade"
>
{{ $gettext('Upgrade') }}
</AButton>
</ATooltip>
</FooterToolBar>
</div>
</template>
Expand Down
2 changes: 1 addition & 1 deletion app/src/views/other/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ async function handlePasskeyLogin() {
:two-f-a-status="{
enabled: true,
otp_status: true,
passkey_status: true,
passkey_status: false,
}"
@submit-o-t-p="handleOTPSubmit"
/>
Expand Down
7 changes: 7 additions & 0 deletions internal/cert/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func (c *ConfigPayload) mkCertificateDir() (err error) {
}
}

if _, err = os.Stat(c.CertificateDir); os.IsNotExist(err) {
err = os.MkdirAll(c.CertificateDir, 0755)
if err == nil {
return nil
}
}

// For windows, replace * with # (issue #403)
c.CertificateDir = strings.ReplaceAll(c.CertificateDir, "*", "#")
if _, err = os.Stat(c.CertificateDir); os.IsNotExist(err) {
Expand Down
15 changes: 11 additions & 4 deletions model/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package model
import (
"github.com/go-webauthn/webauthn/webauthn"
"github.com/spf13/cast"
"gorm.io/gorm"
)

type User struct {
Model

Name string `json:"name"`
Password string `json:"-"`
Status bool `json:"status" gorm:"default:1"`
OTPSecret []byte `json:"-" gorm:"type:blob"`
Name string `json:"name"`
Password string `json:"-"`
Status bool `json:"status" gorm:"default:1"`
OTPSecret []byte `json:"-" gorm:"type:blob"`
EnabledTwoFA bool `json:"enabled_2fa" gorm:"-"`
}

type AuthToken struct {
Expand All @@ -24,6 +26,11 @@ func (u *User) TableName() string {
return "auths"
}

func (u *User) AfterFind(_ *gorm.DB) error {
u.EnabledTwoFA = u.Enabled2FA()
return nil
}

func (u *User) EnabledOTP() bool {
return len(u.OTPSecret) != 0
}
Expand Down

0 comments on commit 2f70703

Please sign in to comment.