diff --git a/server/go.mod b/server/go.mod index 86ed53b7..9eb70338 100644 --- a/server/go.mod +++ b/server/go.mod @@ -24,7 +24,10 @@ require ( gorm.io/gorm v1.25.2 ) -require github.com/go-gormigrate/gormigrate/v2 v2.1.0 +require ( + github.com/go-gormigrate/gormigrate/v2 v2.1.0 + golang.org/x/oauth2 v0.10.0 +) require ( github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect @@ -63,7 +66,6 @@ require ( golang.org/x/arch v0.3.0 // indirect golang.org/x/image v0.0.0-20220302094943-723b81ca9867 // indirect golang.org/x/net v0.12.0 // indirect - golang.org/x/oauth2 v0.10.0 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/text v0.11.0 // indirect diff --git a/server/internal/sys/api/account.go b/server/internal/sys/api/account.go index b3654924..f1b4aa27 100644 --- a/server/internal/sys/api/account.go +++ b/server/internal/sys/api/account.go @@ -120,7 +120,7 @@ func useOtp(account *entity.Account, otpIssuer, accessToken string) (*OtpVerifyI otpStatus := OtpStatusReg otpUrl := "" // 该token用于otp双因素校验 - token := utils.RandString(32) + token := stringx.Rand(32) // 未注册otp secret或重置了秘钥 if otpSecret == "" || otpSecret == "-" { otpStatus = OtpStatusNoReg @@ -140,7 +140,7 @@ func useOtp(account *entity.Account, otpIssuer, accessToken string) (*OtpVerifyI OtpSecret: otpSecret, AccessToken: accessToken, } - cache.SetStr(fmt.Sprintf("otp:token:%s", token), utils.ToJsonStr(otpInfo), time.Minute*time.Duration(3)) + cache.SetStr(fmt.Sprintf("otp:token:%s", token), jsonx.ToStr(otpInfo), time.Minute*time.Duration(3)) return otpInfo, otpUrl, token } diff --git a/server/internal/sys/api/auth.go b/server/internal/sys/api/auth.go index 39cebba9..d1e3e7dd 100644 --- a/server/internal/sys/api/auth.go +++ b/server/internal/sys/api/auth.go @@ -18,7 +18,7 @@ import ( "mayfly-go/pkg/global" "mayfly-go/pkg/model" "mayfly-go/pkg/req" - "mayfly-go/pkg/utils" + "mayfly-go/pkg/utils/stringx" "net/http" "strconv" "strings" @@ -53,7 +53,7 @@ func (a *Auth) OAuth2Login(rc *req.Ctx) { biz.ErrIsNil(err, "获取oauth2 client失败: "+err.Error()) return } - state := utils.RandString(32) + state := stringx.Rand(32) cache.SetStr("oauth2:state:"+state, "login", 5*time.Minute) rc.GinCtx.Redirect(http.StatusFound, client.AuthCodeURL(state)) } @@ -155,7 +155,7 @@ func (a *Auth) OAuth2Callback(rc *req.Ctx) { } // 进行登录 account := &entity.Account{ - Model: model.Model{Id: accountId}, + Model: model.Model{DeletedModel: model.DeletedModel{Id: accountId}}, } if err := a.AccountApp.GetAccount(account, "Id", "Name", "Username", "Password", "Status", "LastLoginTime", "LastLoginIp", "OtpSecret"); err != nil { biz.ErrIsNil(err, "获取用户信息失败: "+err.Error()) @@ -305,7 +305,7 @@ func (a *Auth) OAuth2Bind(rc *req.Ctx) { biz.ErrIsNil(err, "获取oauth2 client失败: "+err.Error()) return } - state := utils.RandString(32) + state := stringx.Rand(32) cache.SetStr("oauth2:state:"+state, "bind:"+strconv.FormatUint(rc.LoginAccount.Id, 10), 5*time.Minute) rc.GinCtx.Redirect(http.StatusFound, client.AuthCodeURL(state)) diff --git a/server/internal/sys/domain/entity/auth.go b/server/internal/sys/domain/entity/auth.go index ead405ef..c558ab06 100644 --- a/server/internal/sys/domain/entity/auth.go +++ b/server/internal/sys/domain/entity/auth.go @@ -1,9 +1,12 @@ package entity -import "time" +import ( + "mayfly-go/pkg/model" + "time" +) type OAuthAccount struct { - Id uint64 `json:"id"` + model.DeletedModel AccountId uint64 `json:"accountId" gorm:"column:account_id;index:account_id,unique"` Identity string `json:"identity" gorm:"column:identity;index:identity,unique"` diff --git a/server/migrations/20230720.go b/server/migrations/20230720.go index 7d2208e9..402f0563 100644 --- a/server/migrations/20230720.go +++ b/server/migrations/20230720.go @@ -18,13 +18,13 @@ func T20230720() *gormigrate.Migration { now := time.Now() res := &entity.Resource{ Model: model.Model{ - Id: 130, - CreateTime: &now, - CreatorId: 1, - Creator: "admin", - UpdateTime: &now, - ModifierId: 1, - Modifier: "admin", + DeletedModel: model.DeletedModel{Id: 130}, + CreateTime: &now, + CreatorId: 1, + Creator: "admin", + UpdateTime: &now, + ModifierId: 1, + Modifier: "admin", }, Pid: 4, UiPath: "sys/auth", @@ -42,13 +42,13 @@ func T20230720() *gormigrate.Migration { } res = &entity.Resource{ Model: model.Model{ - Id: 131, - CreateTime: &now, - CreatorId: 1, - Creator: "admin", - UpdateTime: &now, - ModifierId: 1, - Modifier: "admin", + DeletedModel: model.DeletedModel{Id: 131}, + CreateTime: &now, + CreatorId: 1, + Creator: "admin", + UpdateTime: &now, + ModifierId: 1, + Modifier: "admin", }, Pid: 130, UiPath: "sys/auth/base",