diff --git a/server/home-user-auth/internal/handler/routes.go b/server/home-user-auth/internal/handler/routes.go index aab65dff..718c8455 100644 --- a/server/home-user-auth/internal/handler/routes.go +++ b/server/home-user-auth/internal/handler/routes.go @@ -38,7 +38,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Handler: UserSaveBasicInfoHandler(serverCtx), }, { - Method: http.MethodPost, + Method: http.MethodGet, Path: "/api/user/status-config", Handler: UserStatusConfigHandler(serverCtx), }, diff --git a/server/home-user-auth/internal/logic/userstatusconfiglogic.go b/server/home-user-auth/internal/logic/userstatusconfiglogic.go index 5a498542..95d25249 100644 --- a/server/home-user-auth/internal/logic/userstatusconfiglogic.go +++ b/server/home-user-auth/internal/logic/userstatusconfiglogic.go @@ -28,6 +28,10 @@ func NewUserStatusConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) * func (l *UserStatusConfigLogic) UserStatusConfig(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + if !userinfo.IsUser() { + return resp.SetStatus(basic.CodeUnAuth) + } + data := &types.DataStatusConfig{ SearchList: []types.KeyName{ {Key: -1, Name: "All"}, diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index 0cd5b1e1..b5168153 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -10,6 +10,10 @@ info ( import "basic.api" service home-user-auth { + + @handler UserRegisterHandler + post /api/user/register(RequestUserRegister) returns (response); + @handler UserLoginHandler post /api/user/login(RequestUserLogin) returns (response); @@ -26,7 +30,7 @@ service home-user-auth { post /api/user/basic-info(RequestBasicInfoForm) returns (response); @handler UserStatusConfigHandler - post /api/user/status-config(request) returns (response); + get /api/user/status-config(request) returns (response); @handler UserBasicInfoHandler get /api/user/basic-info(request) returns (response); diff --git a/utils/auth/register.go b/utils/auth/register.go new file mode 100644 index 00000000..d634fdaf --- /dev/null +++ b/utils/auth/register.go @@ -0,0 +1,76 @@ +package auth + +import ( + "net/mail" +) + +// ValidateEmail checks if the provided string is a valid email address. +func ValidateEmail(email string) bool { + _, err := mail.ParseAddress(email) + return err == nil +} + +// ValidatePassword checks if the provided password is strong enough. +// In this example, we just check if the password length is 8 or more. +func ValidatePassword(password string) bool { + const minPasswordLength = 8 + return len(password) >= minPasswordLength +} + +var secret = []byte("your-secret") + +// func generateConfirmationLink(id, email, password, name string, platform string) (string, error) { +// // 创建一个新的 JWT,并将用户的电子邮件设置为它的主题。 +// token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ +// "email": email, +// "password": password, +// "id": id, +// "platform": platform, +// "exp": time.Now().Add(24 * time.Hour).Unix(), // Token expires after 24 hours +// }) + +// // 签署 JWT。 +// tokenString, err := token.SignedString(secret) +// if err != nil { +// return "", err +// } + +// // 生成确认链接,这个链接包含 JWT。 +// link := url.URL{ +// Scheme: "http", +// Host: "yourserver.com", +// Path: "/confirm", +// RawQuery: url.Values{ +// "token": []string{tokenString}, +// }.Encode(), +// } + +// return link.String(), nil +// } + +// func handleConfirm(w http.ResponseWriter, r *http.Request) { +// // 从请求中获取 JWT。 +// tokenString := r.URL.Query().Get("token") + +// // 解析和验证 JWT。 +// token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { +// return secret, nil +// }) + +// if err != nil || !token.Valid { +// http.Error(w, "Invalid confirmation link", http.StatusBadRequest) +// return +// } + +// claims, ok := token.Claims.(jwt.MapClaims) + +// if !ok || !token.Valid { +// http.Error(w, "Invalid token", http.StatusBadRequest) +// return +// } + +// email := claims["sub"].(string) + +// // 确认链接有效,可以创建用户账号了。 +// createUser(email) +// } diff --git a/utils/format/s3keyname.go b/utils/format/s3keyname.go index b5be968a..a72a1447 100644 --- a/utils/format/s3keyname.go +++ b/utils/format/s3keyname.go @@ -19,12 +19,14 @@ const TCategoryPersonalization TypeCategory = "personalization" const TCategory3DTools TypeCategory = "3dtools" const TCategoryQuotation TypeCategory = "quotation" const TCategoryRenderMegre TypeCategory = "render_megre" +const TCategoryImage TypeCategory = "image" var CategoryMap = map[string]bool{ string(TCategoryPersonalization): true, string(TCategory3DTools): true, string(TCategoryQuotation): true, string(TCategoryRenderMegre): true, + string(TCategoryImage): true, } // FormatS3KeyName 需要输入选 @@ -51,6 +53,8 @@ func FormatS3KeyNameUser(userid int64, now time.Time, env string, category TypeC } switch category { + case TCategoryImage: + return fmt.Sprintf("/%s/%s/%d/%s_%d.%s", env, category, userid, name, now.UnixNano(), ext) case TCategoryPersonalization: // /{env}/personalization/{userid}/{filename} return fmt.Sprintf("/%s/%s/%d/%s.%s", env, category, userid, name, ext) @@ -82,12 +86,14 @@ func FormatS3KeyNameGuest(guestid int64, now time.Time, env string, category Typ } switch category { + case TCategoryImage: + return fmt.Sprintf("/%s/%s/g/%d/%s_%d.%s", env, category, guestid, name, now.UnixNano(), ext) case TCategoryPersonalization: - // /{env}/personalization/{guestid}/{filename} - return fmt.Sprintf("/%s/%s/%d/%s.%s", env, category, guestid, name, ext) + // /{env}/personalization/g/{guestid}/{filename} + return fmt.Sprintf("/%s/%s/g/%d/%s.%s", env, category, guestid, name, ext) case TCategoryRenderMegre: // /{env}/render_megre/{guestid}/{filename} 自动删除 - return fmt.Sprintf("/%s/%s/%d/%s_%d.%s", env, category, guestid, name, now.UnixNano(), ext) + return fmt.Sprintf("/%s/%s/g/%d/%s_%d.%s", env, category, guestid, name, now.UnixNano(), ext) case TCategory3DTools: panic(TCategory3DTools + "不存在游客") // /{env}/3dtools/年月/{guestid}/{filename} @@ -97,7 +103,7 @@ func FormatS3KeyNameGuest(guestid int64, now time.Time, env string, category Typ // /{env}/quotation/年月/{guestid}/{filename} // return fmt.Sprintf("/%s/%s/%04d%02d/%d/%s_%d.%s", env, category, year, int(month), guestid, name, now.UnixNano(), ext) default: - return fmt.Sprintf("/%s/%s/%d/%04d%02d/%s_%d.%s", env, category, guestid, year, int(month), name, now.UnixNano(), ext) + return fmt.Sprintf("/%s/%s/g/%d/%04d%02d/%s_%d.%s", env, category, guestid, year, int(month), name, now.UnixNano(), ext) } }