mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
feat: 2fa via passkey
This commit is contained in:
parent
bdfbbd0e8f
commit
0a6a7693a1
21 changed files with 384 additions and 218 deletions
|
@ -3,17 +3,15 @@ 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"`
|
||||
Enabled2FA bool `json:"enabled_2fa" gorm:"-"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"-"`
|
||||
Status bool `json:"status" gorm:"default:1"`
|
||||
OTPSecret []byte `json:"-" gorm:"type:blob"`
|
||||
}
|
||||
|
||||
type AuthToken struct {
|
||||
|
@ -26,15 +24,20 @@ func (u *User) TableName() string {
|
|||
return "auths"
|
||||
}
|
||||
|
||||
func (u *User) AfterFind(_ *gorm.DB) error {
|
||||
u.Enabled2FA = u.EnabledOTP()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *User) EnabledOTP() bool {
|
||||
return len(u.OTPSecret) != 0
|
||||
}
|
||||
|
||||
func (u *User) EnabledPasskey() bool {
|
||||
var passkeys Passkey
|
||||
db.Where("user_id", u.ID).First(&passkeys)
|
||||
return passkeys.ID != 0
|
||||
}
|
||||
|
||||
func (u *User) Enabled2FA() bool {
|
||||
return u.EnabledOTP() || u.EnabledPasskey()
|
||||
}
|
||||
|
||||
func (u *User) WebAuthnID() []byte {
|
||||
return []byte(cast.ToString(u.ID))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue