feat: hide some parts of jwt secret and node secret

This commit is contained in:
Jacky 2024-07-24 10:31:25 +08:00
parent 45a136380d
commit 2b6e84ab62
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
19 changed files with 637 additions and 403 deletions

View file

@ -1,12 +1,15 @@
package model
import "gorm.io/gorm"
type Auth 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"`
Enabled2FA bool `json:"enabled_2fa" gorm:"-"`
}
type AuthToken struct {
@ -15,6 +18,11 @@ type AuthToken struct {
ExpiredAt int64 `json:"expired_at" gorm:"default:0"`
}
func (u *Auth) AfterFind(tx *gorm.DB) error {
u.Enabled2FA = u.EnabledOTP()
return nil
}
func (u *Auth) EnabledOTP() bool {
return len(u.OTPSecret) != 0
}