mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
enhance(wip): error handle
This commit is contained in:
parent
3f95ae5d90
commit
650196d06a
93 changed files with 5228 additions and 3738 deletions
15
internal/user/errors.go
Normal file
15
internal/user/errors.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package user
|
||||
|
||||
import "github.com/uozi-tech/cosy"
|
||||
|
||||
var (
|
||||
e = cosy.NewErrorScope("user")
|
||||
ErrPasswordIncorrect = e.New(40301, "password incorrect")
|
||||
ErrUserBanned = e.New(40303, "user banned")
|
||||
ErrOTPCode = e.New(40304, "invalid otp code")
|
||||
ErrRecoveryCode = e.New(40305, "invalid recovery code")
|
||||
ErrWebAuthnNotConfigured = e.New(50000, "WebAuthn settings are not configured")
|
||||
ErrUserNotEnabledOTPAs2FA = e.New(50001, "user not enabled otp as 2fa")
|
||||
ErrOTPOrRecoveryCodeEmpty = e.New(50002, "otp or recovery code empty")
|
||||
ErrSessionNotFound = e.New(40401, "session not found")
|
||||
)
|
|
@ -1,7 +1,6 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
|
@ -9,11 +8,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrPasswordIncorrect = errors.New("password incorrect")
|
||||
ErrUserBanned = errors.New("user banned")
|
||||
)
|
||||
|
||||
func Login(name string, password string) (user *model.User, err error) {
|
||||
u := query.User
|
||||
|
||||
|
|
|
@ -9,16 +9,10 @@ import (
|
|||
"github.com/0xJacky/Nginx-UI/internal/crypto"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrOTPCode = errors.New("invalid otp code")
|
||||
ErrRecoveryCode = errors.New("invalid recovery code")
|
||||
)
|
||||
|
||||
func VerifyOTP(user *model.User, otp, recoveryCode string) (err error) {
|
||||
if otp != "" {
|
||||
decrypted, err := crypto.AesDecrypt(user.OTPSecret)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue