From b43b5dbd592c77d9ccec0586ee190bc52c7de248 Mon Sep 17 00:00:00 2001
From: eson <9673575+githubcontent@user.noreply.gitee.com>
Date: Mon, 24 Jul 2023 19:17:02 +0800
Subject: [PATCH] fix
---
server/auth/internal/handler/routes.go | 6 +-
.../auth/internal/logic/acceptcookielogic.go | 13 +-
.../internal/logic/email_manager.go | 1 -
.../test/acceptcookielogic_test.go | 4 +-
server/auth/test/basic.go | 40 ++++
server/backend/test/basic.go | 5 +-
.../backend/test/quotationdetaillogic_test.go | 2 +-
server/home-user-auth/etc/home-user-auth.yaml | 1 +
server/home-user-auth/home-user-auth_test.go | 1 -
.../home-user-auth/internal/config/config.go | 12 --
.../internal/handler/acceptcookiehandler.go | 35 ----
.../internal/logic/acceptcookielogic.go | 45 -----
.../internal/logic/usergoogleloginlogic.go | 176 ------------------
.../internal/logic/userloginlogic.go | 84 ---------
server/home-user-auth/internal/types/types.go | 8 -
server/home-user-auth/test/basic.go | 3 +
.../test/useraddaddresslogic_test.go | 6 +-
.../test/useraddresslistlogic_test.go | 4 +-
.../test/userbasicinfologic_test.go | 4 +-
.../test/usercontactservicelogic_test.go | 4 +-
.../test/userfontslogic_test.go | 4 +-
.../test/usergettypelogic_test.go | 4 +-
.../test/useroderdeletelogic_test.go | 4 +-
.../test/usersavebasicinfologic_test.go | 8 +-
.../test/userstatusconfiglogic_test.go | 4 +-
server/upload/test/basic.go | 5 +-
.../test/uploadfilebackendhandler_test.go | 2 +-
.../test/uploadfilefrontendhandler_test.go | 4 +-
server/webset/test/basic.go | 5 +-
server/webset/test/webset_test.go | 2 +-
server_api/auth.api | 6 +-
server_api/home-user-auth.api | 2 -
utils/fstests/basic.go | 20 +-
33 files changed, 109 insertions(+), 415 deletions(-)
rename server/{home-user-auth => auth}/internal/logic/email_manager.go (98%)
rename server/{home-user-auth => auth}/test/acceptcookielogic_test.go (88%)
create mode 100644 server/auth/test/basic.go
delete mode 100644 server/home-user-auth/internal/handler/acceptcookiehandler.go
delete mode 100644 server/home-user-auth/internal/logic/acceptcookielogic.go
delete mode 100644 server/home-user-auth/internal/logic/usergoogleloginlogic.go
delete mode 100644 server/home-user-auth/internal/logic/userloginlogic.go
diff --git a/server/auth/internal/handler/routes.go b/server/auth/internal/handler/routes.go
index 3e951654..3e36c76e 100644
--- a/server/auth/internal/handler/routes.go
+++ b/server/auth/internal/handler/routes.go
@@ -19,17 +19,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
- Path: "/api/user/accept-cookie",
+ Path: "/api/auth/accept-cookie",
Handler: AcceptCookieHandler(serverCtx),
},
{
Method: http.MethodGet,
- Path: "/api/user/oauth2/login/google",
+ Path: "/api/auth/oauth2/login/google",
Handler: UserGoogleLoginHandler(serverCtx),
},
{
Method: http.MethodGet,
- Path: "/api/user/oauth2/login/register",
+ Path: "/api/auth/oauth2/login/register",
Handler: UserEmailRegisterHandler(serverCtx),
},
},
diff --git a/server/auth/internal/logic/acceptcookielogic.go b/server/auth/internal/logic/acceptcookielogic.go
index 730bd493..aa57d085 100644
--- a/server/auth/internal/logic/acceptcookielogic.go
+++ b/server/auth/internal/logic/acceptcookielogic.go
@@ -38,6 +38,17 @@ func NewAcceptCookieLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Acce
func (l *AcceptCookieLogic) AcceptCookie(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
+ idtyp := userinfo.GetIdType()
+ if idtyp == auth.IDTYPE_Guest {
+ return resp.SetStatus(basic.CodeGuestDupErr)
+ }
- return resp.SetStatus(basic.CodeOK)
+ m := l.svcCtx.AllModels.FsGuest
+ token, err := m.GenerateGuestID(l.ctx, &l.svcCtx.Config.Auth.AccessSecret)
+ if err != nil {
+ return resp.SetStatus(basic.CodeGuestGenErr)
+ }
+ return resp.SetStatus(basic.CodeOK, types.DataGuest{
+ Token: token,
+ })
}
diff --git a/server/home-user-auth/internal/logic/email_manager.go b/server/auth/internal/logic/email_manager.go
similarity index 98%
rename from server/home-user-auth/internal/logic/email_manager.go
rename to server/auth/internal/logic/email_manager.go
index 60e600af..63f6060d 100644
--- a/server/home-user-auth/internal/logic/email_manager.go
+++ b/server/auth/internal/logic/email_manager.go
@@ -49,7 +49,6 @@ func (m *EmailSender) ProcessEmailTasks() {
}
m.lock.Unlock()
- // TODO: Replace with actual email content
content := []byte("Hello, this is a test email")
err := smtp.SendMail(emailTarget, m.Auth, m.FromEmail, []string{emailTarget}, content)
if err != nil {
diff --git a/server/home-user-auth/test/acceptcookielogic_test.go b/server/auth/test/acceptcookielogic_test.go
similarity index 88%
rename from server/home-user-auth/test/acceptcookielogic_test.go
rename to server/auth/test/acceptcookielogic_test.go
index 64af9e82..13cd97c2 100644
--- a/server/home-user-auth/test/acceptcookielogic_test.go
+++ b/server/auth/test/acceptcookielogic_test.go
@@ -1,4 +1,4 @@
-package homeuserauthtest
+package authtest
import (
"fmt"
@@ -19,7 +19,7 @@ func TestAcceptCookieLogic(t *testing.T) {
ses := fstests.GetSesssion()
// 向服务器发送 GET 请求,获取 cookie 信息
- resp, err = ses.Post(fmt.Sprintf("http://%s:%d/user/accept-cookie", cnf.Host, cnf.Port)).TestExecute(gserver)
+ resp, err = ses.Post(fmt.Sprintf("http://%s:%d/api/auth/accept-cookie", cnf.Host, cnf.Port)).TestExecute(gserver)
if err != nil {
t.Error(err)
}
diff --git a/server/auth/test/basic.go b/server/auth/test/basic.go
new file mode 100644
index 00000000..b79cca75
--- /dev/null
+++ b/server/auth/test/basic.go
@@ -0,0 +1,40 @@
+package authtest
+
+import (
+ "fmt"
+ "fusenapi/server/auth/internal/config"
+ "fusenapi/server/auth/internal/handler"
+ "fusenapi/server/auth/internal/svc"
+ "fusenapi/utils/fstests"
+ "log"
+ "runtime"
+
+ "github.com/zeromicro/go-zero/core/conf"
+ "github.com/zeromicro/go-zero/rest"
+)
+
+var cnf config.Config
+var gserver *rest.Server
+
+func init() {
+ log.SetFlags(log.Llongfile)
+ gserver = GetTestServer()
+}
+
+func GetTestServer() *rest.Server {
+
+ conf.MustLoad(fstests.GetEtcYamlPathAuto(), &cnf)
+
+ server := rest.MustNewServer(cnf.RestConf)
+ runtime.SetFinalizer(server, func(server *rest.Server) {
+ if server != nil {
+ server.Stop()
+ }
+ })
+
+ ctx := svc.NewServiceContext(cnf)
+ handler.RegisterHandlers(server, ctx)
+
+ fmt.Printf("Starting server at %s:%d...\n", cnf.Host, cnf.Port)
+ return server
+}
diff --git a/server/backend/test/basic.go b/server/backend/test/basic.go
index 39dfc654..61923cf4 100644
--- a/server/backend/test/basic.go
+++ b/server/backend/test/basic.go
@@ -2,10 +2,11 @@ package backendtest
import (
"fmt"
+
+ authtest "fusenapi/server/auth/test"
"fusenapi/server/backend/internal/config"
"fusenapi/server/backend/internal/handler"
"fusenapi/server/backend/internal/svc"
- homeuserauthtest "fusenapi/server/home-user-auth/test"
"fusenapi/utils/fstests"
"log"
"runtime"
@@ -19,7 +20,7 @@ var userver, gserver *rest.Server
func init() {
log.SetFlags(log.Llongfile)
- userver = homeuserauthtest.GetTestServer()
+ userver = authtest.GetTestServer()
gserver = GetTestServer()
}
diff --git a/server/backend/test/quotationdetaillogic_test.go b/server/backend/test/quotationdetaillogic_test.go
index 847819cd..3b8b1a1d 100644
--- a/server/backend/test/quotationdetaillogic_test.go
+++ b/server/backend/test/quotationdetaillogic_test.go
@@ -16,7 +16,7 @@ func TestCaseQuotationDetail(t *testing.T) {
// }
// 向服务器发送 POST 请求,新增用户地址
- tp := ses.Get(fmt.Sprintf("http://%s:%d//quotation/detail", cnf.Host, cnf.Port))
+ tp := ses.Get(fmt.Sprintf("http://%s:%d/api//quotation/detail", cnf.Host, cnf.Port))
tp.QueryParam("id").Set(1003)
resp, err := tp.TestExecute(gserver)
log.Println(resp.Json())
diff --git a/server/home-user-auth/etc/home-user-auth.yaml b/server/home-user-auth/etc/home-user-auth.yaml
index a35c3ac8..cea74d9f 100644
--- a/server/home-user-auth/etc/home-user-auth.yaml
+++ b/server/home-user-auth/etc/home-user-auth.yaml
@@ -1,6 +1,7 @@
Name: home-user-auth
Host: 0.0.0.0
Port: 9904
+MainAddress: "http://localhost:9900"
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
Auth:
diff --git a/server/home-user-auth/home-user-auth_test.go b/server/home-user-auth/home-user-auth_test.go
index d035c13a..fd8532ab 100644
--- a/server/home-user-auth/home-user-auth_test.go
+++ b/server/home-user-auth/home-user-auth_test.go
@@ -7,6 +7,5 @@ import (
// var configFile = flag.String("f", "etc/home-user-auth.yaml", "the config file")
func TestMain(t *testing.T) {
- // log.Println(model.RawFieldNames[FsCanteenType]())
main()
}
diff --git a/server/home-user-auth/internal/config/config.go b/server/home-user-auth/internal/config/config.go
index 19c515b1..6a6fbbc6 100644
--- a/server/home-user-auth/internal/config/config.go
+++ b/server/home-user-auth/internal/config/config.go
@@ -13,18 +13,6 @@ type Config struct {
MainAddress string
- OAuth struct {
- Google struct {
- Appid string
- Secret string
- }
-
- Facebook struct {
- Appid string
- Secret string
- }
- }
-
Stripe struct {
SK string
}
diff --git a/server/home-user-auth/internal/handler/acceptcookiehandler.go b/server/home-user-auth/internal/handler/acceptcookiehandler.go
deleted file mode 100644
index 88e8944a..00000000
--- a/server/home-user-auth/internal/handler/acceptcookiehandler.go
+++ /dev/null
@@ -1,35 +0,0 @@
-package handler
-
-import (
- "net/http"
- "reflect"
-
- "fusenapi/utils/basic"
-
- "fusenapi/server/home-user-auth/internal/logic"
- "fusenapi/server/home-user-auth/internal/svc"
- "fusenapi/server/home-user-auth/internal/types"
-)
-
-func AcceptCookieHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
-
- var req types.Request
- userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
- if err != nil {
- return
- }
-
- // 创建一个业务逻辑层实例
- l := logic.NewAcceptCookieLogic(r.Context(), svcCtx)
-
- rl := reflect.ValueOf(l)
- basic.BeforeLogic(w, r, rl)
-
- resp := l.AcceptCookie(&req, userinfo)
-
- if !basic.AfterLogic(w, r, rl, resp) {
- basic.NormalAfterLogic(w, r, resp)
- }
- }
-}
diff --git a/server/home-user-auth/internal/logic/acceptcookielogic.go b/server/home-user-auth/internal/logic/acceptcookielogic.go
deleted file mode 100644
index 27d0e85c..00000000
--- a/server/home-user-auth/internal/logic/acceptcookielogic.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package logic
-
-import (
- "fusenapi/utils/auth"
- "fusenapi/utils/basic"
-
- "context"
-
- "fusenapi/server/home-user-auth/internal/svc"
- "fusenapi/server/home-user-auth/internal/types"
-
- "github.com/zeromicro/go-zero/core/logx"
-)
-
-type AcceptCookieLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
-}
-
-func NewAcceptCookieLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AcceptCookieLogic {
- return &AcceptCookieLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
-}
-
-func (l *AcceptCookieLogic) AcceptCookie(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
- // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
- // userinfo 传入值时, 一定不为null
- idtyp := userinfo.GetIdType()
- if idtyp == auth.IDTYPE_Guest {
- return resp.SetStatus(basic.CodeGuestDupErr)
- }
-
- m := l.svcCtx.AllModels.FsGuest
- token, err := m.GenerateGuestID(l.ctx, &l.svcCtx.Config.Auth.AccessSecret)
- if err != nil {
- return resp.SetStatus(basic.CodeGuestGenErr)
- }
- return resp.SetStatus(basic.CodeOK, types.DataGuest{
- Token: token,
- })
-}
diff --git a/server/home-user-auth/internal/logic/usergoogleloginlogic.go b/server/home-user-auth/internal/logic/usergoogleloginlogic.go
deleted file mode 100644
index 7ad4958a..00000000
--- a/server/home-user-auth/internal/logic/usergoogleloginlogic.go
+++ /dev/null
@@ -1,176 +0,0 @@
-package logic
-
-import (
- "fmt"
- "fusenapi/utils/auth"
- "fusenapi/utils/basic"
- "log"
- "net/http"
- "time"
-
- "context"
-
- "fusenapi/server/home-user-auth/internal/svc"
- "fusenapi/server/home-user-auth/internal/types"
-
- "github.com/474420502/requests"
- "github.com/zeromicro/go-zero/core/logx"
- "github.com/zeromicro/go-zero/rest/httpx"
- "golang.org/x/net/proxy"
- "golang.org/x/oauth2"
- "golang.org/x/oauth2/google"
- "gorm.io/gorm"
-)
-
-type UserGoogleLoginLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
-
- token string // 登录 token
-
- isRegistered bool // 是否注册
- registerToken string // 注册邮箱的token
- oauthinfo *auth.OAuthInfo
-}
-
-func NewUserGoogleLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserGoogleLoginLogic {
- return &UserGoogleLoginLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
-}
-
-// func (l *UserGoogleLoginLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
-// log.Println(r, w)
-// }
-
-func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
-
- if resp.Code == 200 {
-
- if !l.isRegistered {
- now := time.Now()
- rtoken, err := auth.GenerateRegisterToken(
- &l.svcCtx.Config.Auth.AccessSecret,
- l.svcCtx.Config.Auth.AccessExpire,
- now.Unix(),
- l.oauthinfo.Id,
- l.oauthinfo.Platform,
- )
-
- if err != nil {
- resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
- }
-
- l.registerToken = rtoken
- }
-
- rurl := fmt.Sprintf(
- l.svcCtx.Config.MainAddress+"/oauth?token=%s&is_registered=%t®ister_token=%s",
- l.token,
- l.isRegistered,
- l.registerToken,
- )
-
- html := fmt.Sprintf(`
-
-
-
- Redirect
-
-
-
-
-
- `, rurl)
- fmt.Fprintln(w, html)
- } else {
- httpx.OkJson(w, resp)
- }
-
-}
-
-func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, userinfo *auth.UserInfo) (resp *basic.Response) {
- // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
- // userinfo 传入值时, 一定不为null
-
- dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:1080", nil, proxy.Direct)
- if err != nil {
- log.Fatal(err)
- }
-
- customClient := &http.Client{
- Transport: &http.Transport{
- Dial: dialer.Dial,
- },
- }
-
- ctx := context.WithValue(context.Background(), oauth2.HTTPClient, customClient)
-
- var googleOauthConfig = &oauth2.Config{
- RedirectURL: "http://localhost:9900/api/user/oauth2/login/google",
- ClientID: l.svcCtx.Config.OAuth.Google.Appid,
- ClientSecret: l.svcCtx.Config.OAuth.Google.Secret,
- Scopes: []string{"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
- Endpoint: google.Endpoint,
- }
-
- token, err := googleOauthConfig.Exchange(ctx, req.Code)
- if err != nil {
- logx.Error(err)
- resp.SetStatus(basic.CodeApiErr)
- }
- ses := requests.NewSession()
- ses.Config().SetProxy("socks5://127.0.0.1:1080") // 代理 为了测试功能
-
- r, err := ses.Get("https://www.googleapis.com/oauth2/v2/userinfo?access_token=" + token.AccessToken).Execute()
- if err != nil {
- logx.Error(err)
- return resp.SetStatus(basic.CodeOAuthGoogleApiErr)
- }
-
- log.Println(r.Json())
-
- googleId := r.Json().Get("id").Int()
- user, err := l.svcCtx.AllModels.FsUser.FindUserByGoogleId(context.TODO(), googleId)
- if err != nil {
- if err != gorm.ErrRecordNotFound {
- logx.Error(err)
- return resp.SetStatus(basic.CodeDbSqlErr)
- }
-
- // 进入邮件注册流程
- if req.Email == "" {
- return resp.SetStatus(basic.CodeOK)
- }
-
- // 这里是注册模块, 发邮件, 通过邮件注册确认邮箱存在
-
- // 邮箱验证格式错误
- if !auth.ValidateEmail(req.Email) {
- return resp.SetStatus(basic.CodeOAuthEmailErr)
- }
-
- return resp.SetStatus(basic.CodeOK)
- }
-
- // 如果密码匹配,则生成 JWT Token。
- nowSec := time.Now().Unix()
- jwtToken, err := auth.GenerateJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, user.Id, 0)
-
- // 如果生成 JWT Token 失败,则抛出错误并返回未认证的状态码。
- if err != nil {
- logx.Error(err)
- return resp.SetStatus(basic.CodeServiceErr)
- }
-
- l.token = jwtToken
-
- return resp.SetStatus(basic.CodeOK)
-}
diff --git a/server/home-user-auth/internal/logic/userloginlogic.go b/server/home-user-auth/internal/logic/userloginlogic.go
deleted file mode 100644
index a8900591..00000000
--- a/server/home-user-auth/internal/logic/userloginlogic.go
+++ /dev/null
@@ -1,84 +0,0 @@
-package logic
-
-import (
- "context"
- "errors"
- "fmt"
- "net/http"
- "time"
-
- "fusenapi/server/home-user-auth/internal/svc"
- "fusenapi/server/home-user-auth/internal/types"
- "fusenapi/utils/auth"
- "fusenapi/utils/basic"
-
- "github.com/zeromicro/go-zero/core/logx"
- "github.com/zeromicro/go-zero/rest/httpx"
- "gorm.io/gorm"
-)
-
-type UserLoginLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
-
- token string
-}
-
-func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
- return &UserLoginLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
-}
-
-func (l *UserLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
- if l.token != "" {
- w.Header().Add("Authorization", fmt.Sprintf("Bearer %s", l.token))
- }
-
- httpx.OkJsonCtx(r.Context(), w, resp)
-}
-
-func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin, userinfo *auth.UserInfo) (resp *basic.Response) {
- // 创建一个 FsUserModel 对象 m 并实例化之,该对象用于操作 MySQL 数据库中的用户数据表。
- m := l.svcCtx.AllModels.FsUser
-
- // 在用户数据表中根据登录名(email)查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
- user, err := m.FindUserByEmail(l.ctx, req.Email)
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return resp.SetStatus(basic.CodeEmailNotFoundErr)
- }
-
- // 如果在用户数据表中找到了登录名匹配的用户记录,则判断密码是否匹配。
- if *user.PasswordHash != req.Password {
- logx.Info("密码错误")
- return resp.SetStatus(basic.CodePasswordErr)
- }
-
- // 如果密码匹配,则生成 JWT Token。
- nowSec := time.Now().Unix()
- jwtToken, err := auth.GenerateJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, user.Id, 0)
-
- // 如果生成 JWT Token 失败,则抛出错误并返回未认证的状态码。
- if err != nil {
- logx.Error(err)
- return resp.SetStatus(basic.CodeUnAuth)
- }
-
- // 如果更新 VerificationToken 字段失败,则返回未认证的状态码。
- if err != nil {
- return resp.SetStatus(basic.CodeUnAuth)
- }
-
- // 构造 DataUserLogin 类型的数据对象 data 并设置其属性值为生成的 JWT Token。
- data := &types.DataUserLogin{
- Token: jwtToken,
- }
-
- l.token = jwtToken
-
- // 返回认证成功的状态码以及数据对象 data 和 JWT Token。
- return resp.SetStatus(basic.CodeOK, data)
-}
diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go
index bf8211ab..e299ec9f 100644
--- a/server/home-user-auth/internal/types/types.go
+++ b/server/home-user-auth/internal/types/types.go
@@ -115,14 +115,6 @@ type RequestOrderId struct {
RefundReason string `json:"refund_reason"` //取消原因
}
-type DataUserLogin struct {
- Token string `json:"token"` // 登录jwt token
-}
-
-type DataGuest struct {
- Token string `json:"token"` // 登录jwt token
-}
-
type DataUserBasicInfo struct {
Type int64 `json:"type"` // 1普通餐厅 2连锁餐厅
IsOrderStatusEmail int64 `json:"is_order_status_email"` // 订单状态改变时是否接收邮件
diff --git a/server/home-user-auth/test/basic.go b/server/home-user-auth/test/basic.go
index 0c71b381..20b546f7 100644
--- a/server/home-user-auth/test/basic.go
+++ b/server/home-user-auth/test/basic.go
@@ -2,6 +2,7 @@ package homeuserauthtest
import (
"fmt"
+ authtest "fusenapi/server/auth/test"
"fusenapi/server/home-user-auth/internal/config"
"fusenapi/server/home-user-auth/internal/handler"
"fusenapi/server/home-user-auth/internal/svc"
@@ -15,10 +16,12 @@ import (
)
var cnf config.Config
+var userserver *rest.Server
var gserver *rest.Server
func init() {
log.SetFlags(log.Llongfile)
+ userserver = authtest.GetTestServer()
gserver = GetTestServer()
}
diff --git a/server/home-user-auth/test/useraddaddresslogic_test.go b/server/home-user-auth/test/useraddaddresslogic_test.go
index 37cf260c..7380eb38 100644
--- a/server/home-user-auth/test/useraddaddresslogic_test.go
+++ b/server/home-user-auth/test/useraddaddresslogic_test.go
@@ -16,7 +16,7 @@ func TestCaseUserAddAddress(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
- ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
+ ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
// 构建新增地址请求体
addrReq := types.RequestAddAddress{
@@ -32,7 +32,7 @@ func TestCaseUserAddAddress(t *testing.T) {
}
// 向服务器发送 POST 请求,新增用户地址
- tp := ses.Post(fmt.Sprintf("http://%s:%d/user/add-address", cnf.Host, cnf.Port))
+ tp := ses.Post(fmt.Sprintf("http://%s:%d/api/user/add-address", cnf.Host, cnf.Port))
tp.SetBodyJson(addrReq)
resp, err = tp.TestExecute(gserver)
if err != nil {
@@ -85,7 +85,7 @@ func TestCaseUserAddAddress(t *testing.T) {
}
// 向服务器发送 POST 请求,新增用户地址
- tp = ses.Post(fmt.Sprintf("http://%s:%d/user/add-address", cnf.Host, cnf.Port))
+ tp = ses.Post(fmt.Sprintf("http://%s:%d/api/user/add-address", cnf.Host, cnf.Port))
tp.SetBodyJson(addrReq)
resp, err = tp.TestExecute(gserver)
if err != nil {
diff --git a/server/home-user-auth/test/useraddresslistlogic_test.go b/server/home-user-auth/test/useraddresslistlogic_test.go
index 97ac3306..70cb0c65 100644
--- a/server/home-user-auth/test/useraddresslistlogic_test.go
+++ b/server/home-user-auth/test/useraddresslistlogic_test.go
@@ -15,10 +15,10 @@ func TestCaseAddressList(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
- ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
+ ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户地址列表
- resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/address-list", cnf.Host, cnf.Port)).TestExecute(gserver)
+ resp, err = ses.Get(fmt.Sprintf("http://%s:%d/api/user/address-list", cnf.Host, cnf.Port)).TestExecute(gserver)
if err != nil {
t.Error(err)
}
diff --git a/server/home-user-auth/test/userbasicinfologic_test.go b/server/home-user-auth/test/userbasicinfologic_test.go
index a98aa656..103b7fd0 100644
--- a/server/home-user-auth/test/userbasicinfologic_test.go
+++ b/server/home-user-auth/test/userbasicinfologic_test.go
@@ -15,10 +15,10 @@ func TestCaseBasicInfoLogic(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
- ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
+ ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户基本信息
- resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port)).TestExecute(gserver)
+ resp, err = ses.Get(fmt.Sprintf("http://%s:%d/api/user/basic-info", cnf.Host, cnf.Port)).TestExecute(gserver)
if err != nil {
t.Error(err)
}
diff --git a/server/home-user-auth/test/usercontactservicelogic_test.go b/server/home-user-auth/test/usercontactservicelogic_test.go
index 2242162b..b52b9aa4 100644
--- a/server/home-user-auth/test/usercontactservicelogic_test.go
+++ b/server/home-user-auth/test/usercontactservicelogic_test.go
@@ -16,8 +16,8 @@ func TestUserContactService(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
- ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
- tp := ses.Post(fmt.Sprintf("http://%s:%d/user/contact-service", cnf.Host, cnf.Port))
+ ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
+ tp := ses.Post(fmt.Sprintf("http://%s:%d/api/user/contact-service", cnf.Host, cnf.Port))
req := types.RequestContactService{Type: "order", RelationID: 481, Email: "9107058@qq.com", Name: "zhang"}
tp.SetBodyJson(req)
// 向服务器发送 GET 请求,获取用户基本信息
diff --git a/server/home-user-auth/test/userfontslogic_test.go b/server/home-user-auth/test/userfontslogic_test.go
index a79f5bb8..36ede55d 100644
--- a/server/home-user-auth/test/userfontslogic_test.go
+++ b/server/home-user-auth/test/userfontslogic_test.go
@@ -16,10 +16,10 @@ func TestCaseUserFontsLogic(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
- ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
+ ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取字体列表
- resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/fonts", cnf.Host, cnf.Port)).TestExecute(gserver)
+ resp, err = ses.Get(fmt.Sprintf("http://%s:%d/api/user/fonts", cnf.Host, cnf.Port)).TestExecute(gserver)
if err != nil {
t.Error(err)
}
diff --git a/server/home-user-auth/test/usergettypelogic_test.go b/server/home-user-auth/test/usergettypelogic_test.go
index 6cc72a48..de302aaa 100644
--- a/server/home-user-auth/test/usergettypelogic_test.go
+++ b/server/home-user-auth/test/usergettypelogic_test.go
@@ -15,10 +15,10 @@ func TestCaseGetTypeLogic(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
- ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
+ ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户类型信息
- resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/get-type", cnf.Host, cnf.Port)).TestExecute(gserver)
+ resp, err = ses.Get(fmt.Sprintf("http://%s:%d/api/user/get-type", cnf.Host, cnf.Port)).TestExecute(gserver)
if err != nil {
t.Error(err)
}
diff --git a/server/home-user-auth/test/useroderdeletelogic_test.go b/server/home-user-auth/test/useroderdeletelogic_test.go
index c5526202..f31fce6c 100644
--- a/server/home-user-auth/test/useroderdeletelogic_test.go
+++ b/server/home-user-auth/test/useroderdeletelogic_test.go
@@ -16,10 +16,10 @@ func TestCaseLogic(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
- ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
+ ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户类型信息
- tp := ses.Post(fmt.Sprintf("http://%s:%d/user/order-delete", cnf.Host, cnf.Port))
+ tp := ses.Post(fmt.Sprintf("http://%s:%d/api/user/order-delete", cnf.Host, cnf.Port))
reqO := types.RequestOrderId{
OrderId: 12,
}
diff --git a/server/home-user-auth/test/usersavebasicinfologic_test.go b/server/home-user-auth/test/usersavebasicinfologic_test.go
index f8d4c5fc..355d4ca4 100644
--- a/server/home-user-auth/test/usersavebasicinfologic_test.go
+++ b/server/home-user-auth/test/usersavebasicinfologic_test.go
@@ -17,10 +17,10 @@ func TestCaseUserSaveBasicinfoLogic(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
- ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
+ ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
var tp *requests.Temporary
- tp = ses.Get(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port))
+ tp = ses.Get(fmt.Sprintf("http://%s:%d/api/user/basic-info", cnf.Host, cnf.Port))
resp, err = tp.TestExecute(gserver)
if err != nil {
t.Error(err)
@@ -52,7 +52,7 @@ func TestCaseUserSaveBasicinfoLogic(t *testing.T) {
req.IsRemoveBg = ^req.IsRemoveBg + 2
// 向服务器发送 GET 请求,获取用户类型信息
- tp = ses.Post(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port)).SetBodyJson(req)
+ tp = ses.Post(fmt.Sprintf("http://%s:%d/api/user/basic-info", cnf.Host, cnf.Port)).SetBodyJson(req)
resp, err = tp.TestExecute(gserver)
if err != nil {
t.Error(err)
@@ -69,7 +69,7 @@ func TestCaseUserSaveBasicinfoLogic(t *testing.T) {
return
}
- tp = ses.Get(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port))
+ tp = ses.Get(fmt.Sprintf("http://%s:%d/api/user/basic-info", cnf.Host, cnf.Port))
resp, err = tp.TestExecute(gserver)
if err != nil {
t.Error(err)
diff --git a/server/home-user-auth/test/userstatusconfiglogic_test.go b/server/home-user-auth/test/userstatusconfiglogic_test.go
index 3028418e..e70028b7 100644
--- a/server/home-user-auth/test/userstatusconfiglogic_test.go
+++ b/server/home-user-auth/test/userstatusconfiglogic_test.go
@@ -15,10 +15,10 @@ func TestCaseUserStatusConfigLogic(t *testing.T) {
var result gjson.Result
// 获取 session,并携带 JWT token
- ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
+ ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户类型信息
- resp, err = ses.Post(fmt.Sprintf("http://%s:%d/user/status-config", cnf.Host, cnf.Port)).TestExecute(gserver)
+ resp, err = ses.Post(fmt.Sprintf("http://%s:%d/api/user/status-config", cnf.Host, cnf.Port)).TestExecute(gserver)
if err != nil {
t.Error(err)
}
diff --git a/server/upload/test/basic.go b/server/upload/test/basic.go
index 606e0c0f..c6a4afa3 100644
--- a/server/upload/test/basic.go
+++ b/server/upload/test/basic.go
@@ -2,7 +2,8 @@ package test
import (
"fmt"
- homeuserauthtest "fusenapi/server/home-user-auth/test"
+
+ authtest "fusenapi/server/auth/test"
"fusenapi/server/upload/internal/config"
"fusenapi/server/upload/internal/handler"
"fusenapi/server/upload/internal/svc"
@@ -20,7 +21,7 @@ var userver, gserver *rest.Server
func init() {
log.SetFlags(log.Llongfile)
- userver = homeuserauthtest.GetTestServer()
+ userver = authtest.GetTestServer()
gserver = GetTestServer()
}
diff --git a/server/upload/test/uploadfilebackendhandler_test.go b/server/upload/test/uploadfilebackendhandler_test.go
index e6042280..2cf1560e 100644
--- a/server/upload/test/uploadfilebackendhandler_test.go
+++ b/server/upload/test/uploadfilebackendhandler_test.go
@@ -19,7 +19,7 @@ func TestCaseRenderMegre(t *testing.T) {
// 获取 session,并携带 JWT token
ses := fstests.GetSessionWithUserToken(t, userver, cnf.Host, cnf.Port)
- tp := ses.Post(fmt.Sprintf("http://%s:%d/upload/upload-file-backend", cnf.Host, cnf.Port))
+ tp := ses.Post(fmt.Sprintf("http://%s:%d/api/upload/upload-file-backend", cnf.Host, cnf.Port))
mp := tp.CreateBodyMultipart()
f, err := os.Open("./fusen.webp")
diff --git a/server/upload/test/uploadfilefrontendhandler_test.go b/server/upload/test/uploadfilefrontendhandler_test.go
index 8564c48f..acd8a78f 100644
--- a/server/upload/test/uploadfilefrontendhandler_test.go
+++ b/server/upload/test/uploadfilefrontendhandler_test.go
@@ -20,7 +20,7 @@ func TestCasePersonalization(t *testing.T) {
// 获取 session,并携带 JWT token
ses := fstests.GetSessionWithUserToken(t, userver, cnf.Host, cnf.Port)
- tp := ses.Post(fmt.Sprintf("http://%s:%d/upload/upload-file-frontend", cnf.Host, cnf.Port))
+ tp := ses.Post(fmt.Sprintf("http://%s:%d/api/upload/upload-file-frontend", cnf.Host, cnf.Port))
data, err := ioutil.ReadFile("./fusen.webp")
if err != nil {
@@ -75,7 +75,7 @@ func TestCaseRenderMegreF(t *testing.T) {
// 获取 session,并携带 JWT token
ses := fstests.GetSessionWithUserToken(t, userver, cnf.Host, cnf.Port)
- tp := ses.Post(fmt.Sprintf("http://%s:%d/upload/upload-file-frontend", cnf.Host, cnf.Port))
+ tp := ses.Post(fmt.Sprintf("http://%s:%d/api/upload/upload-file-frontend", cnf.Host, cnf.Port))
data, err := ioutil.ReadFile("./fusen.webp")
if err != nil {
diff --git a/server/webset/test/basic.go b/server/webset/test/basic.go
index b554a70c..0d85a1dd 100644
--- a/server/webset/test/basic.go
+++ b/server/webset/test/basic.go
@@ -2,7 +2,8 @@ package webset_test
import (
"fmt"
- homeuserauthtest "fusenapi/server/home-user-auth/test"
+
+ authtest "fusenapi/server/auth/test"
"fusenapi/server/webset/internal/config"
"fusenapi/server/webset/internal/handler"
"fusenapi/server/webset/internal/svc"
@@ -19,7 +20,7 @@ var userver, gserver *rest.Server
func init() {
log.SetFlags(log.Llongfile)
- userver = homeuserauthtest.GetTestServer()
+ userver = authtest.GetTestServer()
gserver = GetTestServer()
}
diff --git a/server/webset/test/webset_test.go b/server/webset/test/webset_test.go
index 897f3e26..b2f2440b 100644
--- a/server/webset/test/webset_test.go
+++ b/server/webset/test/webset_test.go
@@ -20,7 +20,7 @@ func TestWebSetLogic(t *testing.T) {
// 获取 session,并携带 JWT token
ses := fstests.GetSesssion()
- tp := ses.Get(fmt.Sprintf("http://%s:%d/web-set/setting", cnf.Host, cnf.Port))
+ tp := ses.Get(fmt.Sprintf("http://%s:%d/api/web-set/setting", cnf.Host, cnf.Port))
for _, tType := range testTypes {
tp.QueryParam("type").Set(tType)
diff --git a/server_api/auth.api b/server_api/auth.api
index 2460b9b6..79b6ac9e 100644
--- a/server_api/auth.api
+++ b/server_api/auth.api
@@ -14,13 +14,13 @@ service auth {
post /api/auth/login(RequestUserLogin) returns (response);
@handler AcceptCookieHandler
- post /api/user/accept-cookie(request) returns (response);
+ post /api/auth/accept-cookie(request) returns (response);
@handler UserGoogleLoginHandler
- get /api/user/oauth2/login/google(RequestGoogleLogin) returns (response);
+ get /api/auth/oauth2/login/google(RequestGoogleLogin) returns (response);
@handler UserEmailRegisterHandler
- get /api/user/oauth2/login/register(RequestEmailRegister) returns (response);
+ get /api/auth/oauth2/login/register(RequestEmailRegister) returns (response);
}
// UserAddAddressHandler 用户登录请求结构
diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api
index d36da50b..eb7852e2 100644
--- a/server_api/home-user-auth.api
+++ b/server_api/home-user-auth.api
@@ -173,8 +173,6 @@ type RequestOrderId {
RefundReason string `json:"refund_reason"` //取消原因
}
-
-
// UserBasicInfoHandler 返回data结构
type DataUserBasicInfo {
Type int64 `json:"type"` // 1普通餐厅 2连锁餐厅
diff --git a/utils/fstests/basic.go b/utils/fstests/basic.go
index 1c19783f..585a4301 100644
--- a/utils/fstests/basic.go
+++ b/utils/fstests/basic.go
@@ -85,10 +85,10 @@ func GetSesssion() *requests.Session {
func GetSessionWithUserToken(t *testing.T, server requests.ITestServer, Host string, Port int) *requests.Session {
ses := requests.NewSession()
- tp := ses.Post(fmt.Sprintf("http://%s:%d/user/login", Host, Port))
+ tp := ses.Post(fmt.Sprintf("http://%s:%d/api/auth/login", Host, Port))
tp.SetBodyJson(map[string]interface{}{
- "name": "9107058@qq.com",
- "pwd": "$2y$13$2y4O4OIz/zcK5C0vlSc9LuSpjWySjInLBSe49yDkE.iURb.R1hDsy",
+ "email": "9107058@qq.com",
+ "password": "t1I0hOs0/AmhZfNk9ZiNnd3YZJpI+LL6COnHAmYEJk4=",
})
resp, err := tp.TestExecute(server)
if err != nil {
@@ -104,17 +104,17 @@ func GetSessionWithUserToken(t *testing.T, server requests.ITestServer, Host str
if !token.Exists() {
t.Error("data.token is not exists")
}
- ses.Header.Add("Authorization", token.String())
+ ses.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token.String()))
return ses
}
func GetBackendSessionWithUserToken(t *testing.T, server requests.ITestServer, Host string, Port int) *requests.Session {
ses := requests.NewSession()
- tp := ses.Post(fmt.Sprintf("http://%s:%d/backend-user/login", Host, Port))
+ tp := ses.Post(fmt.Sprintf("http://%s:%d/api/backend-user/login", Host, Port))
tp.SetBodyJson(map[string]interface{}{
- "name": "admin@admin.com",
- "pwd": "ZnVzZW5fYmFja2VuZF8yMDIz47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU=",
+ "email": "admin@admin.com",
+ "pwd": "ZnVzZW5fYmFja2VuZF8yMDIz47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU=",
})
resp, err := tp.TestExecute(server)
if err != nil {
@@ -130,14 +130,14 @@ func GetBackendSessionWithUserToken(t *testing.T, server requests.ITestServer, H
if !token.Exists() {
t.Error("data.token is not exists")
}
- ses.Header.Add("Authorization", token.String())
+ ses.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token.String()))
return ses
}
func GetSesssionWithGuestToken(t *testing.T, server requests.ITestServer, Host string, Port int) *requests.Session {
ses := requests.NewSession()
- tp := ses.Post(fmt.Sprintf("http://%s:%d/accept/cookie", Host, Port))
+ tp := ses.Post(fmt.Sprintf("http://%s:%d/api/auth/accept/cookie", Host, Port))
resp, err := tp.TestExecute(server)
if err != nil {
@@ -148,7 +148,7 @@ func GetSesssionWithGuestToken(t *testing.T, server requests.ITestServer, Host s
if !token.Exists() {
t.Error("data.token is not exists")
}
- ses.Header.Add("Authorization", token.String())
+ ses.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token.String()))
return ses
}