mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
feat: new recovery codes
This commit is contained in:
parent
3738bebca7
commit
0d1f56a43e
24 changed files with 1882 additions and 713 deletions
|
@ -1,19 +1,33 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/spf13/cast"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type RecoveryCode struct {
|
||||
Code string `json:"code"`
|
||||
UsedTime *time.Time `json:"used_time,omitempty" gorm:"type:datetime;default:null"`
|
||||
}
|
||||
|
||||
type RecoveryCodes struct {
|
||||
Codes []RecoveryCode `json:"codes"`
|
||||
LastViewed *time.Time `json:"last_viewed,omitempty" gorm:"type:datetime;default:null"`
|
||||
LastDownloaded *time.Time `json:"last_downloaded,omitempty" gorm:"type:datetime;default:null"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Model
|
||||
|
||||
Name string `json:"name" cosy:"add:max=20;update:omitempty,max=20;list:fussy;db_unique"`
|
||||
Password string `json:"-" cosy:"json:password;add:required,max=20;update:omitempty,max=20"`
|
||||
Status bool `json:"status" gorm:"default:1"`
|
||||
OTPSecret []byte `json:"-" gorm:"type:blob"`
|
||||
EnabledTwoFA bool `json:"enabled_2fa" gorm:"-"`
|
||||
Name string `json:"name" cosy:"add:max=20;update:omitempty,max=20;list:fussy;db_unique"`
|
||||
Password string `json:"-" cosy:"json:password;add:required,max=20;update:omitempty,max=20"`
|
||||
Status bool `json:"status" gorm:"default:1"`
|
||||
OTPSecret []byte `json:"-" gorm:"type:blob"`
|
||||
RecoveryCodes RecoveryCodes `json:"-" gorm:"serializer:json"`
|
||||
EnabledTwoFA bool `json:"enabled_2fa" gorm:"-"`
|
||||
}
|
||||
|
||||
type AuthToken struct {
|
||||
|
@ -35,6 +49,14 @@ func (u *User) EnabledOTP() bool {
|
|||
return len(u.OTPSecret) != 0
|
||||
}
|
||||
|
||||
func (u *User) RecoveryCodeGenerated() bool {
|
||||
return len(u.RecoveryCodes.Codes) > 0
|
||||
}
|
||||
|
||||
func (u *User) RecoveryCodeViewed() bool {
|
||||
return u.RecoveryCodes.LastViewed != nil
|
||||
}
|
||||
|
||||
func (u *User) EnabledPasskey() bool {
|
||||
var passkeys Passkey
|
||||
db.Where("user_id", u.ID).Limit(1).Find(&passkeys)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue