🐛 fix session bug
This commit is contained in:
688
.idea/GOHCache.xml
generated
688
.idea/GOHCache.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,6 @@ package generate
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
@@ -21,7 +20,7 @@ func GenerateRotateCaptcha(captcha rotate.Captcha, redis *redis.Client, ctx cont
|
|||||||
}
|
}
|
||||||
blockData := captchaData.GetData()
|
blockData := captchaData.GetData()
|
||||||
if blockData == nil {
|
if blockData == nil {
|
||||||
return nil, errors.New("captcha data is nil")
|
return nil, nil
|
||||||
}
|
}
|
||||||
masterImageBase64 := captchaData.GetMasterImage().ToBase64()
|
masterImageBase64 := captchaData.GetMasterImage().ToBase64()
|
||||||
thumbImageBase64 := captchaData.GetThumbImage().ToBase64()
|
thumbImageBase64 := captchaData.GetThumbImage().ToBase64()
|
||||||
|
@@ -3,7 +3,6 @@ package generate
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
@@ -21,7 +20,7 @@ func GenerateSlideBasicCaptcha(slide slide.Captcha, redis *redis.Client, ctx con
|
|||||||
}
|
}
|
||||||
blockData := captData.GetData()
|
blockData := captData.GetData()
|
||||||
if blockData == nil {
|
if blockData == nil {
|
||||||
return nil, errors.New("block data is nil")
|
return nil, nil
|
||||||
}
|
}
|
||||||
var masterImageBase64, tileImageBase64 string
|
var masterImageBase64, tileImageBase64 string
|
||||||
masterImageBase64 = captData.GetMasterImage().ToBase64()
|
masterImageBase64 = captData.GetMasterImage().ToBase64()
|
||||||
|
@@ -10,7 +10,10 @@ func NewBundle(tag language.Tag, configs ...string) *i18n2.Bundle {
|
|||||||
bundle := i18n2.NewBundle(tag)
|
bundle := i18n2.NewBundle(tag)
|
||||||
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
||||||
for _, file := range configs {
|
for _, file := range configs {
|
||||||
bundle.LoadMessageFile(file)
|
_, err := bundle.LoadMessageFile(file)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return bundle
|
return bundle
|
||||||
}
|
}
|
||||||
|
@@ -9,13 +9,6 @@ import (
|
|||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
|
||||||
type Cache interface {
|
|
||||||
GetLocalizer() (*i18n2.Localizer, bool)
|
|
||||||
SetLocalizer(l *i18n2.Localizer)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func getLocalizer(ctx context.Context) (*i18n2.Localizer, bool) {
|
func getLocalizer(ctx context.Context) (*i18n2.Localizer, bool) {
|
||||||
v := ctx.Value(I18nKey)
|
v := ctx.Value(I18nKey)
|
||||||
if l, b := v.(*i18n2.Localizer); b {
|
if l, b := v.(*i18n2.Localizer); b {
|
||||||
@@ -49,14 +42,3 @@ func IsHasI18n(ctx context.Context) bool {
|
|||||||
}
|
}
|
||||||
return false
|
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)
|
|
||||||
// }
|
|
||||||
|
@@ -7,37 +7,24 @@ import (
|
|||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FormatText(ctx context.Context, msgId string, defaultText string) string {
|
func FormatText(ctx context.Context, msgId string) string {
|
||||||
return FormatTextWithData(ctx, msgId, defaultText, nil)
|
return FormatTextWithData(ctx, msgId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatTextWithData(ctx context.Context, msgId string, defaultText string, args map[string]interface{}) string {
|
func FormatTextWithData(ctx context.Context, msgId string) string {
|
||||||
return FormatMessage(ctx, &i18n2.Message{
|
hasI18n := IsHasI18n(ctx)
|
||||||
ID: msgId,
|
if !hasI18n {
|
||||||
Other: defaultText,
|
return ""
|
||||||
}, 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,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return formatInternalMessage(message, args)
|
localizer, ok := getLocalizer(ctx)
|
||||||
}
|
if !ok {
|
||||||
|
return ""
|
||||||
func formatInternalMessage(message *i18n2.Message, args map[string]interface{}) string {
|
|
||||||
if args == nil {
|
|
||||||
return message.Other
|
|
||||||
}
|
}
|
||||||
tpl := i18n2.NewMessageTemplate(message)
|
localizeConfig := &i18n2.LocalizeConfig{
|
||||||
msg, err := tpl.Execute("other", args, nil)
|
MessageID: msgId,
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
return msg
|
localize := localizer.MustLocalize(localizeConfig)
|
||||||
|
return localize
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchCurrentLanguageFromCtx(ctx context.Context) (*language.Tag, bool) {
|
func FetchCurrentLanguageFromCtx(ctx context.Context) (*language.Tag, bool) {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package i18n
|
package i18n
|
||||||
|
|
||||||
const I18nKey = "i18n"
|
const I18nKey = "i18n"
|
||||||
const I18nCurrentLangKey = "lang"
|
const I18nCurrentLangKey = "language"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultLangHeaderKey = "Accept-Language"
|
defaultLangHeaderKey = "Accept-Language"
|
||||||
|
@@ -5,10 +5,13 @@ import "golang.org/x/text/language"
|
|||||||
func MatchCurrentLanguageTag(accept string, supportTags []language.Tag) language.Tag {
|
func MatchCurrentLanguageTag(accept string, supportTags []language.Tag) language.Tag {
|
||||||
langTags, _, err := language.ParseAcceptLanguage(accept)
|
langTags, _, err := language.ParseAcceptLanguage(accept)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
langTags = []language.Tag{language.English}
|
langTags = []language.Tag{language.Chinese}
|
||||||
}
|
}
|
||||||
var matcher = language.NewMatcher(supportTags)
|
var matcher = language.NewMatcher(supportTags)
|
||||||
_, i, _ := matcher.Match(langTags...)
|
_, i, _ := matcher.Match(langTags...)
|
||||||
tag := supportTags[i]
|
tag := supportTags[i]
|
||||||
|
if tag == language.Und {
|
||||||
|
tag = language.Chinese
|
||||||
|
}
|
||||||
return tag
|
return tag
|
||||||
}
|
}
|
||||||
|
@@ -5,8 +5,8 @@ import "net/http"
|
|||||||
func CORSMiddleware() func(http.Header) {
|
func CORSMiddleware() func(http.Header) {
|
||||||
return func(header http.Header) {
|
return func(header http.Header) {
|
||||||
header.Set("Access-Control-Allow-Origin", "*")
|
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-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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ package middleware
|
|||||||
|
|
||||||
import "net/http"
|
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("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("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")
|
r.Header.Set("X-XSS-Protection", "1; mode=block")
|
||||||
|
@@ -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"))
|
||||||
|
}
|
||||||
|
}
|
@@ -71,8 +71,8 @@ func ErrorWithMessage(message string) *types.Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ErrorWithI18n returns an error response with the given message.
|
// ErrorWithI18n returns an error response with the given message.
|
||||||
func ErrorWithI18n(ctx context.Context, msgId string, defaultMsg string) *types.Response {
|
func ErrorWithI18n(ctx context.Context, msgId string) *types.Response {
|
||||||
message := i18n.FormatText(ctx, msgId, defaultMsg)
|
message := i18n.FormatText(ctx, msgId)
|
||||||
return &types.Response{
|
return &types.Response{
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Message: message,
|
Message: message,
|
||||||
|
@@ -57,6 +57,7 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 短信发送请求参数
|
||||||
type (
|
type (
|
||||||
SmsSendRequest {
|
SmsSendRequest {
|
||||||
Phone string `json:"phone"`
|
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 (
|
type (
|
||||||
Response {
|
Response {
|
||||||
@@ -124,8 +184,6 @@ service core {
|
|||||||
@server (
|
@server (
|
||||||
group: websocket // 微服务分组
|
group: websocket // 微服务分组
|
||||||
prefix: /api/ws // 微服务前缀
|
prefix: /api/ws // 微服务前缀
|
||||||
timeout: 10s // 超时时间
|
|
||||||
Recover: true // 是否开启自动恢复
|
|
||||||
)
|
)
|
||||||
service core {
|
service core {
|
||||||
@handler qrcodeWebsocket
|
@handler qrcodeWebsocket
|
||||||
@@ -210,3 +268,37 @@ service core {
|
|||||||
get /slide/generate returns (Response)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ func main() {
|
|||||||
var c config.Config
|
var c config.Config
|
||||||
conf.MustLoad(*configFile, &c)
|
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()
|
defer server.Stop()
|
||||||
// i18n middleware
|
// i18n middleware
|
||||||
server.Use(middleware.I18nMiddleware)
|
server.Use(middleware.I18nMiddleware)
|
||||||
|
@@ -6,10 +6,9 @@ Web:
|
|||||||
Middlewares:
|
Middlewares:
|
||||||
Log: true
|
Log: true
|
||||||
Mysql:
|
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:
|
Auth:
|
||||||
AccessSecret: uOvKLmVfztaXGpNYd4Z0I1SiT7MweJhl
|
AccessSecret: uOvKLmVfztaXGpNYd4Z0I1SiT7MweJhl
|
||||||
AccessExpire: 86400
|
|
||||||
Redis:
|
Redis:
|
||||||
Host: 1.95.0.111:6379
|
Host: 1.95.0.111:6379
|
||||||
Pass: LDQ20020618xxx
|
Pass: LDQ20020618xxx
|
||||||
|
@@ -9,7 +9,6 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
Auth struct {
|
Auth struct {
|
||||||
AccessSecret string
|
AccessSecret string
|
||||||
AccessExpire int64
|
|
||||||
}
|
}
|
||||||
Mysql struct {
|
Mysql struct {
|
||||||
DataSource string
|
DataSource string
|
||||||
|
@@ -3,7 +3,9 @@ package captcha
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/captcha"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"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)
|
l := captcha.NewGenerateRotateCaptchaLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GenerateRotateCaptcha()
|
resp, err := l.GenerateRotateCaptcha()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,9 @@ package captcha
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/captcha"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"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)
|
l := captcha.NewGenerateSlideBasicCaptchaLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GenerateSlideBasicCaptcha()
|
resp, err := l.GenerateSlideBasicCaptcha()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
"schisandra-album-cloud-microservices/app/core/api/common/utils"
|
"schisandra-album-cloud-microservices/app/core/api/common/utils"
|
||||||
@@ -15,8 +16,9 @@ func GenerateClientIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
clientIP := utils.GetClientIP(r)
|
clientIP := utils.GetClientIP(r)
|
||||||
l := client.NewGenerateClientIdLogic(r.Context(), svcCtx)
|
l := client.NewGenerateClientIdLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GenerateClientId(clientIP)
|
resp, err := l.GenerateClientId(clientIP)
|
||||||
if err != nil || resp.Code == 500 {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -3,7 +3,9 @@ package oauth
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/oauth"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"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)
|
l := oauth.NewGetGiteeOauthUrlLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetGiteeOauthUrl()
|
resp, err := l.GetGiteeOauthUrl()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,9 @@ package oauth
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/oauth"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
"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)
|
l := oauth.NewGetGithubOauthUrlLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetGithubOauthUrl(&req)
|
resp, err := l.GetGithubOauthUrl(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,9 @@ package oauth
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/oauth"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
"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)
|
l := oauth.NewGetQqOauthUrlLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetQqOauthUrl(&req)
|
resp, err := l.GetQqOauthUrl(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package oauth
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/oauth"
|
||||||
@@ -21,7 +22,8 @@ func GetWechatQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := oauth.NewGetWechatQrcodeLogic(r.Context(), svcCtx)
|
l := oauth.NewGetWechatQrcodeLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetWechatQrcode(r, &req)
|
resp, err := l.GetWechatQrcode(r, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
package oauth
|
package oauth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/oauth"
|
||||||
@@ -21,7 +23,8 @@ func GiteeCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := oauth.NewGiteeCallbackLogic(r.Context(), svcCtx)
|
l := oauth.NewGiteeCallbackLogic(r.Context(), svcCtx)
|
||||||
err := l.GiteeCallback(w, r, &req)
|
err := l.GiteeCallback(w, r, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||||
} else {
|
} else {
|
||||||
httpx.Ok(w)
|
httpx.Ok(w)
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
package oauth
|
package oauth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/oauth"
|
||||||
@@ -21,7 +23,8 @@ func GithubCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := oauth.NewGithubCallbackLogic(r.Context(), svcCtx)
|
l := oauth.NewGithubCallbackLogic(r.Context(), svcCtx)
|
||||||
err := l.GithubCallback(w, r, &req)
|
err := l.GithubCallback(w, r, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||||
} else {
|
} else {
|
||||||
httpx.Ok(w)
|
httpx.Ok(w)
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
package oauth
|
package oauth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/oauth"
|
||||||
@@ -21,7 +23,8 @@ func QqCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := oauth.NewQqCallbackLogic(r.Context(), svcCtx)
|
l := oauth.NewQqCallbackLogic(r.Context(), svcCtx)
|
||||||
err := l.QqCallback(w, r, &req)
|
err := l.QqCallback(w, r, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||||
} else {
|
} else {
|
||||||
httpx.Ok(w)
|
httpx.Ok(w)
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
package oauth
|
package oauth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/oauth"
|
||||||
@@ -14,7 +16,8 @@ func WechatCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := oauth.NewWechatCallbackLogic(r.Context(), svcCtx)
|
l := oauth.NewWechatCallbackLogic(r.Context(), svcCtx)
|
||||||
err := l.WechatCallback(w, r)
|
err := l.WechatCallback(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||||
} else {
|
} else {
|
||||||
httpx.Ok(w)
|
httpx.Ok(w)
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
captcha "schisandra-album-cloud-microservices/app/core/api/internal/handler/captcha"
|
captcha "schisandra-album-cloud-microservices/app/core/api/internal/handler/captcha"
|
||||||
client "schisandra-album-cloud-microservices/app/core/api/internal/handler/client"
|
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"
|
oauth "schisandra-album-cloud-microservices/app/core/api/internal/handler/oauth"
|
||||||
sms "schisandra-album-cloud-microservices/app/core/api/internal/handler/sms"
|
sms "schisandra-album-cloud-microservices/app/core/api/internal/handler/sms"
|
||||||
user "schisandra-album-cloud-microservices/app/core/api/internal/handler/user"
|
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),
|
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(
|
server.AddRoutes(
|
||||||
rest.WithMiddlewares(
|
rest.WithMiddlewares(
|
||||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware},
|
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware},
|
||||||
@@ -184,6 +233,5 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
rest.WithPrefix("/api/ws"),
|
rest.WithPrefix("/api/ws"),
|
||||||
rest.WithTimeout(10000*time.Millisecond),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,9 @@ package sms
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/sms"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
"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)
|
l := sms.NewSendSmsByAliyunLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.SendSmsByAliyun(&req)
|
resp, err := l.SendSmsByAliyun(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,9 @@ package sms
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/sms"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
"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)
|
l := sms.NewSendSmsBySmsbaoLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.SendSmsBySmsbao(&req)
|
resp, err := l.SendSmsBySmsbao(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,9 @@ package sms
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/sms"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
"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)
|
l := sms.NewSendSmsByTestLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.SendSmsByTest(&req)
|
resp, err := l.SendSmsByTest(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
"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)
|
l := user.NewAccountLoginLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.AccountLogin(w, r, &req)
|
resp, err := l.AccountLogin(w, r, &req)
|
||||||
if err != nil || resp.Code == 500 {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
"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)
|
l := user.NewGetUserDeviceLogic(r.Context(), svcCtx)
|
||||||
err := l.GetUserDevice(r)
|
err := l.GetUserDevice(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||||
} else {
|
} else {
|
||||||
httpx.Ok(w)
|
httpx.Ok(w)
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
"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)
|
l := user.NewPhoneLoginLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.PhoneLogin(r, w, &req)
|
resp, err := l.PhoneLogin(r, w, &req)
|
||||||
if err != nil || resp.Code == 500 {
|
if err != nil || resp.Code == 500 {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
"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)
|
l := user.NewRefreshTokenLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.RefreshToken(r)
|
resp, err := l.RefreshToken(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
"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)
|
l := user.NewResetPasswordLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.ResetPassword(&req)
|
resp, err := l.ResetPassword(&req)
|
||||||
if err != nil || resp.Code == 500 {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
logx.Error(err)
|
||||||
|
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,6 @@ package websocket
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"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/logic/websocket"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||||
)
|
)
|
||||||
@@ -12,11 +10,6 @@ import (
|
|||||||
func MessageWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func MessageWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := websocket.NewMessageWebsocketLogic(r.Context(), svcCtx)
|
l := websocket.NewMessageWebsocketLogic(r.Context(), svcCtx)
|
||||||
err := l.MessageWebsocket(w, r)
|
l.MessageWebsocket(w, r)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,6 @@ package websocket
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"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/logic/websocket"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||||
)
|
)
|
||||||
@@ -12,11 +10,6 @@ import (
|
|||||||
func QrcodeWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QrcodeWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := websocket.NewQrcodeWebsocketLogic(r.Context(), svcCtx)
|
l := websocket.NewQrcodeWebsocketLogic(r.Context(), svcCtx)
|
||||||
err := l.QrcodeWebsocket(w, r)
|
l.QrcodeWebsocket(w, r)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,6 @@ func (l *GenerateClientIdLogic) GenerateClientId(clientIP string) (resp *types.R
|
|||||||
}
|
}
|
||||||
simpleUuid := kgo.SimpleUuid()
|
simpleUuid := kgo.SimpleUuid()
|
||||||
if err = l.svcCtx.RedisClient.SetEx(l.ctx, constant.UserClientPrefix+clientIP, simpleUuid, time.Hour*24*7).Err(); err != nil {
|
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.Error(), err
|
||||||
}
|
}
|
||||||
return response.SuccessWithData(simpleUuid), nil
|
return response.SuccessWithData(simpleUuid), nil
|
||||||
|
30
app/core/api/internal/logic/comment/dislike_comment_logic.go
Normal file
30
app/core/api/internal/logic/comment/dislike_comment_logic.go
Normal file
@@ -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
|
||||||
|
}
|
@@ -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
|
||||||
|
}
|
30
app/core/api/internal/logic/comment/get_reply_list_logic.go
Normal file
30
app/core/api/internal/logic/comment/get_reply_list_logic.go
Normal file
@@ -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
|
||||||
|
}
|
30
app/core/api/internal/logic/comment/like_comment_logic.go
Normal file
30
app/core/api/internal/logic/comment/like_comment_logic.go
Normal file
@@ -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
|
||||||
|
}
|
30
app/core/api/internal/logic/comment/submit_comment_logic.go
Normal file
30
app/core/api/internal/logic/comment/submit_comment_logic.go
Normal file
@@ -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
|
||||||
|
}
|
@@ -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
|
||||||
|
}
|
@@ -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
|
||||||
|
}
|
@@ -3,7 +3,6 @@ package oauth
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -79,7 +78,7 @@ func (l *GithubCallbackLogic) GithubCallback(w http.ResponseWriter, r *http.Requ
|
|||||||
}
|
}
|
||||||
if token == nil {
|
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 {
|
if userInfo == nil {
|
||||||
return errors.New("failed to get user info")
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理用户信息
|
// 处理用户信息
|
||||||
|
@@ -3,7 +3,6 @@ package oauth
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -75,7 +74,7 @@ func (l *QqCallbackLogic) QqCallback(w http.ResponseWriter, r *http.Request, req
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if token == nil {
|
if token == nil {
|
||||||
return errors.New("get qq token failed")
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通过 token 获取 openid
|
// 通过 token 获取 openid
|
||||||
|
@@ -61,9 +61,9 @@ func (l *WechatCallbackLogic) WechatCallback(w http.ResponseWriter, r *http.Requ
|
|||||||
key := strings.TrimPrefix(msg.EventKey, "qrscene_")
|
key := strings.TrimPrefix(msg.EventKey, "qrscene_")
|
||||||
err = l.HandlerWechatLogin(msg.FromUserName, key, w, r)
|
err = l.HandlerWechatLogin(msg.FromUserName, key, w, r)
|
||||||
if err != nil {
|
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:
|
case models.CALLBACK_EVENT_UNSUBSCRIBE:
|
||||||
msg := models.EventUnSubscribe{}
|
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)
|
err = l.HandlerWechatLogin(msg.FromUserName, msg.EventKey, w, r)
|
||||||
if err != nil {
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
err = helper.HttpResponseSend(rs, w)
|
err = helper.HttpResponseSend(rs, w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -36,15 +36,15 @@ func (l *SendSmsByAliyunLogic) SendSmsByAliyun(req *types.SmsSendRequest) (resp
|
|||||||
|
|
||||||
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
||||||
if !checkRotateData {
|
if !checkRotateData {
|
||||||
return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure", "验证码错误"), nil
|
return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure"), nil
|
||||||
}
|
}
|
||||||
isPhone := utils.IsPhone(req.Phone)
|
isPhone := utils.IsPhone(req.Phone)
|
||||||
if !isPhone {
|
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()
|
val := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
|
||||||
if val != "" {
|
if val != "" {
|
||||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently", "验证码发送过于频繁,请稍后再试"), nil
|
return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently"), nil
|
||||||
}
|
}
|
||||||
sms := gosms.NewParser(gateways.Gateways{
|
sms := gosms.NewParser(gateways.Gateways{
|
||||||
ALiYun: aliyun.ALiYun{
|
ALiYun: aliyun.ALiYun{
|
||||||
@@ -56,7 +56,7 @@ func (l *SendSmsByAliyunLogic) SendSmsByAliyun(req *types.SmsSendRequest) (resp
|
|||||||
code := utils.GenValidateCode(6)
|
code := utils.GenValidateCode(6)
|
||||||
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
||||||
if wrong != nil {
|
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{
|
_, err = sms.Send(req.Phone, gosms.MapStringAny{
|
||||||
"content": "您的验证码是:****。请不要把验证码泄露给其他人。",
|
"content": "您的验证码是:****。请不要把验证码泄露给其他人。",
|
||||||
@@ -67,7 +67,7 @@ func (l *SendSmsByAliyunLogic) SendSmsByAliyun(req *types.SmsSendRequest) (resp
|
|||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed", "验证码发送失败"), err
|
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), err
|
||||||
}
|
}
|
||||||
return response.Success(), nil
|
return response.Success(), nil
|
||||||
}
|
}
|
||||||
|
@@ -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) {
|
func (l *SendSmsBySmsbaoLogic) SendSmsBySmsbao(req *types.SmsSendRequest) (resp *types.Response, err error) {
|
||||||
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
||||||
if !checkRotateData {
|
if !checkRotateData {
|
||||||
return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure", "验证码错误"), nil
|
return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure"), nil
|
||||||
}
|
}
|
||||||
isPhone := utils.IsPhone(req.Phone)
|
isPhone := utils.IsPhone(req.Phone)
|
||||||
if !isPhone {
|
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()
|
val := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
|
||||||
if val != "" {
|
if val != "" {
|
||||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently", "验证码发送过于频繁,请稍后再试"), nil
|
return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently"), nil
|
||||||
}
|
}
|
||||||
sms := gosms.NewParser(gateways.Gateways{
|
sms := gosms.NewParser(gateways.Gateways{
|
||||||
SmsBao: smsbao.SmsBao{
|
SmsBao: smsbao.SmsBao{
|
||||||
@@ -54,13 +54,13 @@ func (l *SendSmsBySmsbaoLogic) SendSmsBySmsbao(req *types.SmsSendRequest) (resp
|
|||||||
code := utils.GenValidateCode(6)
|
code := utils.GenValidateCode(6)
|
||||||
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
||||||
if wrong != nil {
|
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{
|
_, err = sms.Send(req.Phone, gosms.MapStringAny{
|
||||||
"content": "您的验证码是:" + code + "。请不要把验证码泄露给其他人。",
|
"content": "您的验证码是:" + code + "。请不要把验证码泄露给其他人。",
|
||||||
}, nil)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed", "验证码发送失败"), err
|
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), err
|
||||||
}
|
}
|
||||||
return response.Success(), nil
|
return response.Success(), nil
|
||||||
}
|
}
|
||||||
|
@@ -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) {
|
func (l *SendSmsByTestLogic) SendSmsByTest(req *types.SmsSendRequest) (resp *types.Response, err error) {
|
||||||
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
||||||
if !checkRotateData {
|
if !checkRotateData {
|
||||||
return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure", "验证码错误"), nil
|
return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure"), nil
|
||||||
}
|
}
|
||||||
isPhone := utils.IsPhone(req.Phone)
|
isPhone := utils.IsPhone(req.Phone)
|
||||||
if !isPhone {
|
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()
|
val := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
|
||||||
if val != "" {
|
if val != "" {
|
||||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently", "验证码发送过于频繁,请稍后再试"), nil
|
return response.ErrorWithI18n(l.ctx, "sms.smsSendTooFrequently"), nil
|
||||||
}
|
}
|
||||||
code := utils.GenValidateCode(6)
|
code := utils.GenValidateCode(6)
|
||||||
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
||||||
if wrong != nil {
|
if wrong != nil {
|
||||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed", "验证码发送失败"), wrong
|
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), wrong
|
||||||
}
|
}
|
||||||
return response.Success(), nil
|
return response.Success(), nil
|
||||||
}
|
}
|
||||||
|
@@ -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) {
|
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)
|
verifyResult := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
||||||
if !verifyResult {
|
if !verifyResult {
|
||||||
return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure", "验证失败!"), nil
|
return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure"), nil
|
||||||
}
|
}
|
||||||
var user *ent.ScaAuthUser
|
var user *ent.ScaAuthUser
|
||||||
var query *ent.ScaAuthUserQuery
|
var query *ent.ScaAuthUserQuery
|
||||||
@@ -49,23 +49,27 @@ func (l *AccountLoginLogic) AccountLogin(w http.ResponseWriter, r *http.Request,
|
|||||||
case utils.IsUsername(req.Account):
|
case utils.IsUsername(req.Account):
|
||||||
query = l.svcCtx.MySQLClient.ScaAuthUser.Query().Where(scaauthuser.UsernameEQ(req.Account), scaauthuser.DeletedEQ(0))
|
query = l.svcCtx.MySQLClient.ScaAuthUser.Query().Where(scaauthuser.UsernameEQ(req.Account), scaauthuser.DeletedEQ(0))
|
||||||
default:
|
default:
|
||||||
return response.ErrorWithI18n(l.ctx, "login.invalidAccount", "无效账号!"), nil
|
return response.ErrorWithI18n(l.ctx, "login.invalidAccount"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err = query.First(l.ctx)
|
user, err = query.First(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ent.IsNotFound(err) {
|
if ent.IsNotFound(err) {
|
||||||
return response.ErrorWithI18n(l.ctx, "login.userNotRegistered", "用户未注册!"), nil
|
return response.ErrorWithI18n(l.ctx, "login.userNotRegistered"), nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !utils.Verify(user.Password, req.Password) {
|
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)
|
data, result := HandleUserLogin(user, l.svcCtx, req.AutoLogin, r, w, l.ctx)
|
||||||
if !result {
|
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
|
return response.SuccessWithData(data), nil
|
||||||
}
|
}
|
||||||
@@ -96,6 +100,7 @@ func HandleUserLogin(user *ent.ScaAuthUser, svcCtx *svc.ServiceContext, autoLogi
|
|||||||
|
|
||||||
redisToken := types.RedisToken{
|
redisToken := types.RedisToken{
|
||||||
AccessToken: accessToken,
|
AccessToken: accessToken,
|
||||||
|
RefreshToken: refreshToken,
|
||||||
UID: user.UID,
|
UID: user.UID,
|
||||||
}
|
}
|
||||||
err := svcCtx.RedisClient.Set(ctx, constant.UserTokenPrefix+user.UID, redisToken, days).Err()
|
err := svcCtx.RedisClient.Set(ctx, constant.UserTokenPrefix+user.UID, redisToken, days).Err()
|
||||||
@@ -103,24 +108,17 @@ func HandleUserLogin(user *ent.ScaAuthUser, svcCtx *svc.ServiceContext, autoLogi
|
|||||||
logc.Error(ctx, err)
|
logc.Error(ctx, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
sessionData := types.SessionData{
|
|
||||||
RefreshToken: refreshToken,
|
|
||||||
UID: user.UID,
|
|
||||||
}
|
|
||||||
session, err := svcCtx.Session.Get(r, constant.SESSION_KEY)
|
session, err := svcCtx.Session.Get(r, constant.SESSION_KEY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logc.Error(ctx, err)
|
logc.Error(ctx, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
session.Values[constant.SESSION_KEY] = sessionData
|
session.Values["refresh_token"] = refreshToken
|
||||||
|
session.Values["uid"] = user.UID
|
||||||
err = session.Save(r, w)
|
err = session.Save(r, w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
// 记录用户登录设备
|
|
||||||
if !GetUserLoginDevice(user.UID, r, svcCtx.Ip2Region, svcCtx.MySQLClient, ctx) {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
return &data, true
|
return &data, true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,7 @@ func (l *GetUserDeviceLogic) GetUserDevice(r *http.Request) error {
|
|||||||
}
|
}
|
||||||
sessionData, ok := session.Values[constant.SESSION_KEY]
|
sessionData, ok := session.Values[constant.SESSION_KEY]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("User not found or device not found")
|
return errors.New("user session not found")
|
||||||
}
|
}
|
||||||
var data types.SessionData
|
var data types.SessionData
|
||||||
err = json.Unmarshal(sessionData.([]byte), &data)
|
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)
|
res := GetUserLoginDevice(data.UID, r, l.svcCtx.Ip2Region, l.svcCtx.MySQLClient, l.ctx)
|
||||||
if !res {
|
if !res {
|
||||||
return errors.New("User not found or device not found")
|
return errors.New("user device not found")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -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) {
|
func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, w http.ResponseWriter, req *types.PhoneLoginRequest) (resp *types.Response, err error) {
|
||||||
if !utils.IsPhone(req.Phone) {
|
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()
|
code := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
|
||||||
if code == "" {
|
if code == "" {
|
||||||
return response.ErrorWithI18n(l.ctx, "login.captchaExpired", "验证码已过期"), nil
|
return response.ErrorWithI18n(l.ctx, "login.captchaExpired"), nil
|
||||||
}
|
}
|
||||||
if req.Captcha != code {
|
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)
|
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)
|
tx, wrong := l.svcCtx.MySQLClient.Tx(l.ctx)
|
||||||
if wrong != nil {
|
if wrong != nil {
|
||||||
return response.ErrorWithI18n(l.ctx, "login.loginFailed", "登录失败"), err
|
return response.ErrorWithI18n(l.ctx, "login.loginFailed"), err
|
||||||
}
|
}
|
||||||
if ent.IsNotFound(err) {
|
if ent.IsNotFound(err) {
|
||||||
uid := idgen.NextId()
|
uid := idgen.NextId()
|
||||||
@@ -64,17 +64,21 @@ func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, w http.ResponseWriter, req
|
|||||||
Save(l.ctx)
|
Save(l.ctx)
|
||||||
if fault != nil {
|
if fault != nil {
|
||||||
err = tx.Rollback()
|
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)
|
_, err = l.svcCtx.CasbinEnforcer.AddRoleForUser(uidStr, constant.User)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = tx.Rollback()
|
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)
|
data, result := HandleUserLogin(addUser, l.svcCtx, req.AutoLogin, r, w, l.ctx)
|
||||||
if !result {
|
if !result {
|
||||||
err = tx.Rollback()
|
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()
|
err = tx.Commit()
|
||||||
if err != nil {
|
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)
|
data, result := HandleUserLogin(user, l.svcCtx, req.AutoLogin, r, w, l.ctx)
|
||||||
if !result {
|
if !result {
|
||||||
err = tx.Rollback()
|
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()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -93,6 +101,6 @@ func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, w http.ResponseWriter, req
|
|||||||
}
|
}
|
||||||
return response.SuccessWithData(data), nil
|
return response.SuccessWithData(data), nil
|
||||||
} else {
|
} else {
|
||||||
return response.ErrorWithI18n(l.ctx, "login.loginFailed", "登录失败"), nil
|
return response.ErrorWithI18n(l.ctx, "login.loginFailed"), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,27 +34,40 @@ func (l *RefreshTokenLogic) RefreshToken(r *http.Request) (resp *types.Response,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return response.ErrorWithCode(403), err
|
return response.ErrorWithCode(403), err
|
||||||
}
|
}
|
||||||
sessionData, ok := session.Values[constant.SESSION_KEY]
|
refreshSessionToken, ok := session.Values["refresh_token"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return response.ErrorWithCode(403), err
|
return response.ErrorWithCode(403), nil
|
||||||
}
|
}
|
||||||
data := types.SessionData{}
|
userId, ok := session.Values["uid"].(string)
|
||||||
err = json.Unmarshal(sessionData.([]byte), &data)
|
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 {
|
if err != nil {
|
||||||
return response.ErrorWithCode(403), err
|
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 {
|
if !result {
|
||||||
return response.ErrorWithCode(403), err
|
return response.ErrorWithCode(403), nil
|
||||||
}
|
}
|
||||||
accessToken := jwt.GenerateAccessToken(l.svcCtx.Config.Auth.AccessSecret, jwt.AccessJWTPayload{
|
accessToken := jwt.GenerateAccessToken(l.svcCtx.Config.Auth.AccessSecret, jwt.AccessJWTPayload{
|
||||||
UserID: refreshToken.UserID,
|
UserID: refreshToken.UserID,
|
||||||
})
|
})
|
||||||
if accessToken == "" {
|
if accessToken == "" {
|
||||||
return response.ErrorWithCode(403), err
|
return response.ErrorWithCode(403), nil
|
||||||
}
|
}
|
||||||
redisToken := types.RedisToken{
|
redisToken := types.RedisToken{
|
||||||
AccessToken: accessToken,
|
AccessToken: accessToken,
|
||||||
|
RefreshToken: refreshSessionToken,
|
||||||
UID: refreshToken.UserID,
|
UID: refreshToken.UserID,
|
||||||
}
|
}
|
||||||
err = l.svcCtx.RedisClient.Set(l.ctx, constant.UserTokenPrefix+refreshToken.UserID, redisToken, time.Hour*24*7).Err()
|
err = l.svcCtx.RedisClient.Set(l.ctx, constant.UserTokenPrefix+refreshToken.UserID, redisToken, time.Hour*24*7).Err()
|
||||||
|
@@ -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) {
|
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (resp *types.Response, err error) {
|
||||||
if !utils.IsPhone(req.Phone) {
|
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 {
|
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) {
|
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()
|
code := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
|
||||||
if code == "" {
|
if code == "" {
|
||||||
return response.ErrorWithI18n(l.ctx, "login.captchaExpired", "验证码已过期"), nil
|
return response.ErrorWithI18n(l.ctx, "login.captchaExpired"), nil
|
||||||
}
|
}
|
||||||
if req.Captcha != code {
|
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 {
|
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)
|
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) {
|
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)
|
encrypt, err := utils.Encrypt(req.Password)
|
||||||
if err != nil {
|
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)
|
err = user.Update().SetPassword(encrypt).Exec(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.ErrorWithI18n(l.ctx, "login.resetPasswordError", "重置密码失败"), err
|
return response.ErrorWithI18n(l.ctx, "login.resetPasswordError"), err
|
||||||
}
|
}
|
||||||
return response.Success(), nil
|
return response.Success(), nil
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,7 @@ var MessageWebSocketHandler *MessageWebSocket
|
|||||||
func InitializeWebSocketHandler(svcCtx *svc.ServiceContext) {
|
func InitializeWebSocketHandler(svcCtx *svc.ServiceContext) {
|
||||||
MessageWebSocketHandler = NewMessageWebSocket(svcCtx)
|
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{
|
upgrader := gws.NewUpgrader(MessageWebSocketHandler, &gws.ServerOption{
|
||||||
HandshakeTimeout: 5 * time.Second, // 握手超时时间
|
HandshakeTimeout: 5 * time.Second, // 握手超时时间
|
||||||
ReadBufferSize: 1024, // 读缓冲区大小
|
ReadBufferSize: 1024, // 读缓冲区大小
|
||||||
@@ -71,12 +71,11 @@ func (l *MessageWebsocketLogic) MessageWebsocket(w http.ResponseWriter, r *http.
|
|||||||
})
|
})
|
||||||
socket, err := upgrader.Upgrade(w, r)
|
socket, err := upgrader.Upgrade(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
panic(err)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
socket.ReadLoop() // 此处阻塞会使请求上下文不能顺利被GC
|
socket.ReadLoop() // 此处阻塞会使请求上下文不能顺利被GC
|
||||||
}()
|
}()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMessageWebSocket 创建WebSocket实例
|
// NewMessageWebSocket 创建WebSocket实例
|
||||||
|
@@ -40,7 +40,7 @@ type QrcodeWebSocket struct {
|
|||||||
|
|
||||||
var QrcodeWebSocketHandler = NewWebSocket()
|
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{
|
upgrader := gws.NewUpgrader(QrcodeWebSocketHandler, &gws.ServerOption{
|
||||||
HandshakeTimeout: 5 * time.Second, // 握手超时时间
|
HandshakeTimeout: 5 * time.Second, // 握手超时时间
|
||||||
ReadBufferSize: 1024, // 读缓冲区大小
|
ReadBufferSize: 1024, // 读缓冲区大小
|
||||||
@@ -66,12 +66,11 @@ func (l *QrcodeWebsocketLogic) QrcodeWebsocket(w http.ResponseWriter, r *http.Re
|
|||||||
})
|
})
|
||||||
socket, err := upgrader.Upgrade(w, r)
|
socket, err := upgrader.Upgrade(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
panic(err)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
socket.ReadLoop() // 此处阻塞会使请求上下文不能顺利被GC
|
socket.ReadLoop() // 此处阻塞会使请求上下文不能顺利被GC
|
||||||
}()
|
}()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustLoad 从session中加载数据
|
// MustLoad 从session中加载数据
|
||||||
|
29
app/core/api/internal/middleware/casbinverify_middleware.go
Normal file
29
app/core/api/internal/middleware/casbinverify_middleware.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
@@ -15,7 +15,7 @@ func NewSecurityHeadersMiddleware() *SecurityHeadersMiddleware {
|
|||||||
|
|
||||||
func (m *SecurityHeadersMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
func (m *SecurityHeadersMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
middleware.SecurityHeadersMiddleware(w, r)
|
middleware.SecurityHeadersMiddleware(r)
|
||||||
next(w, r)
|
next(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import (
|
|||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SecurityHeadersMiddleware rest.Middleware
|
SecurityHeadersMiddleware rest.Middleware
|
||||||
|
CasbinVerifyMiddleware rest.Middleware
|
||||||
MySQLClient *ent.Client
|
MySQLClient *ent.Client
|
||||||
RedisClient *redis.Client
|
RedisClient *redis.Client
|
||||||
MongoClient *mongo.Database
|
MongoClient *mongo.Database
|
||||||
@@ -43,15 +44,17 @@ type ServiceContext struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
casbinEnforcer := casbinx.NewCasbin(c.Mysql.DataSource)
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
SecurityHeadersMiddleware: middleware.NewSecurityHeadersMiddleware().Handle,
|
SecurityHeadersMiddleware: middleware.NewSecurityHeadersMiddleware().Handle,
|
||||||
|
CasbinVerifyMiddleware: middleware.NewCasbinVerifyMiddleware(casbinEnforcer).Handle,
|
||||||
MySQLClient: mysql.NewMySQL(c.Mysql.DataSource),
|
MySQLClient: mysql.NewMySQL(c.Mysql.DataSource),
|
||||||
RedisClient: redisx.NewRedis(c.Redis.Host, c.Redis.Pass, c.Redis.DB),
|
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),
|
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),
|
Session: redis_session.NewRedisSession(c.Redis.Host, c.Redis.Pass),
|
||||||
Ip2Region: ip2region.NewIP2Region(),
|
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),
|
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(),
|
Sensitive: sensitivex.NewSensitive(),
|
||||||
RotateCaptcha: captcha.NewRotateCaptcha(),
|
RotateCaptcha: captcha.NewRotateCaptcha(),
|
||||||
|
@@ -4,6 +4,7 @@ import "encoding/json"
|
|||||||
|
|
||||||
type RedisToken struct {
|
type RedisToken struct {
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
|
RefreshToken string `json:"refresh_token"`
|
||||||
UID string `json:"uid"`
|
UID string `json:"uid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,6 +11,32 @@ type AccountLoginRequest struct {
|
|||||||
Key string `json:"key"`
|
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 {
|
type LoginResponse struct {
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
UID string `json:"uid"`
|
UID string `json:"uid"`
|
||||||
@@ -38,6 +64,36 @@ type PhoneLoginRequest struct {
|
|||||||
AutoLogin bool `json:"auto_login"`
|
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 {
|
type ResetPasswordRequest struct {
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
Captcha string `json:"captcha"`
|
Captcha string `json:"captcha"`
|
||||||
|
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/rbcervilla/redisstore/v9"
|
"github.com/rbcervilla/redisstore/v9"
|
||||||
"github.com/redis/go-redis/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/common/constant"
|
||||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
"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)
|
store, err := redisstore.NewRedisStore(context.Background(), client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logc.Error(context.Background(), err)
|
panic(err)
|
||||||
}
|
}
|
||||||
store.KeyPrefix(constant.UserSessionPrefix)
|
store.KeyPrefix(constant.UserSessionPrefix)
|
||||||
store.Options(sessions.Options{
|
store.Options(sessions.Options{
|
||||||
Path: "/",
|
Path: "/",
|
||||||
// Domain: global.CONFIG.System.Web,
|
|
||||||
MaxAge: 86400 * 7,
|
MaxAge: 86400 * 7,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: true,
|
Secure: true,
|
||||||
|
Reference in New Issue
Block a user