From 78a162a19a10f3b184f5c28ea028dcbbb14d6a71 Mon Sep 17 00:00:00 2001
From: landaiqing <3517283258@qq.com>
Date: Sun, 17 Nov 2024 20:02:59 +0800
Subject: [PATCH] :bug: fix session bug
---
.idea/GOHCache.xml | 688 +++++++++++-------
.../generate/generate_rotate_captcha.go | 3 +-
.../generate/generate_slide_basic_captcha.go | 3 +-
app/core/api/common/i18n/bundle.go | 5 +-
app/core/api/common/i18n/cache.go | 18 -
app/core/api/common/i18n/i18n.go | 39 +-
app/core/api/common/i18n/keys.go | 2 +-
app/core/api/common/i18n/parse.go | 5 +-
.../api/common/middleware/cors_middleware.go | 4 +-
.../middleware/security_headers_middleware.go | 2 +-
.../unauthorized_callback_middleware.go | 16 +
app/core/api/common/response/response.go | 4 +-
app/core/api/core.api | 100 ++-
app/core/api/core.go | 2 +-
app/core/api/etc/core.yaml | 3 +-
app/core/api/internal/config/config.go | 1 -
.../generate_rotate_captcha_handler.go | 5 +-
.../generate_slide_basic_captcha_handler.go | 5 +-
.../client/generate_client_id_handler.go | 6 +-
.../comment/dislike_comment_handler.go | 31 +
.../comment/get_comment_list_handler.go | 31 +
.../handler/comment/get_reply_list_handler.go | 31 +
.../handler/comment/like_comment_handler.go | 31 +
.../handler/comment/submit_comment_handler.go | 31 +
.../comment/submit_reply_comment_handler.go | 31 +
.../comment/submit_reply_reply_handler.go | 31 +
.../oauth/get_gitee_oauth_url_handler.go | 5 +-
.../oauth/get_github_oauth_url_handler.go | 5 +-
.../handler/oauth/get_qq_oauth_url_handler.go | 5 +-
.../oauth/get_wechat_qrcode_handler.go | 4 +-
.../handler/oauth/gitee_callback_handler.go | 5 +-
.../handler/oauth/github_callback_handler.go | 5 +-
.../handler/oauth/qq_callback_handler.go | 5 +-
.../handler/oauth/wechat_callback_handler.go | 5 +-
app/core/api/internal/handler/routes.go | 50 +-
.../handler/sms/send_sms_by_aliyun_handler.go | 5 +-
.../handler/sms/send_sms_by_smsbao_handler.go | 5 +-
.../handler/sms/send_sms_by_test_handler.go | 5 +-
.../handler/user/account_login_handler.go | 6 +-
.../handler/user/get_user_device_handler.go | 5 +-
.../handler/user/phone_login_handler.go | 4 +-
.../handler/user/refresh_token_handler.go | 4 +-
.../handler/user/reset_password_handler.go | 6 +-
.../websocket/message_websocket_handler.go | 9 +-
.../websocket/qrcode_websocket_handler.go | 9 +-
.../logic/client/generate_client_id_logic.go | 1 -
.../logic/comment/dislike_comment_logic.go | 30 +
.../logic/comment/get_comment_list_logic.go | 31 +
.../logic/comment/get_reply_list_logic.go | 30 +
.../logic/comment/like_comment_logic.go | 30 +
.../logic/comment/submit_comment_logic.go | 30 +
.../comment/submit_reply_comment_logic.go | 30 +
.../logic/comment/submit_reply_reply_logic.go | 30 +
.../logic/oauth/github_callback_logic.go | 5 +-
.../internal/logic/oauth/qq_callback_logic.go | 3 +-
.../logic/oauth/wechat_callback_logic.go | 12 +-
.../logic/sms/send_sms_by_aliyun_logic.go | 10 +-
.../logic/sms/send_sms_by_smsbao_logic.go | 10 +-
.../logic/sms/send_sms_by_test_logic.go | 8 +-
.../logic/user/account_login_logic.go | 30 +-
.../logic/user/get_user_device_logic.go | 4 +-
.../internal/logic/user/phone_login_logic.go | 26 +-
.../logic/user/refresh_token_logic.go | 31 +-
.../logic/user/reset_password_logic.go | 18 +-
.../websocket/message_websocket_logic.go | 5 +-
.../logic/websocket/qrcode_websocket_logic.go | 5 +-
.../middleware/casbinverify_middleware.go | 29 +
.../middleware/securityheaders_middleware.go | 2 +-
app/core/api/internal/svc/service_context.go | 5 +-
app/core/api/internal/types/redis_token.go | 5 +-
app/core/api/internal/types/types.go | 56 ++
app/core/api/repository/redis_session/init.go | 6 +-
72 files changed, 1304 insertions(+), 453 deletions(-)
create mode 100644 app/core/api/common/middleware/unauthorized_callback_middleware.go
create mode 100644 app/core/api/internal/handler/comment/dislike_comment_handler.go
create mode 100644 app/core/api/internal/handler/comment/get_comment_list_handler.go
create mode 100644 app/core/api/internal/handler/comment/get_reply_list_handler.go
create mode 100644 app/core/api/internal/handler/comment/like_comment_handler.go
create mode 100644 app/core/api/internal/handler/comment/submit_comment_handler.go
create mode 100644 app/core/api/internal/handler/comment/submit_reply_comment_handler.go
create mode 100644 app/core/api/internal/handler/comment/submit_reply_reply_handler.go
create mode 100644 app/core/api/internal/logic/comment/dislike_comment_logic.go
create mode 100644 app/core/api/internal/logic/comment/get_comment_list_logic.go
create mode 100644 app/core/api/internal/logic/comment/get_reply_list_logic.go
create mode 100644 app/core/api/internal/logic/comment/like_comment_logic.go
create mode 100644 app/core/api/internal/logic/comment/submit_comment_logic.go
create mode 100644 app/core/api/internal/logic/comment/submit_reply_comment_logic.go
create mode 100644 app/core/api/internal/logic/comment/submit_reply_reply_logic.go
create mode 100644 app/core/api/internal/middleware/casbinverify_middleware.go
diff --git a/.idea/GOHCache.xml b/.idea/GOHCache.xml
index 8bd259f..aaac738 100644
--- a/.idea/GOHCache.xml
+++ b/.idea/GOHCache.xml
@@ -34,8 +34,6 @@
-
-
@@ -44,14 +42,13 @@
-
-
+
-
+
@@ -69,6 +66,13 @@
+
+
+
+
+
+
+
@@ -76,6 +80,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -97,11 +122,16 @@
+
+
+
+
+
+
+
-
-
@@ -127,6 +157,13 @@
+
+
+
+
+
+
+
@@ -148,6 +185,13 @@
+
+
+
+
+
+
+
@@ -204,6 +248,13 @@
+
+
+
+
+
+
+
@@ -292,7 +343,6 @@
-
@@ -300,7 +350,6 @@
-
@@ -329,7 +378,6 @@
-
@@ -354,6 +402,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -418,13 +487,6 @@
-
-
-
-
-
-
-
@@ -517,13 +579,6 @@
-
-
-
-
-
-
-
@@ -659,13 +714,6 @@
-
-
-
-
-
-
-
@@ -715,13 +763,6 @@
-
-
-
-
-
-
-
@@ -800,13 +841,6 @@
-
-
-
-
-
-
-
@@ -916,7 +950,34 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -941,14 +1002,6 @@
-
-
-
-
-
-
-
-
@@ -1033,14 +1086,14 @@
-
+
-
+
@@ -1117,28 +1170,28 @@
-
+
-
+
-
+
-
+
@@ -1157,7 +1210,7 @@
-
+
@@ -1202,7 +1255,7 @@
-
+
@@ -1216,7 +1269,14 @@
-
+
+
+
+
+
+
+
+
@@ -1258,14 +1318,7 @@
-
-
-
-
-
-
-
-
+
@@ -1276,6 +1329,13 @@
+
+
+
+
+
+
+
@@ -1319,7 +1379,7 @@
-
+
@@ -1333,7 +1393,7 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -1488,7 +1632,7 @@
-
+
@@ -1497,6 +1641,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1562,7 +1790,7 @@
-
+
@@ -1575,7 +1803,7 @@
-
+
@@ -1590,7 +1818,7 @@
-
+
@@ -1602,7 +1830,7 @@
-
+
@@ -1614,7 +1842,7 @@
-
+
@@ -1626,7 +1854,7 @@
-
+
@@ -1638,7 +1866,7 @@
-
+
@@ -1650,7 +1878,7 @@
-
+
@@ -1662,7 +1890,7 @@
-
+
@@ -1674,7 +1902,7 @@
-
+
@@ -1686,7 +1914,7 @@
-
+
@@ -1698,7 +1926,7 @@
-
+
@@ -1711,7 +1939,7 @@
-
+
@@ -1721,10 +1949,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -1736,7 +1976,7 @@
-
+
@@ -1748,7 +1988,7 @@
-
+
@@ -1772,17 +2012,25 @@
-
+
+
+
+
+
+
+
+
+
@@ -1823,39 +2071,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1876,13 +2091,6 @@
-
-
-
-
-
-
-
@@ -1926,7 +2134,7 @@
-
+
@@ -1946,7 +2154,7 @@
-
+
@@ -1965,7 +2173,7 @@
-
+
@@ -1981,7 +2189,7 @@
-
+
@@ -1993,7 +2201,7 @@
-
+
@@ -2005,7 +2213,7 @@
-
+
@@ -2017,14 +2225,14 @@
-
+
-
+
@@ -2040,35 +2248,35 @@
-
+
-
+
-
+
-
+
-
+
@@ -2080,21 +2288,21 @@
-
+
-
+
-
+
@@ -2107,7 +2315,7 @@
-
+
@@ -2120,7 +2328,7 @@
-
+
@@ -2134,7 +2342,7 @@
-
+
@@ -2147,7 +2355,7 @@
-
+
@@ -2159,21 +2367,21 @@
-
+
-
+
-
+
@@ -2186,7 +2394,7 @@
-
+
@@ -2199,7 +2407,7 @@
-
+
@@ -2213,7 +2421,7 @@
-
+
@@ -2226,7 +2434,7 @@
-
+
@@ -2238,21 +2446,21 @@
-
+
-
+
-
+
@@ -2265,7 +2473,7 @@
-
+
@@ -2278,7 +2486,7 @@
-
+
@@ -2292,7 +2500,7 @@
-
+
@@ -2305,7 +2513,7 @@
-
+
@@ -2317,21 +2525,21 @@
-
+
-
+
-
+
@@ -2344,7 +2552,7 @@
-
+
@@ -2357,7 +2565,7 @@
-
+
@@ -2371,7 +2579,7 @@
-
+
@@ -2384,7 +2592,7 @@
-
+
@@ -2396,21 +2604,21 @@
-
+
-
+
-
+
@@ -2423,7 +2631,7 @@
-
+
@@ -2436,7 +2644,7 @@
-
+
@@ -2450,7 +2658,7 @@
-
+
@@ -2463,7 +2671,7 @@
-
+
@@ -2562,19 +2770,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -2585,25 +2781,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -2611,13 +2788,6 @@
-
-
-
-
-
-
-
@@ -2625,27 +2795,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -2656,21 +2805,28 @@
-
+
+
-
+
+
+
+
+
+
+
@@ -2681,6 +2837,7 @@
+
@@ -2702,6 +2859,9 @@
+
+
+
@@ -2711,7 +2871,6 @@
-
@@ -2725,7 +2884,6 @@
-
@@ -2745,7 +2903,6 @@
-
@@ -2753,7 +2910,6 @@
-
@@ -2765,7 +2921,6 @@
-
@@ -2783,15 +2938,18 @@
+
+
+
+
-
-
+
\ No newline at end of file
diff --git a/app/core/api/common/captcha/generate/generate_rotate_captcha.go b/app/core/api/common/captcha/generate/generate_rotate_captcha.go
index 8d367f3..b534e20 100644
--- a/app/core/api/common/captcha/generate/generate_rotate_captcha.go
+++ b/app/core/api/common/captcha/generate/generate_rotate_captcha.go
@@ -3,7 +3,6 @@ package generate
import (
"context"
"encoding/json"
- "errors"
"time"
"github.com/redis/go-redis/v9"
@@ -21,7 +20,7 @@ func GenerateRotateCaptcha(captcha rotate.Captcha, redis *redis.Client, ctx cont
}
blockData := captchaData.GetData()
if blockData == nil {
- return nil, errors.New("captcha data is nil")
+ return nil, nil
}
masterImageBase64 := captchaData.GetMasterImage().ToBase64()
thumbImageBase64 := captchaData.GetThumbImage().ToBase64()
diff --git a/app/core/api/common/captcha/generate/generate_slide_basic_captcha.go b/app/core/api/common/captcha/generate/generate_slide_basic_captcha.go
index 852acbd..3341e1d 100644
--- a/app/core/api/common/captcha/generate/generate_slide_basic_captcha.go
+++ b/app/core/api/common/captcha/generate/generate_slide_basic_captcha.go
@@ -3,7 +3,6 @@ package generate
import (
"context"
"encoding/json"
- "errors"
"time"
"github.com/redis/go-redis/v9"
@@ -21,7 +20,7 @@ func GenerateSlideBasicCaptcha(slide slide.Captcha, redis *redis.Client, ctx con
}
blockData := captData.GetData()
if blockData == nil {
- return nil, errors.New("block data is nil")
+ return nil, nil
}
var masterImageBase64, tileImageBase64 string
masterImageBase64 = captData.GetMasterImage().ToBase64()
diff --git a/app/core/api/common/i18n/bundle.go b/app/core/api/common/i18n/bundle.go
index 8ff75ab..91f2002 100644
--- a/app/core/api/common/i18n/bundle.go
+++ b/app/core/api/common/i18n/bundle.go
@@ -10,7 +10,10 @@ func NewBundle(tag language.Tag, configs ...string) *i18n2.Bundle {
bundle := i18n2.NewBundle(tag)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
for _, file := range configs {
- bundle.LoadMessageFile(file)
+ _, err := bundle.LoadMessageFile(file)
+ if err != nil {
+ panic(err)
+ }
}
return bundle
}
diff --git a/app/core/api/common/i18n/cache.go b/app/core/api/common/i18n/cache.go
index b870028..18bbb23 100644
--- a/app/core/api/common/i18n/cache.go
+++ b/app/core/api/common/i18n/cache.go
@@ -9,13 +9,6 @@ import (
"google.golang.org/grpc/metadata"
)
-/*
-type Cache interface {
- GetLocalizer() (*i18n2.Localizer, bool)
- SetLocalizer(l *i18n2.Localizer)
-}
-*/
-
func getLocalizer(ctx context.Context) (*i18n2.Localizer, bool) {
v := ctx.Value(I18nKey)
if l, b := v.(*i18n2.Localizer); b {
@@ -49,14 +42,3 @@ func IsHasI18n(ctx context.Context) bool {
}
return false
}
-
-// func isHasI18n(ctx context.Context) bool {
-// if use, exist := ctx.Value(isUseI18n).(bool); exist {
-// return use
-// }
-// return false
-// }
-//
-// func setHasI18n(ctx context.Context, use bool) context.Context {
-// return context.WithValue(ctx, isUseI18n, use)
-// }
diff --git a/app/core/api/common/i18n/i18n.go b/app/core/api/common/i18n/i18n.go
index 8b8267d..2b6a1ea 100644
--- a/app/core/api/common/i18n/i18n.go
+++ b/app/core/api/common/i18n/i18n.go
@@ -7,37 +7,24 @@ import (
"golang.org/x/text/language"
)
-func FormatText(ctx context.Context, msgId string, defaultText string) string {
- return FormatTextWithData(ctx, msgId, defaultText, nil)
+func FormatText(ctx context.Context, msgId string) string {
+ return FormatTextWithData(ctx, msgId)
}
-func FormatTextWithData(ctx context.Context, msgId string, defaultText string, args map[string]interface{}) string {
- return FormatMessage(ctx, &i18n2.Message{
- ID: msgId,
- Other: defaultText,
- }, args)
-}
-
-func FormatMessage(ctx context.Context, message *i18n2.Message, args map[string]interface{}) string {
- if localizer, ok := getLocalizer(ctx); ok {
- return localizer.MustLocalize(&i18n2.LocalizeConfig{
- DefaultMessage: message,
- TemplateData: args,
- })
+func FormatTextWithData(ctx context.Context, msgId string) string {
+ hasI18n := IsHasI18n(ctx)
+ if !hasI18n {
+ return ""
}
- return formatInternalMessage(message, args)
-}
-
-func formatInternalMessage(message *i18n2.Message, args map[string]interface{}) string {
- if args == nil {
- return message.Other
+ localizer, ok := getLocalizer(ctx)
+ if !ok {
+ return ""
}
- tpl := i18n2.NewMessageTemplate(message)
- msg, err := tpl.Execute("other", args, nil)
- if err != nil {
- panic(err)
+ localizeConfig := &i18n2.LocalizeConfig{
+ MessageID: msgId,
}
- return msg
+ localize := localizer.MustLocalize(localizeConfig)
+ return localize
}
func FetchCurrentLanguageFromCtx(ctx context.Context) (*language.Tag, bool) {
diff --git a/app/core/api/common/i18n/keys.go b/app/core/api/common/i18n/keys.go
index 67c71ec..af93391 100644
--- a/app/core/api/common/i18n/keys.go
+++ b/app/core/api/common/i18n/keys.go
@@ -1,7 +1,7 @@
package i18n
const I18nKey = "i18n"
-const I18nCurrentLangKey = "lang"
+const I18nCurrentLangKey = "language"
var (
defaultLangHeaderKey = "Accept-Language"
diff --git a/app/core/api/common/i18n/parse.go b/app/core/api/common/i18n/parse.go
index 7128781..53505d7 100644
--- a/app/core/api/common/i18n/parse.go
+++ b/app/core/api/common/i18n/parse.go
@@ -5,10 +5,13 @@ import "golang.org/x/text/language"
func MatchCurrentLanguageTag(accept string, supportTags []language.Tag) language.Tag {
langTags, _, err := language.ParseAcceptLanguage(accept)
if err != nil {
- langTags = []language.Tag{language.English}
+ langTags = []language.Tag{language.Chinese}
}
var matcher = language.NewMatcher(supportTags)
_, i, _ := matcher.Match(langTags...)
tag := supportTags[i]
+ if tag == language.Und {
+ tag = language.Chinese
+ }
return tag
}
diff --git a/app/core/api/common/middleware/cors_middleware.go b/app/core/api/common/middleware/cors_middleware.go
index 65476db..50dce4e 100644
--- a/app/core/api/common/middleware/cors_middleware.go
+++ b/app/core/api/common/middleware/cors_middleware.go
@@ -5,8 +5,8 @@ import "net/http"
func CORSMiddleware() func(http.Header) {
return func(header http.Header) {
header.Set("Access-Control-Allow-Origin", "*")
- header.Add("Access-Control-Allow-Headers", "UserHeader1, UserHeader2")
header.Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, PATCH")
- header.Set("Access-Control-Expose-Headers", "Content-Length, Content-Type")
+ header.Set("Access-Control-Expose-Headers", "Content-Length, Content-Type,Authorization,Accept-Language,Origin")
+ header.Set("Access-Control-Allow-Credentials", "true")
}
}
diff --git a/app/core/api/common/middleware/security_headers_middleware.go b/app/core/api/common/middleware/security_headers_middleware.go
index 2d9be78..7781129 100644
--- a/app/core/api/common/middleware/security_headers_middleware.go
+++ b/app/core/api/common/middleware/security_headers_middleware.go
@@ -2,7 +2,7 @@ package middleware
import "net/http"
-func SecurityHeadersMiddleware(w http.ResponseWriter, r *http.Request) {
+func SecurityHeadersMiddleware(r *http.Request) {
r.Header.Set("X-Frame-Options", "DENY")
r.Header.Set("Content-Security-Policy", "default-src 'self'; connect-src *; font-src *; script-src-elem * 'unsafe-inline'; img-src * data:; style-src * 'unsafe-inline';")
r.Header.Set("X-XSS-Protection", "1; mode=block")
diff --git a/app/core/api/common/middleware/unauthorized_callback_middleware.go b/app/core/api/common/middleware/unauthorized_callback_middleware.go
new file mode 100644
index 0000000..61f525f
--- /dev/null
+++ b/app/core/api/common/middleware/unauthorized_callback_middleware.go
@@ -0,0 +1,16 @@
+package middleware
+
+import (
+ "net/http"
+
+ "github.com/zeromicro/go-zero/rest/httpx"
+
+ "schisandra-album-cloud-microservices/app/core/api/common/response"
+)
+
+func UnauthorizedCallbackMiddleware() func(w http.ResponseWriter, r *http.Request, err error) {
+ return func(w http.ResponseWriter, r *http.Request, err error) {
+ // httpx.WriteJson(w, http.StatusUnauthorized, response.ErrorWithCodeMessage(http.StatusUnauthorized, "Unauthorized"))
+ httpx.OkJsonCtx(r.Context(), w, response.ErrorWithCodeMessage(http.StatusUnauthorized, "Unauthorized"))
+ }
+}
diff --git a/app/core/api/common/response/response.go b/app/core/api/common/response/response.go
index 51f44f3..1df88d5 100644
--- a/app/core/api/common/response/response.go
+++ b/app/core/api/common/response/response.go
@@ -71,8 +71,8 @@ func ErrorWithMessage(message string) *types.Response {
}
// ErrorWithI18n returns an error response with the given message.
-func ErrorWithI18n(ctx context.Context, msgId string, defaultMsg string) *types.Response {
- message := i18n.FormatText(ctx, msgId, defaultMsg)
+func ErrorWithI18n(ctx context.Context, msgId string) *types.Response {
+ message := i18n.FormatText(ctx, msgId)
return &types.Response{
Code: 500,
Message: message,
diff --git a/app/core/api/core.api b/app/core/api/core.api
index bf32ff4..6eca108 100644
--- a/app/core/api/core.api
+++ b/app/core/api/core.api
@@ -57,6 +57,7 @@ type (
}
)
+// 短信发送请求参数
type (
SmsSendRequest {
Phone string `json:"phone"`
@@ -65,6 +66,65 @@ type (
}
)
+// 评论请求参数
+type (
+ // 评论提交请求参数
+ CommentRequest {
+ Content string `json:"content"`
+ Images []string `json:"images,optional"`
+ TopicId string `json:"topic_id"`
+ Author string `json:"author"`
+ Key string `json:"key"`
+ Point []int64 `json:"point"`
+ }
+ // 回复评论提交请求参数
+ ReplyCommentRequest {
+ Content string `json:"content"`
+ Images []string `json:"images,optional"`
+ TopicId string `json:"topic_id" `
+ ReplyId int64 `json:"reply_id" `
+ ReplyUser string `json:"reply_user" `
+ Author string `json:"author"`
+ Key string `json:"key"`
+ Point []int64 `json:"point"`
+ }
+ // 回复回复请求参数
+ ReplyReplyRequest {
+ Content string `json:"content"`
+ Images []string `json:"images,optional"`
+ TopicId string `json:"topic_id"`
+ ReplyTo int64 `json:"reply_to"`
+ ReplyId int64 `json:"reply_id"`
+ ReplyUser string `json:"reply_user" `
+ Author string `json:"author"`
+ Key string `json:"key"`
+ Point []int64 `json:"point"`
+ }
+ // 评论列表请求参数
+ CommentListRequest {
+ TopicId string `json:"topic_id"`
+ Page int `json:"page,default=1,optional"`
+ Size int `json:"size,default=5,optional"`
+ IsHot bool `json:"is_hot,default=true,optional"`
+ }
+ // 回复列表请求参数
+ ReplyListRequest {
+ TopicId string `json:"topic_id"`
+ CommentId int64 `json:"comment_id"`
+ Page int `json:"page,default=1,optional"`
+ Size int `json:"size,default=5,optional"`
+ }
+ // 点赞评论的请求参数
+ CommentLikeRequest {
+ TopicId string `json:"topic_id"`
+ CommentId int64 `json:"comment_id"`
+ }
+ CommentDisLikeRequest {
+ TopicId string `json:"topic_id"`
+ CommentId int64 `json:"comment_id"`
+ }
+)
+
// 统一响应参数
type (
Response {
@@ -122,10 +182,8 @@ service core {
}
@server (
- group: websocket // 微服务分组
- prefix: /api/ws // 微服务前缀
- timeout: 10s // 超时时间
- Recover: true // 是否开启自动恢复
+ group: websocket // 微服务分组
+ prefix: /api/ws // 微服务前缀
)
service core {
@handler qrcodeWebsocket
@@ -210,3 +268,37 @@ service core {
get /slide/generate returns (Response)
}
+@server (
+ group: comment // 微服务分组
+ prefix: /api/auth/comment // 微服务前缀
+ timeout: 10s // 超时时间
+ maxBytes: 1048576 // 最大请求大小
+ signature: true // 是否开启签名验证
+ middleware: SecurityHeadersMiddleware,CasbinVerifyMiddleware // 注册中间件
+ MaxConns: true // 是否开启最大连接数限制
+ Recover: true // 是否开启自动恢复
+ jwt: Auth // 是否开启jwt验证
+)
+service core {
+ @handler getCommentList
+ post /list (CommentListRequest) returns (Response)
+
+ @handler getReplyList
+ post /reply/list (ReplyListRequest) returns (Response)
+
+ @handler submitComment
+ post /submit (CommentRequest) returns (Response)
+
+ @handler submitReplyComment
+ post /reply/submit (ReplyCommentRequest) returns (Response)
+
+ @handler submitReplyReply
+ post /reply/reply/submit (ReplyReplyRequest) returns (Response)
+
+ @handler likeComment
+ post /like (CommentLikeRequest) returns (Response)
+
+ @handler dislikeComment
+ post /dislike (CommentDisLikeRequest) returns (Response)
+}
+
diff --git a/app/core/api/core.go b/app/core/api/core.go
index d942b4a..61dd904 100644
--- a/app/core/api/core.go
+++ b/app/core/api/core.go
@@ -23,7 +23,7 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)
- server := rest.MustNewServer(c.RestConf, rest.WithCors())
+ server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(middleware.CORSMiddleware(), nil), rest.WithUnauthorizedCallback(middleware.UnauthorizedCallbackMiddleware()))
defer server.Stop()
// i18n middleware
server.Use(middleware.I18nMiddleware)
diff --git a/app/core/api/etc/core.yaml b/app/core/api/etc/core.yaml
index 90ed653..ac152b1 100644
--- a/app/core/api/etc/core.yaml
+++ b/app/core/api/etc/core.yaml
@@ -6,10 +6,9 @@ Web:
Middlewares:
Log: true
Mysql:
- DataSource: root:1611@tcp(localhost:3306)/schisandra-cloud-album?charset=utf8mb4&parseTime=True&loc=Local
+ DataSource: root:LDQ20020618xxx@tcp(1.95.0.111:3306)/schisandra-cloud-album?charset=utf8mb4&parseTime=True&loc=Local
Auth:
AccessSecret: uOvKLmVfztaXGpNYd4Z0I1SiT7MweJhl
- AccessExpire: 86400
Redis:
Host: 1.95.0.111:6379
Pass: LDQ20020618xxx
diff --git a/app/core/api/internal/config/config.go b/app/core/api/internal/config/config.go
index cdf60f3..a17be18 100644
--- a/app/core/api/internal/config/config.go
+++ b/app/core/api/internal/config/config.go
@@ -9,7 +9,6 @@ type Config struct {
}
Auth struct {
AccessSecret string
- AccessExpire int64
}
Mysql struct {
DataSource string
diff --git a/app/core/api/internal/handler/captcha/generate_rotate_captcha_handler.go b/app/core/api/internal/handler/captcha/generate_rotate_captcha_handler.go
index b1b407c..7ee458f 100644
--- a/app/core/api/internal/handler/captcha/generate_rotate_captcha_handler.go
+++ b/app/core/api/internal/handler/captcha/generate_rotate_captcha_handler.go
@@ -3,7 +3,9 @@ package captcha
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
+
"schisandra-album-cloud-microservices/app/core/api/internal/logic/captcha"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
)
@@ -13,7 +15,8 @@ func GenerateRotateCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := captcha.NewGenerateRotateCaptchaLogic(r.Context(), svcCtx)
resp, err := l.GenerateRotateCaptcha()
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/captcha/generate_slide_basic_captcha_handler.go b/app/core/api/internal/handler/captcha/generate_slide_basic_captcha_handler.go
index 97656cd..1569a1b 100644
--- a/app/core/api/internal/handler/captcha/generate_slide_basic_captcha_handler.go
+++ b/app/core/api/internal/handler/captcha/generate_slide_basic_captcha_handler.go
@@ -3,7 +3,9 @@ package captcha
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
+
"schisandra-album-cloud-microservices/app/core/api/internal/logic/captcha"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
)
@@ -13,7 +15,8 @@ func GenerateSlideBasicCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFu
l := captcha.NewGenerateSlideBasicCaptchaLogic(r.Context(), svcCtx)
resp, err := l.GenerateSlideBasicCaptcha()
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/client/generate_client_id_handler.go b/app/core/api/internal/handler/client/generate_client_id_handler.go
index ce68314..e3c07dc 100644
--- a/app/core/api/internal/handler/client/generate_client_id_handler.go
+++ b/app/core/api/internal/handler/client/generate_client_id_handler.go
@@ -3,6 +3,7 @@ package client
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/utils"
@@ -15,8 +16,9 @@ func GenerateClientIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
clientIP := utils.GetClientIP(r)
l := client.NewGenerateClientIdLogic(r.Context(), svcCtx)
resp, err := l.GenerateClientId(clientIP)
- if err != nil || resp.Code == 500 {
- httpx.ErrorCtx(r.Context(), w, err)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/comment/dislike_comment_handler.go b/app/core/api/internal/handler/comment/dislike_comment_handler.go
new file mode 100644
index 0000000..37a23da
--- /dev/null
+++ b/app/core/api/internal/handler/comment/dislike_comment_handler.go
@@ -0,0 +1,31 @@
+package comment
+
+import (
+ "net/http"
+
+ "github.com/zeromicro/go-zero/core/logx"
+ "github.com/zeromicro/go-zero/rest/httpx"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+)
+
+func DislikeCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ var req types.CommentDisLikeRequest
+ if err := httpx.Parse(r, &req); err != nil {
+ httpx.ErrorCtx(r.Context(), w, err)
+ return
+ }
+
+ l := comment.NewDislikeCommentLogic(r.Context(), svcCtx)
+ resp, err := l.DislikeComment(&req)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
+ } else {
+ httpx.OkJsonCtx(r.Context(), w, resp)
+ }
+ }
+}
diff --git a/app/core/api/internal/handler/comment/get_comment_list_handler.go b/app/core/api/internal/handler/comment/get_comment_list_handler.go
new file mode 100644
index 0000000..623bc86
--- /dev/null
+++ b/app/core/api/internal/handler/comment/get_comment_list_handler.go
@@ -0,0 +1,31 @@
+package comment
+
+import (
+ "net/http"
+
+ "github.com/zeromicro/go-zero/core/logx"
+ "github.com/zeromicro/go-zero/rest/httpx"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+)
+
+func GetCommentListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ var req types.CommentListRequest
+ if err := httpx.Parse(r, &req); err != nil {
+ httpx.ErrorCtx(r.Context(), w, err)
+ return
+ }
+
+ l := comment.NewGetCommentListLogic(r.Context(), svcCtx)
+ resp, err := l.GetCommentList(&req)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
+ } else {
+ httpx.OkJsonCtx(r.Context(), w, resp)
+ }
+ }
+}
diff --git a/app/core/api/internal/handler/comment/get_reply_list_handler.go b/app/core/api/internal/handler/comment/get_reply_list_handler.go
new file mode 100644
index 0000000..22061c1
--- /dev/null
+++ b/app/core/api/internal/handler/comment/get_reply_list_handler.go
@@ -0,0 +1,31 @@
+package comment
+
+import (
+ "net/http"
+
+ "github.com/zeromicro/go-zero/core/logx"
+ "github.com/zeromicro/go-zero/rest/httpx"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+)
+
+func GetReplyListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ var req types.ReplyListRequest
+ if err := httpx.Parse(r, &req); err != nil {
+ httpx.ErrorCtx(r.Context(), w, err)
+ return
+ }
+
+ l := comment.NewGetReplyListLogic(r.Context(), svcCtx)
+ resp, err := l.GetReplyList(&req)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
+ } else {
+ httpx.OkJsonCtx(r.Context(), w, resp)
+ }
+ }
+}
diff --git a/app/core/api/internal/handler/comment/like_comment_handler.go b/app/core/api/internal/handler/comment/like_comment_handler.go
new file mode 100644
index 0000000..046e7e1
--- /dev/null
+++ b/app/core/api/internal/handler/comment/like_comment_handler.go
@@ -0,0 +1,31 @@
+package comment
+
+import (
+ "net/http"
+
+ "github.com/zeromicro/go-zero/core/logx"
+ "github.com/zeromicro/go-zero/rest/httpx"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+)
+
+func LikeCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ var req types.CommentLikeRequest
+ if err := httpx.Parse(r, &req); err != nil {
+ httpx.ErrorCtx(r.Context(), w, err)
+ return
+ }
+
+ l := comment.NewLikeCommentLogic(r.Context(), svcCtx)
+ resp, err := l.LikeComment(&req)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
+ } else {
+ httpx.OkJsonCtx(r.Context(), w, resp)
+ }
+ }
+}
diff --git a/app/core/api/internal/handler/comment/submit_comment_handler.go b/app/core/api/internal/handler/comment/submit_comment_handler.go
new file mode 100644
index 0000000..3879c5d
--- /dev/null
+++ b/app/core/api/internal/handler/comment/submit_comment_handler.go
@@ -0,0 +1,31 @@
+package comment
+
+import (
+ "net/http"
+
+ "github.com/zeromicro/go-zero/core/logx"
+ "github.com/zeromicro/go-zero/rest/httpx"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+)
+
+func SubmitCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ var req types.CommentRequest
+ if err := httpx.Parse(r, &req); err != nil {
+ httpx.ErrorCtx(r.Context(), w, err)
+ return
+ }
+
+ l := comment.NewSubmitCommentLogic(r.Context(), svcCtx)
+ resp, err := l.SubmitComment(&req)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
+ } else {
+ httpx.OkJsonCtx(r.Context(), w, resp)
+ }
+ }
+}
diff --git a/app/core/api/internal/handler/comment/submit_reply_comment_handler.go b/app/core/api/internal/handler/comment/submit_reply_comment_handler.go
new file mode 100644
index 0000000..957f347
--- /dev/null
+++ b/app/core/api/internal/handler/comment/submit_reply_comment_handler.go
@@ -0,0 +1,31 @@
+package comment
+
+import (
+ "net/http"
+
+ "github.com/zeromicro/go-zero/core/logx"
+ "github.com/zeromicro/go-zero/rest/httpx"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+)
+
+func SubmitReplyCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ var req types.ReplyCommentRequest
+ if err := httpx.Parse(r, &req); err != nil {
+ httpx.ErrorCtx(r.Context(), w, err)
+ return
+ }
+
+ l := comment.NewSubmitReplyCommentLogic(r.Context(), svcCtx)
+ resp, err := l.SubmitReplyComment(&req)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
+ } else {
+ httpx.OkJsonCtx(r.Context(), w, resp)
+ }
+ }
+}
diff --git a/app/core/api/internal/handler/comment/submit_reply_reply_handler.go b/app/core/api/internal/handler/comment/submit_reply_reply_handler.go
new file mode 100644
index 0000000..b1e40e7
--- /dev/null
+++ b/app/core/api/internal/handler/comment/submit_reply_reply_handler.go
@@ -0,0 +1,31 @@
+package comment
+
+import (
+ "net/http"
+
+ "github.com/zeromicro/go-zero/core/logx"
+ "github.com/zeromicro/go-zero/rest/httpx"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+)
+
+func SubmitReplyReplyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ var req types.ReplyReplyRequest
+ if err := httpx.Parse(r, &req); err != nil {
+ httpx.ErrorCtx(r.Context(), w, err)
+ return
+ }
+
+ l := comment.NewSubmitReplyReplyLogic(r.Context(), svcCtx)
+ resp, err := l.SubmitReplyReply(&req)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
+ } else {
+ httpx.OkJsonCtx(r.Context(), w, resp)
+ }
+ }
+}
diff --git a/app/core/api/internal/handler/oauth/get_gitee_oauth_url_handler.go b/app/core/api/internal/handler/oauth/get_gitee_oauth_url_handler.go
index 75108e7..73c9bf4 100644
--- a/app/core/api/internal/handler/oauth/get_gitee_oauth_url_handler.go
+++ b/app/core/api/internal/handler/oauth/get_gitee_oauth_url_handler.go
@@ -3,7 +3,9 @@ package oauth
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
+
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
)
@@ -13,7 +15,8 @@ func GetGiteeOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := oauth.NewGetGiteeOauthUrlLogic(r.Context(), svcCtx)
resp, err := l.GetGiteeOauthUrl()
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/oauth/get_github_oauth_url_handler.go b/app/core/api/internal/handler/oauth/get_github_oauth_url_handler.go
index 15ebd37..17eb559 100644
--- a/app/core/api/internal/handler/oauth/get_github_oauth_url_handler.go
+++ b/app/core/api/internal/handler/oauth/get_github_oauth_url_handler.go
@@ -3,7 +3,9 @@ package oauth
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
+
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -20,7 +22,8 @@ func GetGithubOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := oauth.NewGetGithubOauthUrlLogic(r.Context(), svcCtx)
resp, err := l.GetGithubOauthUrl(&req)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/oauth/get_qq_oauth_url_handler.go b/app/core/api/internal/handler/oauth/get_qq_oauth_url_handler.go
index 6520ce9..7700a74 100644
--- a/app/core/api/internal/handler/oauth/get_qq_oauth_url_handler.go
+++ b/app/core/api/internal/handler/oauth/get_qq_oauth_url_handler.go
@@ -3,7 +3,9 @@ package oauth
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
+
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -20,7 +22,8 @@ func GetQqOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := oauth.NewGetQqOauthUrlLogic(r.Context(), svcCtx)
resp, err := l.GetQqOauthUrl(&req)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/oauth/get_wechat_qrcode_handler.go b/app/core/api/internal/handler/oauth/get_wechat_qrcode_handler.go
index 4de5369..74fed7e 100644
--- a/app/core/api/internal/handler/oauth/get_wechat_qrcode_handler.go
+++ b/app/core/api/internal/handler/oauth/get_wechat_qrcode_handler.go
@@ -3,6 +3,7 @@ package oauth
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
@@ -21,7 +22,8 @@ func GetWechatQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := oauth.NewGetWechatQrcodeLogic(r.Context(), svcCtx)
resp, err := l.GetWechatQrcode(r, &req)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/oauth/gitee_callback_handler.go b/app/core/api/internal/handler/oauth/gitee_callback_handler.go
index dd7e34b..d77fcdf 100644
--- a/app/core/api/internal/handler/oauth/gitee_callback_handler.go
+++ b/app/core/api/internal/handler/oauth/gitee_callback_handler.go
@@ -1,8 +1,10 @@
package oauth
import (
+ "errors"
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
@@ -21,7 +23,8 @@ func GiteeCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := oauth.NewGiteeCallbackLogic(r.Context(), svcCtx)
err := l.GiteeCallback(w, r, &req)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
} else {
httpx.Ok(w)
}
diff --git a/app/core/api/internal/handler/oauth/github_callback_handler.go b/app/core/api/internal/handler/oauth/github_callback_handler.go
index 5e99d1e..c28f4a7 100644
--- a/app/core/api/internal/handler/oauth/github_callback_handler.go
+++ b/app/core/api/internal/handler/oauth/github_callback_handler.go
@@ -1,8 +1,10 @@
package oauth
import (
+ "errors"
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
@@ -21,7 +23,8 @@ func GithubCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := oauth.NewGithubCallbackLogic(r.Context(), svcCtx)
err := l.GithubCallback(w, r, &req)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
} else {
httpx.Ok(w)
}
diff --git a/app/core/api/internal/handler/oauth/qq_callback_handler.go b/app/core/api/internal/handler/oauth/qq_callback_handler.go
index 216a1f7..c4880a0 100644
--- a/app/core/api/internal/handler/oauth/qq_callback_handler.go
+++ b/app/core/api/internal/handler/oauth/qq_callback_handler.go
@@ -1,8 +1,10 @@
package oauth
import (
+ "errors"
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
@@ -21,7 +23,8 @@ func QqCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := oauth.NewQqCallbackLogic(r.Context(), svcCtx)
err := l.QqCallback(w, r, &req)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
} else {
httpx.Ok(w)
}
diff --git a/app/core/api/internal/handler/oauth/wechat_callback_handler.go b/app/core/api/internal/handler/oauth/wechat_callback_handler.go
index 7be30f3..530c010 100644
--- a/app/core/api/internal/handler/oauth/wechat_callback_handler.go
+++ b/app/core/api/internal/handler/oauth/wechat_callback_handler.go
@@ -1,8 +1,10 @@
package oauth
import (
+ "errors"
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
@@ -14,7 +16,8 @@ func WechatCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := oauth.NewWechatCallbackLogic(r.Context(), svcCtx)
err := l.WechatCallback(w, r)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
} else {
httpx.Ok(w)
}
diff --git a/app/core/api/internal/handler/routes.go b/app/core/api/internal/handler/routes.go
index ba7c624..6dd9078 100644
--- a/app/core/api/internal/handler/routes.go
+++ b/app/core/api/internal/handler/routes.go
@@ -9,6 +9,7 @@ import (
captcha "schisandra-album-cloud-microservices/app/core/api/internal/handler/captcha"
client "schisandra-album-cloud-microservices/app/core/api/internal/handler/client"
+ comment "schisandra-album-cloud-microservices/app/core/api/internal/handler/comment"
oauth "schisandra-album-cloud-microservices/app/core/api/internal/handler/oauth"
sms "schisandra-album-cloud-microservices/app/core/api/internal/handler/sms"
user "schisandra-album-cloud-microservices/app/core/api/internal/handler/user"
@@ -56,6 +57,54 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithMaxBytes(1048576),
)
+ server.AddRoutes(
+ rest.WithMiddlewares(
+ []rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.CasbinVerifyMiddleware},
+ []rest.Route{
+ {
+ Method: http.MethodPost,
+ Path: "/dislike",
+ Handler: comment.DislikeCommentHandler(serverCtx),
+ },
+ {
+ Method: http.MethodPost,
+ Path: "/like",
+ Handler: comment.LikeCommentHandler(serverCtx),
+ },
+ {
+ Method: http.MethodPost,
+ Path: "/list",
+ Handler: comment.GetCommentListHandler(serverCtx),
+ },
+ {
+ Method: http.MethodPost,
+ Path: "/reply/list",
+ Handler: comment.GetReplyListHandler(serverCtx),
+ },
+ {
+ Method: http.MethodPost,
+ Path: "/reply/reply/submit",
+ Handler: comment.SubmitReplyReplyHandler(serverCtx),
+ },
+ {
+ Method: http.MethodPost,
+ Path: "/reply/submit",
+ Handler: comment.SubmitReplyCommentHandler(serverCtx),
+ },
+ {
+ Method: http.MethodPost,
+ Path: "/submit",
+ Handler: comment.SubmitCommentHandler(serverCtx),
+ },
+ }...,
+ ),
+ rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+ rest.WithSignature(serverCtx.Config.Signature),
+ rest.WithPrefix("/api/auth/comment"),
+ rest.WithTimeout(10000*time.Millisecond),
+ rest.WithMaxBytes(1048576),
+ )
+
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware},
@@ -184,6 +233,5 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
},
rest.WithPrefix("/api/ws"),
- rest.WithTimeout(10000*time.Millisecond),
)
}
diff --git a/app/core/api/internal/handler/sms/send_sms_by_aliyun_handler.go b/app/core/api/internal/handler/sms/send_sms_by_aliyun_handler.go
index 604033b..eab595a 100644
--- a/app/core/api/internal/handler/sms/send_sms_by_aliyun_handler.go
+++ b/app/core/api/internal/handler/sms/send_sms_by_aliyun_handler.go
@@ -3,7 +3,9 @@ package sms
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
+
"schisandra-album-cloud-microservices/app/core/api/internal/logic/sms"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -20,7 +22,8 @@ func SendSmsByAliyunHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := sms.NewSendSmsByAliyunLogic(r.Context(), svcCtx)
resp, err := l.SendSmsByAliyun(&req)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/sms/send_sms_by_smsbao_handler.go b/app/core/api/internal/handler/sms/send_sms_by_smsbao_handler.go
index 0157366..e6fc322 100644
--- a/app/core/api/internal/handler/sms/send_sms_by_smsbao_handler.go
+++ b/app/core/api/internal/handler/sms/send_sms_by_smsbao_handler.go
@@ -3,7 +3,9 @@ package sms
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
+
"schisandra-album-cloud-microservices/app/core/api/internal/logic/sms"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -20,7 +22,8 @@ func SendSmsBySmsbaoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := sms.NewSendSmsBySmsbaoLogic(r.Context(), svcCtx)
resp, err := l.SendSmsBySmsbao(&req)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/sms/send_sms_by_test_handler.go b/app/core/api/internal/handler/sms/send_sms_by_test_handler.go
index cdc7e8e..ed4c9c8 100644
--- a/app/core/api/internal/handler/sms/send_sms_by_test_handler.go
+++ b/app/core/api/internal/handler/sms/send_sms_by_test_handler.go
@@ -3,7 +3,9 @@ package sms
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
+
"schisandra-album-cloud-microservices/app/core/api/internal/logic/sms"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -20,7 +22,8 @@ func SendSmsByTestHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := sms.NewSendSmsByTestLogic(r.Context(), svcCtx)
resp, err := l.SendSmsByTest(&req)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/user/account_login_handler.go b/app/core/api/internal/handler/user/account_login_handler.go
index 86e513f..6f35a40 100644
--- a/app/core/api/internal/handler/user/account_login_handler.go
+++ b/app/core/api/internal/handler/user/account_login_handler.go
@@ -3,6 +3,7 @@ package user
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
@@ -20,8 +21,9 @@ func AccountLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewAccountLoginLogic(r.Context(), svcCtx)
resp, err := l.AccountLogin(w, r, &req)
- if err != nil || resp.Code == 500 {
- httpx.ErrorCtx(r.Context(), w, err)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/user/get_user_device_handler.go b/app/core/api/internal/handler/user/get_user_device_handler.go
index 98e2697..44ac736 100644
--- a/app/core/api/internal/handler/user/get_user_device_handler.go
+++ b/app/core/api/internal/handler/user/get_user_device_handler.go
@@ -1,8 +1,10 @@
package user
import (
+ "errors"
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
@@ -14,7 +16,8 @@ func GetUserDeviceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewGetUserDeviceLogic(r.Context(), svcCtx)
err := l.GetUserDevice(r)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
} else {
httpx.Ok(w)
}
diff --git a/app/core/api/internal/handler/user/phone_login_handler.go b/app/core/api/internal/handler/user/phone_login_handler.go
index 3704a43..439c0b6 100644
--- a/app/core/api/internal/handler/user/phone_login_handler.go
+++ b/app/core/api/internal/handler/user/phone_login_handler.go
@@ -3,6 +3,7 @@ package user
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
@@ -21,7 +22,8 @@ func PhoneLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewPhoneLoginLogic(r.Context(), svcCtx)
resp, err := l.PhoneLogin(r, w, &req)
if err != nil || resp.Code == 500 {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/user/refresh_token_handler.go b/app/core/api/internal/handler/user/refresh_token_handler.go
index 7938c5e..8d17984 100644
--- a/app/core/api/internal/handler/user/refresh_token_handler.go
+++ b/app/core/api/internal/handler/user/refresh_token_handler.go
@@ -3,6 +3,7 @@ package user
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
@@ -14,7 +15,8 @@ func RefreshTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewRefreshTokenLogic(r.Context(), svcCtx)
resp, err := l.RefreshToken(r)
if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/user/reset_password_handler.go b/app/core/api/internal/handler/user/reset_password_handler.go
index a24525b..878c285 100644
--- a/app/core/api/internal/handler/user/reset_password_handler.go
+++ b/app/core/api/internal/handler/user/reset_password_handler.go
@@ -3,6 +3,7 @@ package user
import (
"net/http"
+ "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
@@ -20,8 +21,9 @@ func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewResetPasswordLogic(r.Context(), svcCtx)
resp, err := l.ResetPassword(&req)
- if err != nil || resp.Code == 500 {
- httpx.ErrorCtx(r.Context(), w, err)
+ if err != nil {
+ logx.Error(err)
+ httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
diff --git a/app/core/api/internal/handler/websocket/message_websocket_handler.go b/app/core/api/internal/handler/websocket/message_websocket_handler.go
index 832a6b7..0fc8350 100644
--- a/app/core/api/internal/handler/websocket/message_websocket_handler.go
+++ b/app/core/api/internal/handler/websocket/message_websocket_handler.go
@@ -3,8 +3,6 @@ package websocket
import (
"net/http"
- "github.com/zeromicro/go-zero/rest/httpx"
-
"schisandra-album-cloud-microservices/app/core/api/internal/logic/websocket"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
)
@@ -12,11 +10,6 @@ import (
func MessageWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := websocket.NewMessageWebsocketLogic(r.Context(), svcCtx)
- err := l.MessageWebsocket(w, r)
- if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
- } else {
- httpx.Ok(w)
- }
+ l.MessageWebsocket(w, r)
}
}
diff --git a/app/core/api/internal/handler/websocket/qrcode_websocket_handler.go b/app/core/api/internal/handler/websocket/qrcode_websocket_handler.go
index aeb1192..acfd354 100644
--- a/app/core/api/internal/handler/websocket/qrcode_websocket_handler.go
+++ b/app/core/api/internal/handler/websocket/qrcode_websocket_handler.go
@@ -3,8 +3,6 @@ package websocket
import (
"net/http"
- "github.com/zeromicro/go-zero/rest/httpx"
-
"schisandra-album-cloud-microservices/app/core/api/internal/logic/websocket"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
)
@@ -12,11 +10,6 @@ import (
func QrcodeWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := websocket.NewQrcodeWebsocketLogic(r.Context(), svcCtx)
- err := l.QrcodeWebsocket(w, r)
- if err != nil {
- httpx.ErrorCtx(r.Context(), w, err)
- } else {
- httpx.Ok(w)
- }
+ l.QrcodeWebsocket(w, r)
}
}
diff --git a/app/core/api/internal/logic/client/generate_client_id_logic.go b/app/core/api/internal/logic/client/generate_client_id_logic.go
index 328bc89..0c1cb75 100644
--- a/app/core/api/internal/logic/client/generate_client_id_logic.go
+++ b/app/core/api/internal/logic/client/generate_client_id_logic.go
@@ -36,7 +36,6 @@ func (l *GenerateClientIdLogic) GenerateClientId(clientIP string) (resp *types.R
}
simpleUuid := kgo.SimpleUuid()
if err = l.svcCtx.RedisClient.SetEx(l.ctx, constant.UserClientPrefix+clientIP, simpleUuid, time.Hour*24*7).Err(); err != nil {
- l.Error(err)
return response.Error(), err
}
return response.SuccessWithData(simpleUuid), nil
diff --git a/app/core/api/internal/logic/comment/dislike_comment_logic.go b/app/core/api/internal/logic/comment/dislike_comment_logic.go
new file mode 100644
index 0000000..5a20356
--- /dev/null
+++ b/app/core/api/internal/logic/comment/dislike_comment_logic.go
@@ -0,0 +1,30 @@
+package comment
+
+import (
+ "context"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+
+ "github.com/zeromicro/go-zero/core/logx"
+)
+
+type DislikeCommentLogic struct {
+ logx.Logger
+ ctx context.Context
+ svcCtx *svc.ServiceContext
+}
+
+func NewDislikeCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DislikeCommentLogic {
+ return &DislikeCommentLogic{
+ Logger: logx.WithContext(ctx),
+ ctx: ctx,
+ svcCtx: svcCtx,
+ }
+}
+
+func (l *DislikeCommentLogic) DislikeComment(req *types.CommentDisLikeRequest) (resp *types.Response, err error) {
+ // todo: add your logic here and delete this line
+
+ return
+}
diff --git a/app/core/api/internal/logic/comment/get_comment_list_logic.go b/app/core/api/internal/logic/comment/get_comment_list_logic.go
new file mode 100644
index 0000000..cfa2329
--- /dev/null
+++ b/app/core/api/internal/logic/comment/get_comment_list_logic.go
@@ -0,0 +1,31 @@
+package comment
+
+import (
+ "context"
+
+ "schisandra-album-cloud-microservices/app/core/api/common/response"
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+
+ "github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetCommentListLogic struct {
+ logx.Logger
+ ctx context.Context
+ svcCtx *svc.ServiceContext
+}
+
+func NewGetCommentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCommentListLogic {
+ return &GetCommentListLogic{
+ Logger: logx.WithContext(ctx),
+ ctx: ctx,
+ svcCtx: svcCtx,
+ }
+}
+
+func (l *GetCommentListLogic) GetCommentList(req *types.CommentListRequest) (resp *types.Response, err error) {
+ // todo: add your logic here and delete this line
+
+ return response.Success(), nil
+}
diff --git a/app/core/api/internal/logic/comment/get_reply_list_logic.go b/app/core/api/internal/logic/comment/get_reply_list_logic.go
new file mode 100644
index 0000000..89a0652
--- /dev/null
+++ b/app/core/api/internal/logic/comment/get_reply_list_logic.go
@@ -0,0 +1,30 @@
+package comment
+
+import (
+ "context"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+
+ "github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetReplyListLogic struct {
+ logx.Logger
+ ctx context.Context
+ svcCtx *svc.ServiceContext
+}
+
+func NewGetReplyListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetReplyListLogic {
+ return &GetReplyListLogic{
+ Logger: logx.WithContext(ctx),
+ ctx: ctx,
+ svcCtx: svcCtx,
+ }
+}
+
+func (l *GetReplyListLogic) GetReplyList(req *types.ReplyListRequest) (resp *types.Response, err error) {
+ // todo: add your logic here and delete this line
+
+ return
+}
diff --git a/app/core/api/internal/logic/comment/like_comment_logic.go b/app/core/api/internal/logic/comment/like_comment_logic.go
new file mode 100644
index 0000000..4aa4d4b
--- /dev/null
+++ b/app/core/api/internal/logic/comment/like_comment_logic.go
@@ -0,0 +1,30 @@
+package comment
+
+import (
+ "context"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+
+ "github.com/zeromicro/go-zero/core/logx"
+)
+
+type LikeCommentLogic struct {
+ logx.Logger
+ ctx context.Context
+ svcCtx *svc.ServiceContext
+}
+
+func NewLikeCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeCommentLogic {
+ return &LikeCommentLogic{
+ Logger: logx.WithContext(ctx),
+ ctx: ctx,
+ svcCtx: svcCtx,
+ }
+}
+
+func (l *LikeCommentLogic) LikeComment(req *types.CommentLikeRequest) (resp *types.Response, err error) {
+ // todo: add your logic here and delete this line
+
+ return
+}
diff --git a/app/core/api/internal/logic/comment/submit_comment_logic.go b/app/core/api/internal/logic/comment/submit_comment_logic.go
new file mode 100644
index 0000000..3af8720
--- /dev/null
+++ b/app/core/api/internal/logic/comment/submit_comment_logic.go
@@ -0,0 +1,30 @@
+package comment
+
+import (
+ "context"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+
+ "github.com/zeromicro/go-zero/core/logx"
+)
+
+type SubmitCommentLogic struct {
+ logx.Logger
+ ctx context.Context
+ svcCtx *svc.ServiceContext
+}
+
+func NewSubmitCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitCommentLogic {
+ return &SubmitCommentLogic{
+ Logger: logx.WithContext(ctx),
+ ctx: ctx,
+ svcCtx: svcCtx,
+ }
+}
+
+func (l *SubmitCommentLogic) SubmitComment(req *types.CommentRequest) (resp *types.Response, err error) {
+ // todo: add your logic here and delete this line
+
+ return
+}
diff --git a/app/core/api/internal/logic/comment/submit_reply_comment_logic.go b/app/core/api/internal/logic/comment/submit_reply_comment_logic.go
new file mode 100644
index 0000000..9dd9a7c
--- /dev/null
+++ b/app/core/api/internal/logic/comment/submit_reply_comment_logic.go
@@ -0,0 +1,30 @@
+package comment
+
+import (
+ "context"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+
+ "github.com/zeromicro/go-zero/core/logx"
+)
+
+type SubmitReplyCommentLogic struct {
+ logx.Logger
+ ctx context.Context
+ svcCtx *svc.ServiceContext
+}
+
+func NewSubmitReplyCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitReplyCommentLogic {
+ return &SubmitReplyCommentLogic{
+ Logger: logx.WithContext(ctx),
+ ctx: ctx,
+ svcCtx: svcCtx,
+ }
+}
+
+func (l *SubmitReplyCommentLogic) SubmitReplyComment(req *types.ReplyCommentRequest) (resp *types.Response, err error) {
+ // todo: add your logic here and delete this line
+
+ return
+}
diff --git a/app/core/api/internal/logic/comment/submit_reply_reply_logic.go b/app/core/api/internal/logic/comment/submit_reply_reply_logic.go
new file mode 100644
index 0000000..96fb767
--- /dev/null
+++ b/app/core/api/internal/logic/comment/submit_reply_reply_logic.go
@@ -0,0 +1,30 @@
+package comment
+
+import (
+ "context"
+
+ "schisandra-album-cloud-microservices/app/core/api/internal/svc"
+ "schisandra-album-cloud-microservices/app/core/api/internal/types"
+
+ "github.com/zeromicro/go-zero/core/logx"
+)
+
+type SubmitReplyReplyLogic struct {
+ logx.Logger
+ ctx context.Context
+ svcCtx *svc.ServiceContext
+}
+
+func NewSubmitReplyReplyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitReplyReplyLogic {
+ return &SubmitReplyReplyLogic{
+ Logger: logx.WithContext(ctx),
+ ctx: ctx,
+ svcCtx: svcCtx,
+ }
+}
+
+func (l *SubmitReplyReplyLogic) SubmitReplyReply(req *types.ReplyReplyRequest) (resp *types.Response, err error) {
+ // todo: add your logic here and delete this line
+
+ return
+}
diff --git a/app/core/api/internal/logic/oauth/github_callback_logic.go b/app/core/api/internal/logic/oauth/github_callback_logic.go
index 3dbdddb..1062e00 100644
--- a/app/core/api/internal/logic/oauth/github_callback_logic.go
+++ b/app/core/api/internal/logic/oauth/github_callback_logic.go
@@ -3,7 +3,6 @@ package oauth
import (
"context"
"encoding/json"
- "errors"
"fmt"
"net/http"
"strconv"
@@ -79,7 +78,7 @@ func (l *GithubCallbackLogic) GithubCallback(w http.ResponseWriter, r *http.Requ
}
if token == nil {
- return errors.New("failed to get token")
+ return nil
}
// 获取用户信息
@@ -90,7 +89,7 @@ func (l *GithubCallbackLogic) GithubCallback(w http.ResponseWriter, r *http.Requ
}
if userInfo == nil {
- return errors.New("failed to get user info")
+ return nil
}
// 处理用户信息
diff --git a/app/core/api/internal/logic/oauth/qq_callback_logic.go b/app/core/api/internal/logic/oauth/qq_callback_logic.go
index 82f0a8a..86e0b15 100644
--- a/app/core/api/internal/logic/oauth/qq_callback_logic.go
+++ b/app/core/api/internal/logic/oauth/qq_callback_logic.go
@@ -3,7 +3,6 @@ package oauth
import (
"context"
"encoding/json"
- "errors"
"fmt"
"net/http"
"strconv"
@@ -75,7 +74,7 @@ func (l *QqCallbackLogic) QqCallback(w http.ResponseWriter, r *http.Request, req
return err
}
if token == nil {
- return errors.New("get qq token failed")
+ return nil
}
// 通过 token 获取 openid
diff --git a/app/core/api/internal/logic/oauth/wechat_callback_logic.go b/app/core/api/internal/logic/oauth/wechat_callback_logic.go
index 9519874..06d1842 100644
--- a/app/core/api/internal/logic/oauth/wechat_callback_logic.go
+++ b/app/core/api/internal/logic/oauth/wechat_callback_logic.go
@@ -61,9 +61,9 @@ func (l *WechatCallbackLogic) WechatCallback(w http.ResponseWriter, r *http.Requ
key := strings.TrimPrefix(msg.EventKey, "qrscene_")
err = l.HandlerWechatLogin(msg.FromUserName, key, w, r)
if err != nil {
- return messages.NewText(i18n.FormatText(l.ctx, "login.loginFailed", "登录失败"))
+ return messages.NewText(i18n.FormatText(l.ctx, "login.loginFailed"))
}
- return messages.NewText(i18n.FormatText(l.ctx, "login.loginSuccess", "登录成功"))
+ return messages.NewText(i18n.FormatText(l.ctx, "login.loginSuccess"))
case models.CALLBACK_EVENT_UNSUBSCRIBE:
msg := models.EventUnSubscribe{}
@@ -83,9 +83,9 @@ func (l *WechatCallbackLogic) WechatCallback(w http.ResponseWriter, r *http.Requ
}
err = l.HandlerWechatLogin(msg.FromUserName, msg.EventKey, w, r)
if err != nil {
- return messages.NewText(i18n.FormatText(l.ctx, "login.loginFailed", "登录失败"))
+ return messages.NewText(i18n.FormatText(l.ctx, "login.loginFailed"))
}
- return messages.NewText(i18n.FormatText(l.ctx, "login.loginSuccess", "登录成功"))
+ return messages.NewText(i18n.FormatText(l.ctx, "login.loginSuccess"))
}
@@ -101,11 +101,11 @@ func (l *WechatCallbackLogic) WechatCallback(w http.ResponseWriter, r *http.Requ
})
if err != nil {
- panic(err)
+ return err
}
err = helper.HttpResponseSend(rs, w)
if err != nil {
- panic(err)
+ return err
}
return nil
}
diff --git a/app/core/api/internal/logic/sms/send_sms_by_aliyun_logic.go b/app/core/api/internal/logic/sms/send_sms_by_aliyun_logic.go
index 711bd54..6dcec57 100644
--- a/app/core/api/internal/logic/sms/send_sms_by_aliyun_logic.go
+++ b/app/core/api/internal/logic/sms/send_sms_by_aliyun_logic.go
@@ -36,15 +36,15 @@ func (l *SendSmsByAliyunLogic) SendSmsByAliyun(req *types.SmsSendRequest) (resp
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
if !checkRotateData {
- return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure", "验证码错误"), nil
+ return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure"), nil
}
isPhone := utils.IsPhone(req.Phone)
if !isPhone {
- return response.ErrorWithI18n(l.ctx, "login.phoneFormatError", "手机号格式错误"), nil
+ return response.ErrorWithI18n(l.ctx, "login.phoneFormatError"), nil
}
val := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
if val != "" {
- return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently", "验证码发送过于频繁,请稍后再试"), nil
+ return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently"), nil
}
sms := gosms.NewParser(gateways.Gateways{
ALiYun: aliyun.ALiYun{
@@ -56,7 +56,7 @@ func (l *SendSmsByAliyunLogic) SendSmsByAliyun(req *types.SmsSendRequest) (resp
code := utils.GenValidateCode(6)
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
if wrong != nil {
- return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed", "验证码发送失败"), wrong
+ return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), wrong
}
_, err = sms.Send(req.Phone, gosms.MapStringAny{
"content": "您的验证码是:****。请不要把验证码泄露给其他人。",
@@ -67,7 +67,7 @@ func (l *SendSmsByAliyunLogic) SendSmsByAliyun(req *types.SmsSendRequest) (resp
},
}, nil)
if err != nil {
- return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed", "验证码发送失败"), err
+ return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), err
}
return response.Success(), nil
}
diff --git a/app/core/api/internal/logic/sms/send_sms_by_smsbao_logic.go b/app/core/api/internal/logic/sms/send_sms_by_smsbao_logic.go
index 6d18dda..1b745b1 100644
--- a/app/core/api/internal/logic/sms/send_sms_by_smsbao_logic.go
+++ b/app/core/api/internal/logic/sms/send_sms_by_smsbao_logic.go
@@ -35,15 +35,15 @@ func NewSendSmsBySmsbaoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *S
func (l *SendSmsBySmsbaoLogic) SendSmsBySmsbao(req *types.SmsSendRequest) (resp *types.Response, err error) {
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
if !checkRotateData {
- return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure", "验证码错误"), nil
+ return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure"), nil
}
isPhone := utils.IsPhone(req.Phone)
if !isPhone {
- return response.ErrorWithI18n(l.ctx, "login.phoneFormatError", "手机号格式错误"), nil
+ return response.ErrorWithI18n(l.ctx, "login.phoneFormatError"), nil
}
val := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
if val != "" {
- return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently", "验证码发送过于频繁,请稍后再试"), nil
+ return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently"), nil
}
sms := gosms.NewParser(gateways.Gateways{
SmsBao: smsbao.SmsBao{
@@ -54,13 +54,13 @@ func (l *SendSmsBySmsbaoLogic) SendSmsBySmsbao(req *types.SmsSendRequest) (resp
code := utils.GenValidateCode(6)
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
if wrong != nil {
- return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed", "验证码发送失败"), wrong
+ return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), wrong
}
_, err = sms.Send(req.Phone, gosms.MapStringAny{
"content": "您的验证码是:" + code + "。请不要把验证码泄露给其他人。",
}, nil)
if err != nil {
- return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed", "验证码发送失败"), err
+ return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), err
}
return response.Success(), nil
}
diff --git a/app/core/api/internal/logic/sms/send_sms_by_test_logic.go b/app/core/api/internal/logic/sms/send_sms_by_test_logic.go
index e7aaa3a..297e6bc 100644
--- a/app/core/api/internal/logic/sms/send_sms_by_test_logic.go
+++ b/app/core/api/internal/logic/sms/send_sms_by_test_logic.go
@@ -31,20 +31,20 @@ func NewSendSmsByTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sen
func (l *SendSmsByTestLogic) SendSmsByTest(req *types.SmsSendRequest) (resp *types.Response, err error) {
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
if !checkRotateData {
- return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure", "验证码错误"), nil
+ return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure"), nil
}
isPhone := utils.IsPhone(req.Phone)
if !isPhone {
- return response.ErrorWithI18n(l.ctx, "login.phoneFormatError", "手机号格式错误"), nil
+ return response.ErrorWithI18n(l.ctx, "login.phoneFormatError"), nil
}
val := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
if val != "" {
- return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently", "验证码发送过于频繁,请稍后再试"), nil
+ return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently"), nil
}
code := utils.GenValidateCode(6)
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
if wrong != nil {
- return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed", "验证码发送失败"), wrong
+ return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), wrong
}
return response.Success(), nil
}
diff --git a/app/core/api/internal/logic/user/account_login_logic.go b/app/core/api/internal/logic/user/account_login_logic.go
index e6dbb39..306f7a6 100644
--- a/app/core/api/internal/logic/user/account_login_logic.go
+++ b/app/core/api/internal/logic/user/account_login_logic.go
@@ -36,7 +36,7 @@ func NewAccountLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Acco
func (l *AccountLoginLogic) AccountLogin(w http.ResponseWriter, r *http.Request, req *types.AccountLoginRequest) (resp *types.Response, err error) {
verifyResult := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
if !verifyResult {
- return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure", "验证失败!"), nil
+ return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure"), nil
}
var user *ent.ScaAuthUser
var query *ent.ScaAuthUserQuery
@@ -49,23 +49,27 @@ func (l *AccountLoginLogic) AccountLogin(w http.ResponseWriter, r *http.Request,
case utils.IsUsername(req.Account):
query = l.svcCtx.MySQLClient.ScaAuthUser.Query().Where(scaauthuser.UsernameEQ(req.Account), scaauthuser.DeletedEQ(0))
default:
- return response.ErrorWithI18n(l.ctx, "login.invalidAccount", "无效账号!"), nil
+ return response.ErrorWithI18n(l.ctx, "login.invalidAccount"), nil
}
user, err = query.First(l.ctx)
if err != nil {
if ent.IsNotFound(err) {
- return response.ErrorWithI18n(l.ctx, "login.userNotRegistered", "用户未注册!"), nil
+ return response.ErrorWithI18n(l.ctx, "login.userNotRegistered"), nil
}
return nil, err
}
if !utils.Verify(user.Password, req.Password) {
- return response.ErrorWithI18n(l.ctx, "login.invalidPassword", "密码错误!"), nil
+ return response.ErrorWithI18n(l.ctx, "login.invalidPassword"), nil
}
data, result := HandleUserLogin(user, l.svcCtx, req.AutoLogin, r, w, l.ctx)
if !result {
- return response.ErrorWithI18n(l.ctx, "login.loginFailed", "登录失败!"), nil
+ return response.ErrorWithI18n(l.ctx, "login.loginFailed"), nil
+ }
+ // 记录用户登录设备
+ if !GetUserLoginDevice(user.UID, r, l.svcCtx.Ip2Region, l.svcCtx.MySQLClient, l.ctx) {
+ return response.ErrorWithI18n(l.ctx, "login.loginFailed"), nil
}
return response.SuccessWithData(data), nil
}
@@ -95,32 +99,26 @@ func HandleUserLogin(user *ent.ScaAuthUser, svcCtx *svc.ServiceContext, autoLogi
}
redisToken := types.RedisToken{
- AccessToken: accessToken,
- UID: user.UID,
+ AccessToken: accessToken,
+ RefreshToken: refreshToken,
+ UID: user.UID,
}
err := svcCtx.RedisClient.Set(ctx, constant.UserTokenPrefix+user.UID, redisToken, days).Err()
if err != nil {
logc.Error(ctx, err)
return nil, false
}
- sessionData := types.SessionData{
- RefreshToken: refreshToken,
- UID: user.UID,
- }
session, err := svcCtx.Session.Get(r, constant.SESSION_KEY)
if err != nil {
logc.Error(ctx, err)
return nil, false
}
- session.Values[constant.SESSION_KEY] = sessionData
+ session.Values["refresh_token"] = refreshToken
+ session.Values["uid"] = user.UID
err = session.Save(r, w)
if err != nil {
return nil, false
}
- // 记录用户登录设备
- if !GetUserLoginDevice(user.UID, r, svcCtx.Ip2Region, svcCtx.MySQLClient, ctx) {
- return nil, false
- }
return &data, true
}
diff --git a/app/core/api/internal/logic/user/get_user_device_logic.go b/app/core/api/internal/logic/user/get_user_device_logic.go
index 7df3eb8..c004771 100644
--- a/app/core/api/internal/logic/user/get_user_device_logic.go
+++ b/app/core/api/internal/logic/user/get_user_device_logic.go
@@ -39,7 +39,7 @@ func (l *GetUserDeviceLogic) GetUserDevice(r *http.Request) error {
}
sessionData, ok := session.Values[constant.SESSION_KEY]
if !ok {
- return errors.New("User not found or device not found")
+ return errors.New("user session not found")
}
var data types.SessionData
err = json.Unmarshal(sessionData.([]byte), &data)
@@ -49,7 +49,7 @@ func (l *GetUserDeviceLogic) GetUserDevice(r *http.Request) error {
res := GetUserLoginDevice(data.UID, r, l.svcCtx.Ip2Region, l.svcCtx.MySQLClient, l.ctx)
if !res {
- return errors.New("User not found or device not found")
+ return errors.New("user device not found")
}
return nil
}
diff --git a/app/core/api/internal/logic/user/phone_login_logic.go b/app/core/api/internal/logic/user/phone_login_logic.go
index 2656c1a..2b2a2a7 100644
--- a/app/core/api/internal/logic/user/phone_login_logic.go
+++ b/app/core/api/internal/logic/user/phone_login_logic.go
@@ -34,19 +34,19 @@ func NewPhoneLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PhoneL
func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, w http.ResponseWriter, req *types.PhoneLoginRequest) (resp *types.Response, err error) {
if !utils.IsPhone(req.Phone) {
- return response.ErrorWithI18n(l.ctx, "login.phoneFormatError", "手机号格式错误"), nil
+ return response.ErrorWithI18n(l.ctx, "login.phoneFormatError"), nil
}
code := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
if code == "" {
- return response.ErrorWithI18n(l.ctx, "login.captchaExpired", "验证码已过期"), nil
+ return response.ErrorWithI18n(l.ctx, "login.captchaExpired"), nil
}
if req.Captcha != code {
- return response.ErrorWithI18n(l.ctx, "login.captchaError", "验证码错误"), nil
+ return response.ErrorWithI18n(l.ctx, "login.captchaError"), nil
}
user, err := l.svcCtx.MySQLClient.ScaAuthUser.Query().Where(scaauthuser.Phone(req.Phone), scaauthuser.Deleted(0)).First(l.ctx)
tx, wrong := l.svcCtx.MySQLClient.Tx(l.ctx)
if wrong != nil {
- return response.ErrorWithI18n(l.ctx, "login.loginFailed", "登录失败"), err
+ return response.ErrorWithI18n(l.ctx, "login.loginFailed"), err
}
if ent.IsNotFound(err) {
uid := idgen.NextId()
@@ -64,17 +64,21 @@ func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, w http.ResponseWriter, req
Save(l.ctx)
if fault != nil {
err = tx.Rollback()
- return response.ErrorWithI18n(l.ctx, "login.registerError", "注册失败"), err
+ return response.ErrorWithI18n(l.ctx, "login.registerError"), err
}
_, err = l.svcCtx.CasbinEnforcer.AddRoleForUser(uidStr, constant.User)
if err != nil {
err = tx.Rollback()
- return response.ErrorWithI18n(l.ctx, "login.registerError", "注册失败"), err
+ return response.ErrorWithI18n(l.ctx, "login.registerError"), err
}
data, result := HandleUserLogin(addUser, l.svcCtx, req.AutoLogin, r, w, l.ctx)
if !result {
err = tx.Rollback()
- return response.ErrorWithI18n(l.ctx, "login.registerError", "注册失败"), err
+ return response.ErrorWithI18n(l.ctx, "login.registerError"), err
+ }
+ // 记录用户登录设备
+ if !GetUserLoginDevice(addUser.UID, r, l.svcCtx.Ip2Region, l.svcCtx.MySQLClient, l.ctx) {
+ return response.ErrorWithI18n(l.ctx, "login.registerError"), nil
}
err = tx.Commit()
if err != nil {
@@ -85,7 +89,11 @@ func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, w http.ResponseWriter, req
data, result := HandleUserLogin(user, l.svcCtx, req.AutoLogin, r, w, l.ctx)
if !result {
err = tx.Rollback()
- return response.ErrorWithI18n(l.ctx, "login.loginFailed", "登录失败"), err
+ return response.ErrorWithI18n(l.ctx, "login.loginFailed"), err
+ }
+ // 记录用户登录设备
+ if !GetUserLoginDevice(user.UID, r, l.svcCtx.Ip2Region, l.svcCtx.MySQLClient, l.ctx) {
+ return response.ErrorWithI18n(l.ctx, "login.loginFailed"), nil
}
err = tx.Commit()
if err != nil {
@@ -93,6 +101,6 @@ func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, w http.ResponseWriter, req
}
return response.SuccessWithData(data), nil
} else {
- return response.ErrorWithI18n(l.ctx, "login.loginFailed", "登录失败"), nil
+ return response.ErrorWithI18n(l.ctx, "login.loginFailed"), nil
}
}
diff --git a/app/core/api/internal/logic/user/refresh_token_logic.go b/app/core/api/internal/logic/user/refresh_token_logic.go
index 46160f9..03ca6ab 100644
--- a/app/core/api/internal/logic/user/refresh_token_logic.go
+++ b/app/core/api/internal/logic/user/refresh_token_logic.go
@@ -34,28 +34,41 @@ func (l *RefreshTokenLogic) RefreshToken(r *http.Request) (resp *types.Response,
if err != nil {
return response.ErrorWithCode(403), err
}
- sessionData, ok := session.Values[constant.SESSION_KEY]
+ refreshSessionToken, ok := session.Values["refresh_token"].(string)
if !ok {
- return response.ErrorWithCode(403), err
+ return response.ErrorWithCode(403), nil
}
- data := types.SessionData{}
- err = json.Unmarshal(sessionData.([]byte), &data)
+ userId, ok := session.Values["uid"].(string)
+ if !ok {
+ return response.ErrorWithCode(403), nil
+ }
+ tokenData := l.svcCtx.RedisClient.Get(l.ctx, constant.UserTokenPrefix+userId).Val()
+ if tokenData == "" {
+ return response.ErrorWithCode(403), nil
+ }
+ redisTokenData := types.RedisToken{}
+ err = json.Unmarshal([]byte(tokenData), &redisTokenData)
if err != nil {
return response.ErrorWithCode(403), err
}
- refreshToken, result := jwt.ParseRefreshToken(l.svcCtx.Config.Auth.AccessSecret, data.RefreshToken)
+ if redisTokenData.RefreshToken != refreshSessionToken {
+ return response.ErrorWithCode(403), nil
+ }
+
+ refreshToken, result := jwt.ParseRefreshToken(l.svcCtx.Config.Auth.AccessSecret, refreshSessionToken)
if !result {
- return response.ErrorWithCode(403), err
+ return response.ErrorWithCode(403), nil
}
accessToken := jwt.GenerateAccessToken(l.svcCtx.Config.Auth.AccessSecret, jwt.AccessJWTPayload{
UserID: refreshToken.UserID,
})
if accessToken == "" {
- return response.ErrorWithCode(403), err
+ return response.ErrorWithCode(403), nil
}
redisToken := types.RedisToken{
- AccessToken: accessToken,
- UID: refreshToken.UserID,
+ AccessToken: accessToken,
+ RefreshToken: refreshSessionToken,
+ UID: refreshToken.UserID,
}
err = l.svcCtx.RedisClient.Set(l.ctx, constant.UserTokenPrefix+refreshToken.UserID, redisToken, time.Hour*24*7).Err()
if err != nil {
diff --git a/app/core/api/internal/logic/user/reset_password_logic.go b/app/core/api/internal/logic/user/reset_password_logic.go
index 382645c..929af70 100644
--- a/app/core/api/internal/logic/user/reset_password_logic.go
+++ b/app/core/api/internal/logic/user/reset_password_logic.go
@@ -30,36 +30,36 @@ func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Res
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (resp *types.Response, err error) {
if !utils.IsPhone(req.Phone) {
- return response.ErrorWithI18n(l.ctx, "login.phoneFormatError", "手机号格式错误"), nil
+ return response.ErrorWithI18n(l.ctx, "login.phoneFormatError"), nil
}
if req.Password != req.Repassword {
- return response.ErrorWithI18n(l.ctx, "login.passwordNotMatch", "两次密码输入不一致"), nil
+ return response.ErrorWithI18n(l.ctx, "login.passwordNotMatch"), nil
}
if !utils.IsPassword(req.Password) {
- return response.ErrorWithI18n(l.ctx, "login.passwordFormatError", "密码格式错误"), nil
+ return response.ErrorWithI18n(l.ctx, "login.passwordFormatError"), nil
}
code := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
if code == "" {
- return response.ErrorWithI18n(l.ctx, "login.captchaExpired", "验证码已过期"), nil
+ return response.ErrorWithI18n(l.ctx, "login.captchaExpired"), nil
}
if req.Captcha != code {
- return response.ErrorWithI18n(l.ctx, "login.captchaError", "验证码错误"), nil
+ return response.ErrorWithI18n(l.ctx, "login.captchaError"), nil
}
// 验证码检查通过后立即删除或标记为已使用
if err = l.svcCtx.RedisClient.Del(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Err(); err != nil {
- return response.ErrorWithI18n(l.ctx, "login.captchaError", "验证码错误"), nil
+ return response.ErrorWithI18n(l.ctx, "login.captchaError"), err
}
user, err := l.svcCtx.MySQLClient.ScaAuthUser.Query().Where(scaauthuser.Phone(req.Phone), scaauthuser.Deleted(constant.NotDeleted)).First(l.ctx)
if err != nil && ent.IsNotFound(err) {
- return response.ErrorWithI18n(l.ctx, "login.userNotRegistered", "用户未注册"), nil
+ return response.ErrorWithI18n(l.ctx, "login.userNotRegistered"), err
}
encrypt, err := utils.Encrypt(req.Password)
if err != nil {
- return response.ErrorWithI18n(l.ctx, "login.resetPasswordError", "重置密码失败"), nil
+ return response.ErrorWithI18n(l.ctx, "login.resetPasswordError"), err
}
err = user.Update().SetPassword(encrypt).Exec(l.ctx)
if err != nil {
- return response.ErrorWithI18n(l.ctx, "login.resetPasswordError", "重置密码失败"), err
+ return response.ErrorWithI18n(l.ctx, "login.resetPasswordError"), err
}
return response.Success(), nil
}
diff --git a/app/core/api/internal/logic/websocket/message_websocket_logic.go b/app/core/api/internal/logic/websocket/message_websocket_logic.go
index 3f88c6a..747f7db 100644
--- a/app/core/api/internal/logic/websocket/message_websocket_logic.go
+++ b/app/core/api/internal/logic/websocket/message_websocket_logic.go
@@ -42,7 +42,7 @@ var MessageWebSocketHandler *MessageWebSocket
func InitializeWebSocketHandler(svcCtx *svc.ServiceContext) {
MessageWebSocketHandler = NewMessageWebSocket(svcCtx)
}
-func (l *MessageWebsocketLogic) MessageWebsocket(w http.ResponseWriter, r *http.Request) error {
+func (l *MessageWebsocketLogic) MessageWebsocket(w http.ResponseWriter, r *http.Request) {
upgrader := gws.NewUpgrader(MessageWebSocketHandler, &gws.ServerOption{
HandshakeTimeout: 5 * time.Second, // 握手超时时间
ReadBufferSize: 1024, // 读缓冲区大小
@@ -71,12 +71,11 @@ func (l *MessageWebsocketLogic) MessageWebsocket(w http.ResponseWriter, r *http.
})
socket, err := upgrader.Upgrade(w, r)
if err != nil {
- return err
+ panic(err)
}
go func() {
socket.ReadLoop() // 此处阻塞会使请求上下文不能顺利被GC
}()
- return nil
}
// NewMessageWebSocket 创建WebSocket实例
diff --git a/app/core/api/internal/logic/websocket/qrcode_websocket_logic.go b/app/core/api/internal/logic/websocket/qrcode_websocket_logic.go
index 0039f29..5e84e33 100644
--- a/app/core/api/internal/logic/websocket/qrcode_websocket_logic.go
+++ b/app/core/api/internal/logic/websocket/qrcode_websocket_logic.go
@@ -40,7 +40,7 @@ type QrcodeWebSocket struct {
var QrcodeWebSocketHandler = NewWebSocket()
-func (l *QrcodeWebsocketLogic) QrcodeWebsocket(w http.ResponseWriter, r *http.Request) error {
+func (l *QrcodeWebsocketLogic) QrcodeWebsocket(w http.ResponseWriter, r *http.Request) {
upgrader := gws.NewUpgrader(QrcodeWebSocketHandler, &gws.ServerOption{
HandshakeTimeout: 5 * time.Second, // 握手超时时间
ReadBufferSize: 1024, // 读缓冲区大小
@@ -66,12 +66,11 @@ func (l *QrcodeWebsocketLogic) QrcodeWebsocket(w http.ResponseWriter, r *http.Re
})
socket, err := upgrader.Upgrade(w, r)
if err != nil {
- return err
+ panic(err)
}
go func() {
socket.ReadLoop() // 此处阻塞会使请求上下文不能顺利被GC
}()
- return nil
}
// MustLoad 从session中加载数据
diff --git a/app/core/api/internal/middleware/casbinverify_middleware.go b/app/core/api/internal/middleware/casbinverify_middleware.go
new file mode 100644
index 0000000..8a5a78e
--- /dev/null
+++ b/app/core/api/internal/middleware/casbinverify_middleware.go
@@ -0,0 +1,29 @@
+package middleware
+
+import (
+ "net/http"
+
+ "github.com/casbin/casbin/v2"
+)
+
+type CasbinVerifyMiddleware struct {
+ casbin *casbin.CachedEnforcer
+}
+
+func NewCasbinVerifyMiddleware(casbin *casbin.CachedEnforcer) *CasbinVerifyMiddleware {
+ return &CasbinVerifyMiddleware{
+ casbin: casbin,
+ }
+}
+
+func (m *CasbinVerifyMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ userId := r.Context().Value("user_id")
+ correct, err := m.casbin.Enforce(userId, r.URL.Path, r.Method)
+ if err != nil || !correct {
+ http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
+ return
+ }
+ next(w, r)
+ }
+}
diff --git a/app/core/api/internal/middleware/securityheaders_middleware.go b/app/core/api/internal/middleware/securityheaders_middleware.go
index 637d1f1..3b58cfe 100644
--- a/app/core/api/internal/middleware/securityheaders_middleware.go
+++ b/app/core/api/internal/middleware/securityheaders_middleware.go
@@ -15,7 +15,7 @@ func NewSecurityHeadersMiddleware() *SecurityHeadersMiddleware {
func (m *SecurityHeadersMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
- middleware.SecurityHeadersMiddleware(w, r)
+ middleware.SecurityHeadersMiddleware(r)
next(w, r)
}
}
diff --git a/app/core/api/internal/svc/service_context.go b/app/core/api/internal/svc/service_context.go
index 749289b..1ad2118 100644
--- a/app/core/api/internal/svc/service_context.go
+++ b/app/core/api/internal/svc/service_context.go
@@ -30,6 +30,7 @@ import (
type ServiceContext struct {
Config config.Config
SecurityHeadersMiddleware rest.Middleware
+ CasbinVerifyMiddleware rest.Middleware
MySQLClient *ent.Client
RedisClient *redis.Client
MongoClient *mongo.Database
@@ -43,15 +44,17 @@ type ServiceContext struct {
}
func NewServiceContext(c config.Config) *ServiceContext {
+ casbinEnforcer := casbinx.NewCasbin(c.Mysql.DataSource)
return &ServiceContext{
Config: c,
SecurityHeadersMiddleware: middleware.NewSecurityHeadersMiddleware().Handle,
+ CasbinVerifyMiddleware: middleware.NewCasbinVerifyMiddleware(casbinEnforcer).Handle,
MySQLClient: mysql.NewMySQL(c.Mysql.DataSource),
RedisClient: redisx.NewRedis(c.Redis.Host, c.Redis.Pass, c.Redis.DB),
MongoClient: mongodb.NewMongoDB(c.Mongo.Uri, c.Mongo.Username, c.Mongo.Password, c.Mongo.AuthSource, c.Mongo.Database),
Session: redis_session.NewRedisSession(c.Redis.Host, c.Redis.Pass),
Ip2Region: ip2region.NewIP2Region(),
- CasbinEnforcer: casbinx.NewCasbin(c.Mysql.DataSource),
+ CasbinEnforcer: casbinEnforcer,
WechatPublic: wechat_public.NewWechatPublic(c.Wechat.AppID, c.Wechat.AppSecret, c.Wechat.Token, c.Wechat.AESKey, c.Redis.Host, c.Redis.Pass, c.Redis.DB),
Sensitive: sensitivex.NewSensitive(),
RotateCaptcha: captcha.NewRotateCaptcha(),
diff --git a/app/core/api/internal/types/redis_token.go b/app/core/api/internal/types/redis_token.go
index ec2c23c..a7fa5ba 100644
--- a/app/core/api/internal/types/redis_token.go
+++ b/app/core/api/internal/types/redis_token.go
@@ -3,8 +3,9 @@ package types
import "encoding/json"
type RedisToken struct {
- AccessToken string `json:"access_token"`
- UID string `json:"uid"`
+ AccessToken string `json:"access_token"`
+ RefreshToken string `json:"refresh_token"`
+ UID string `json:"uid"`
}
func (res RedisToken) MarshalBinary() ([]byte, error) {
diff --git a/app/core/api/internal/types/types.go b/app/core/api/internal/types/types.go
index e80c12a..50886df 100644
--- a/app/core/api/internal/types/types.go
+++ b/app/core/api/internal/types/types.go
@@ -11,6 +11,32 @@ type AccountLoginRequest struct {
Key string `json:"key"`
}
+type CommentDisLikeRequest struct {
+ TopicId string `json:"topic_id"`
+ CommentId int64 `json:"comment_id"`
+}
+
+type CommentLikeRequest struct {
+ TopicId string `json:"topic_id"`
+ CommentId int64 `json:"comment_id"`
+}
+
+type CommentListRequest struct {
+ TopicId string `json:"topic_id"`
+ Page int `json:"page,default=1,optional"`
+ Size int `json:"size,default=5,optional"`
+ IsHot bool `json:"is_hot,default=true,optional"`
+}
+
+type CommentRequest struct {
+ Content string `json:"content"`
+ Images []string `json:"images,optional"`
+ TopicId string `json:"topic_id"`
+ Author string `json:"author"`
+ Key string `json:"key"`
+ Point []int64 `json:"point"`
+}
+
type LoginResponse struct {
AccessToken string `json:"access_token"`
UID string `json:"uid"`
@@ -38,6 +64,36 @@ type PhoneLoginRequest struct {
AutoLogin bool `json:"auto_login"`
}
+type ReplyCommentRequest struct {
+ Content string `json:"content"`
+ Images []string `json:"images,optional"`
+ TopicId string `json:"topic_id" `
+ ReplyId int64 `json:"reply_id" `
+ ReplyUser string `json:"reply_user" `
+ Author string `json:"author"`
+ Key string `json:"key"`
+ Point []int64 `json:"point"`
+}
+
+type ReplyListRequest struct {
+ TopicId string `json:"topic_id"`
+ CommentId int64 `json:"comment_id"`
+ Page int `json:"page,default=1,optional"`
+ Size int `json:"size,default=5,optional"`
+}
+
+type ReplyReplyRequest struct {
+ Content string `json:"content"`
+ Images []string `json:"images,optional"`
+ TopicId string `json:"topic_id"`
+ ReplyTo int64 `json:"reply_to"`
+ ReplyId int64 `json:"reply_id"`
+ ReplyUser string `json:"reply_user" `
+ Author string `json:"author"`
+ Key string `json:"key"`
+ Point []int64 `json:"point"`
+}
+
type ResetPasswordRequest struct {
Phone string `json:"phone"`
Captcha string `json:"captcha"`
diff --git a/app/core/api/repository/redis_session/init.go b/app/core/api/repository/redis_session/init.go
index ba973ad..9af1728 100644
--- a/app/core/api/repository/redis_session/init.go
+++ b/app/core/api/repository/redis_session/init.go
@@ -8,7 +8,6 @@ import (
"github.com/gorilla/sessions"
"github.com/rbcervilla/redisstore/v9"
"github.com/redis/go-redis/v9"
- "github.com/zeromicro/go-zero/core/logc"
"schisandra-album-cloud-microservices/app/core/api/common/constant"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -22,12 +21,11 @@ func NewRedisSession(addr string, password string) *redisstore.RedisStore {
})
store, err := redisstore.NewRedisStore(context.Background(), client)
if err != nil {
- logc.Error(context.Background(), err)
+ panic(err)
}
store.KeyPrefix(constant.UserSessionPrefix)
store.Options(sessions.Options{
- Path: "/",
- // Domain: global.CONFIG.System.Web,
+ Path: "/",
MaxAge: 86400 * 7,
HttpOnly: true,
Secure: true,