🎨 updated error handling logic
This commit is contained in:
120
app/core/api/Dockerfile
Normal file
120
app/core/api/Dockerfile
Normal file
@@ -0,0 +1,120 @@
|
||||
# to build this docker image:
|
||||
# docker build -f Dockerfile -t schisandra-cloud-album-server .
|
||||
# docker build --build-arg OPENCV_VERSION="4.x" --build-arg OPENCV_FILE="https://github.com/opencv/opencv/archive/refs/heads/4.x.zip" --build-arg OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip" -f Dockerfile -t schisandra-cloud-album-server .
|
||||
|
||||
FROM ubuntu:20.04 AS opencv-builder
|
||||
|
||||
LABEL maintainer="landaiqing <<landaiqing@126.com>>"
|
||||
|
||||
RUN sed -i 's|http://archive.ubuntu.com/ubuntu/|http://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list
|
||||
|
||||
ENV TZ=Europe/Madrid
|
||||
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
|
||||
tzdata git build-essential cmake pkg-config wget unzip libgtk2.0-dev \
|
||||
curl ca-certificates libcurl4-openssl-dev libssl-dev \
|
||||
libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \
|
||||
libharfbuzz-dev libfreetype6-dev \
|
||||
libjpeg-turbo8-dev libpng-dev libtiff-dev libdc1394-22-dev nasm && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG OPENCV_VERSION="4.10.0"
|
||||
|
||||
ENV OPENCV_VERSION=$OPENCV_VERSION
|
||||
|
||||
ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip"
|
||||
|
||||
ENV OPENCV_FILE=$OPENCV_FILE
|
||||
|
||||
ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip"
|
||||
|
||||
ENV OPENCV_CONTRIB_FILE=$OPENCV_CONTRIB_FILE
|
||||
|
||||
RUN curl -Lo opencv.zip ${OPENCV_FILE} && \
|
||||
unzip -q opencv.zip && \
|
||||
curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \
|
||||
unzip -q opencv_contrib.zip && \
|
||||
rm opencv.zip opencv_contrib.zip && \
|
||||
cd opencv-${OPENCV_VERSION} && \
|
||||
mkdir build && cd build && \
|
||||
cmake -D CMAKE_BUILD_TYPE=RELEASE \
|
||||
-D WITH_IPP=OFF \
|
||||
-D WITH_OPENGL=OFF \
|
||||
-D WITH_QT=OFF \
|
||||
-D WITH_FREETYPE=ON \
|
||||
-D CMAKE_INSTALL_PREFIX=/usr/local \
|
||||
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \
|
||||
-D OPENCV_ENABLE_NONFREE=ON \
|
||||
-D WITH_JASPER=OFF \
|
||||
-D WITH_TBB=ON \
|
||||
-D BUILD_JPEG=ON \
|
||||
-D WITH_SIMD=ON \
|
||||
-D ENABLE_LIBJPEG_TURBO_SIMD=ON \
|
||||
-D BUILD_DOCS=OFF \
|
||||
-D BUILD_EXAMPLES=OFF \
|
||||
-D BUILD_TESTS=OFF \
|
||||
-D BUILD_PERF_TESTS=ON \
|
||||
-D BUILD_opencv_java=NO \
|
||||
-D BUILD_opencv_python=NO \
|
||||
-D BUILD_opencv_python2=NO \
|
||||
-D BUILD_opencv_python3=NO \
|
||||
-D OPENCV_GENERATE_PKGCONFIG=ON .. && \
|
||||
make -j $(nproc --all) && \
|
||||
make preinstall && make install && ldconfig && \
|
||||
cd / && rm -rf opencv*
|
||||
|
||||
|
||||
FROM golang:1.23.1-alpine AS go-builder
|
||||
|
||||
RUN apk add --no-cache gcc musl-dev libgcc libstdc++ cmake
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
ENV CGO_ENABLED=1
|
||||
|
||||
ENV CGO_CFLAGS="-I/usr/local/include/opencv4"
|
||||
|
||||
ENV CGO_LDFLAGS="-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui"
|
||||
|
||||
ENV GOOS=linux
|
||||
|
||||
ENV GOARCH=amd64
|
||||
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
COPY --from=opencv-builder /usr/local/lib /usr/local/lib
|
||||
COPY --from=opencv-builder /usr/local/include/opencv4 /usr/local/include/opencv4
|
||||
|
||||
RUN go mod download
|
||||
|
||||
RUN go build -o schisandra-cloud-album-server
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
|
||||
RUN apk add --no-cache tzdata
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=go-builder /app/schisandra-cloud-album-server .
|
||||
|
||||
COPY --from=go-builder /app/config.yaml .
|
||||
|
||||
COPY --from=go-builder /app/resource ./resource
|
||||
|
||||
COPY --from=go-builder /app/config/rbac_model.conf ./config/rbac_model.conf
|
||||
|
||||
COPY --from=opencv-builder /usr/local/lib /usr/local/lib
|
||||
|
||||
COPY --from=opencv-builder /usr/local/include/opencv4 /usr/local/include/opencv4
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["./schisandra-cloud-album-server"]
|
@@ -21,7 +21,6 @@ func Success() *types.Response {
|
||||
return &types.Response{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +29,6 @@ func SuccessWithMessage(message string) *types.Response {
|
||||
return &types.Response{
|
||||
Code: 200,
|
||||
Message: message,
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +37,6 @@ func Error() *types.Response {
|
||||
return &types.Response{
|
||||
Code: 500,
|
||||
Message: "error",
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +45,6 @@ func ErrorWithCode(code int64) *types.Response {
|
||||
return &types.Response{
|
||||
Code: code,
|
||||
Message: "error",
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +53,6 @@ func ErrorWithCodeMessage(code int64, message string) *types.Response {
|
||||
return &types.Response{
|
||||
Code: code,
|
||||
Message: message,
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +61,6 @@ func ErrorWithMessage(message string) *types.Response {
|
||||
return &types.Response{
|
||||
Code: 500,
|
||||
Message: message,
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +70,5 @@ func ErrorWithI18n(ctx context.Context, msgId string) *types.Response {
|
||||
return &types.Response{
|
||||
Code: 500,
|
||||
Message: message,
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
11
app/core/api/common/utils/xss_filter.go
Normal file
11
app/core/api/common/utils/xss_filter.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import "github.com/microcosm-cc/bluemonday"
|
||||
|
||||
// XssFilter Xss 过滤器
|
||||
func XssFilter(str string) string {
|
||||
p := bluemonday.NewPolicy()
|
||||
p.AllowElements("br", "img")
|
||||
p.AllowAttrs("style", "src", "alt", "width", "height", "loading").OnElements("img")
|
||||
return p.Sanitize(str)
|
||||
}
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/captcha"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -16,7 +17,11 @@ func GenerateRotateCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.GenerateRotateCaptcha()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/captcha"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -16,7 +17,11 @@ func GenerateSlideBasicCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFu
|
||||
resp, err := l.GenerateSlideBasicCaptcha()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/utils"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/client"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
@@ -18,7 +19,11 @@ func GenerateClientIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.GenerateClientId(clientIP)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"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"
|
||||
@@ -23,7 +24,11 @@ func DislikeCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.DislikeComment(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"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"
|
||||
@@ -23,7 +24,11 @@ func GetCommentListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.GetCommentList(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"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"
|
||||
@@ -23,7 +24,11 @@ func GetReplyListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.GetReplyList(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"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"
|
||||
@@ -23,7 +24,11 @@ func LikeCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.LikeComment(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"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"
|
||||
@@ -23,7 +24,11 @@ func SubmitCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.SubmitComment(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"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"
|
||||
@@ -23,7 +24,11 @@ func SubmitReplyCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.SubmitReplyComment(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"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"
|
||||
@@ -23,7 +24,11 @@ func SubmitReplyReplyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.SubmitReplyReply(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -16,7 +17,11 @@ func GetGiteeOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.GetGiteeOauthUrl()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -23,7 +24,11 @@ func GetGithubOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.GetGithubOauthUrl(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -23,7 +24,11 @@ func GetQqOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.GetQqOauthUrl(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -23,7 +24,11 @@ func GetWechatQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.GetWechatQrcode(r, &req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -24,7 +24,11 @@ func GiteeCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
err := l.GiteeCallback(w, r, &req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -24,7 +24,11 @@ func GithubCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
err := l.GithubCallback(w, r, &req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -24,7 +24,11 @@ func QqCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
err := l.QqCallback(w, r, &req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -17,7 +17,11 @@ func WechatCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
err := l.WechatCallback(w, r)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/sms"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -23,7 +24,11 @@ func SendSmsByAliyunHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.SendSmsByAliyun(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/sms"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -23,7 +24,11 @@ func SendSmsBySmsbaoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.SendSmsBySmsbao(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/sms"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -23,7 +24,11 @@ func SendSmsByTestHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.SendSmsByTest(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -23,7 +24,11 @@ func AccountLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.AccountLogin(w, r, &req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -17,7 +17,11 @@ func GetUserDeviceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
err := l.GetUserDevice(r)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -23,7 +24,11 @@ func PhoneLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.PhoneLogin(r, w, &req)
|
||||
if err != nil || resp.Code == 500 {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -16,7 +17,11 @@ func RefreshTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.RefreshToken(r)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/response"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -23,7 +24,11 @@ func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
resp, err := l.ResetPassword(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
httpx.WriteJsonCtx(
|
||||
r.Context(),
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
response.ErrorWithI18n(r.Context(), "system.error"))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ func NewGenerateRotateCaptchaLogic(ctx context.Context, svcCtx *svc.ServiceConte
|
||||
func (l *GenerateRotateCaptchaLogic) GenerateRotateCaptcha() (resp *types.Response, err error) {
|
||||
captcha, err := generate.GenerateRotateCaptcha(l.svcCtx.RotateCaptcha, l.svcCtx.RedisClient, l.ctx)
|
||||
if err != nil {
|
||||
return response.Error(), err
|
||||
return nil, err
|
||||
}
|
||||
return response.SuccessWithData(captcha), nil
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ func NewGenerateSlideBasicCaptchaLogic(ctx context.Context, svcCtx *svc.ServiceC
|
||||
func (l *GenerateSlideBasicCaptchaLogic) GenerateSlideBasicCaptcha() (resp *types.Response, err error) {
|
||||
captcha, err := generate.GenerateSlideBasicCaptcha(l.svcCtx.SlideCaptcha, l.svcCtx.RedisClient, l.ctx)
|
||||
if err != nil {
|
||||
return response.Error(), err
|
||||
return nil, err
|
||||
}
|
||||
return response.SuccessWithData(captcha), nil
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ func (l *GenerateClientIdLogic) GenerateClientId(clientIP string) (resp *types.R
|
||||
}
|
||||
simpleUuid := kgo.SimpleUuid()
|
||||
if err = l.svcCtx.RedisClient.SetEx(l.ctx, constant.UserClientPrefix+clientIP, simpleUuid, time.Hour*24*7).Err(); err != nil {
|
||||
return response.Error(), err
|
||||
return nil, err
|
||||
}
|
||||
return response.SuccessWithData(simpleUuid), nil
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@ package comment
|
||||
import (
|
||||
"context"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/captcha/verify"
|
||||
"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"
|
||||
|
||||
@@ -24,7 +26,11 @@ func NewSubmitCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sub
|
||||
}
|
||||
|
||||
func (l *SubmitCommentLogic) SubmitComment(req *types.CommentRequest) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
res := verify.VerifySlideCaptcha(l.ctx, l.svcCtx.RedisClient, req.Point, req.Key)
|
||||
if !res {
|
||||
return response.ErrorWithI18n(l.ctx, "captcha.verificationFailure"), nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ func (l *GetWechatQrcodeLogic) GetWechatQrcode(r *http.Request, req *types.OAuth
|
||||
if qrcode != "" {
|
||||
data := new(response.ResponseQRCodeCreate)
|
||||
if err = json.Unmarshal([]byte(qrcode), data); err != nil {
|
||||
return response2.Error(), err
|
||||
return nil, err
|
||||
}
|
||||
return response2.SuccessWithData(data.Url), nil
|
||||
}
|
||||
@@ -48,16 +48,16 @@ func (l *GetWechatQrcodeLogic) GetWechatQrcode(r *http.Request, req *types.OAuth
|
||||
// 生成临时二维码
|
||||
data, err := l.svcCtx.WechatPublic.QRCode.Temporary(l.ctx, req.Client_id, 7*24*3600)
|
||||
if err != nil {
|
||||
return response2.Error(), err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 序列化数据并存储到Redis
|
||||
serializedData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return response2.Error(), err
|
||||
return nil, err
|
||||
}
|
||||
if err = l.svcCtx.RedisClient.Set(l.ctx, key, serializedData, time.Hour*24*7).Err(); err != nil {
|
||||
return response2.Error(), err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response2.SuccessWithData(data.Url), nil
|
||||
|
@@ -56,7 +56,7 @@ func (l *SendSmsByAliyunLogic) SendSmsByAliyun(req *types.SmsSendRequest) (resp
|
||||
code := utils.GenValidateCode(6)
|
||||
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
||||
if wrong != nil {
|
||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), wrong
|
||||
return nil, wrong
|
||||
}
|
||||
_, err = sms.Send(req.Phone, gosms.MapStringAny{
|
||||
"content": "您的验证码是:****。请不要把验证码泄露给其他人。",
|
||||
@@ -67,7 +67,7 @@ func (l *SendSmsByAliyunLogic) SendSmsByAliyun(req *types.SmsSendRequest) (resp
|
||||
},
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), err
|
||||
return nil, err
|
||||
}
|
||||
return response.Success(), nil
|
||||
}
|
||||
|
@@ -54,13 +54,13 @@ func (l *SendSmsBySmsbaoLogic) SendSmsBySmsbao(req *types.SmsSendRequest) (resp
|
||||
code := utils.GenValidateCode(6)
|
||||
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
||||
if wrong != nil {
|
||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), wrong
|
||||
return nil, wrong
|
||||
}
|
||||
_, err = sms.Send(req.Phone, gosms.MapStringAny{
|
||||
"content": "您的验证码是:" + code + "。请不要把验证码泄露给其他人。",
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), err
|
||||
return nil, err
|
||||
}
|
||||
return response.Success(), nil
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ func (l *SendSmsByTestLogic) SendSmsByTest(req *types.SmsSendRequest) (resp *typ
|
||||
code := utils.GenValidateCode(6)
|
||||
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
||||
if wrong != nil {
|
||||
return response.ErrorWithI18n(l.ctx, "sms.smsSendFailed"), wrong
|
||||
return nil, wrong
|
||||
}
|
||||
return response.Success(), nil
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
@@ -13,7 +12,6 @@ import (
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/constant"
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/utils"
|
||||
"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/repository/mysql/ent"
|
||||
"schisandra-album-cloud-microservices/app/core/api/repository/mysql/ent/scaauthuserdevice"
|
||||
)
|
||||
@@ -37,17 +35,12 @@ func (l *GetUserDeviceLogic) GetUserDevice(r *http.Request) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sessionData, ok := session.Values[constant.SESSION_KEY]
|
||||
uid, ok := session.Values["uid"].(string)
|
||||
if !ok {
|
||||
return errors.New("user session not found")
|
||||
}
|
||||
var data types.SessionData
|
||||
err = json.Unmarshal(sessionData.([]byte), &data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res := GetUserLoginDevice(data.UID, r, l.svcCtx.Ip2Region, l.svcCtx.MySQLClient, l.ctx)
|
||||
res := GetUserLoginDevice(uid, r, l.svcCtx.Ip2Region, l.svcCtx.MySQLClient, l.ctx)
|
||||
if !res {
|
||||
return errors.New("user device not found")
|
||||
}
|
||||
@@ -63,7 +56,6 @@ func GetUserLoginDevice(userId string, r *http.Request, ip2location *xdb.Searche
|
||||
ip := utils.GetClientIP(r)
|
||||
location, err := ip2location.SearchByStr(ip)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return false
|
||||
}
|
||||
location = utils.RemoveZeroAndAdjust(location)
|
||||
|
@@ -46,7 +46,7 @@ func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, w http.ResponseWriter, req
|
||||
user, err := l.svcCtx.MySQLClient.ScaAuthUser.Query().Where(scaauthuser.Phone(req.Phone), scaauthuser.Deleted(0)).First(l.ctx)
|
||||
tx, wrong := l.svcCtx.MySQLClient.Tx(l.ctx)
|
||||
if wrong != nil {
|
||||
return response.ErrorWithI18n(l.ctx, "login.loginFailed"), err
|
||||
return nil, err
|
||||
}
|
||||
if ent.IsNotFound(err) {
|
||||
uid := idgen.NextId()
|
||||
@@ -64,12 +64,12 @@ func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, w http.ResponseWriter, req
|
||||
Save(l.ctx)
|
||||
if fault != nil {
|
||||
err = tx.Rollback()
|
||||
return response.ErrorWithI18n(l.ctx, "login.registerError"), err
|
||||
return nil, err
|
||||
}
|
||||
_, err = l.svcCtx.CasbinEnforcer.AddRoleForUser(uidStr, constant.User)
|
||||
if err != nil {
|
||||
err = tx.Rollback()
|
||||
return response.ErrorWithI18n(l.ctx, "login.registerError"), err
|
||||
return nil, err
|
||||
}
|
||||
data, result := HandleUserLogin(addUser, l.svcCtx, req.AutoLogin, r, w, l.ctx)
|
||||
if !result {
|
||||
|
@@ -32,7 +32,7 @@ func NewRefreshTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Refr
|
||||
func (l *RefreshTokenLogic) RefreshToken(r *http.Request) (resp *types.Response, err error) {
|
||||
session, err := l.svcCtx.Session.Get(r, constant.SESSION_KEY)
|
||||
if err != nil {
|
||||
return response.ErrorWithCode(403), err
|
||||
return nil, err
|
||||
}
|
||||
refreshSessionToken, ok := session.Values["refresh_token"].(string)
|
||||
if !ok {
|
||||
@@ -49,7 +49,7 @@ func (l *RefreshTokenLogic) RefreshToken(r *http.Request) (resp *types.Response,
|
||||
redisTokenData := types.RedisToken{}
|
||||
err = json.Unmarshal([]byte(tokenData), &redisTokenData)
|
||||
if err != nil {
|
||||
return response.ErrorWithCode(403), err
|
||||
return nil, err
|
||||
}
|
||||
if redisTokenData.RefreshToken != refreshSessionToken {
|
||||
return response.ErrorWithCode(403), nil
|
||||
@@ -72,7 +72,7 @@ func (l *RefreshTokenLogic) RefreshToken(r *http.Request) (resp *types.Response,
|
||||
}
|
||||
err = l.svcCtx.RedisClient.Set(l.ctx, constant.UserTokenPrefix+refreshToken.UserID, redisToken, time.Hour*24*7).Err()
|
||||
if err != nil {
|
||||
return response.ErrorWithCode(403), err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response.SuccessWithData(accessToken), nil
|
||||
|
@@ -47,19 +47,19 @@ func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (res
|
||||
}
|
||||
// 验证码检查通过后立即删除或标记为已使用
|
||||
if err = l.svcCtx.RedisClient.Del(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Err(); err != nil {
|
||||
return response.ErrorWithI18n(l.ctx, "login.captchaError"), err
|
||||
return nil, err
|
||||
}
|
||||
user, err := l.svcCtx.MySQLClient.ScaAuthUser.Query().Where(scaauthuser.Phone(req.Phone), scaauthuser.Deleted(constant.NotDeleted)).First(l.ctx)
|
||||
if err != nil && ent.IsNotFound(err) {
|
||||
return response.ErrorWithI18n(l.ctx, "login.userNotRegistered"), err
|
||||
return response.ErrorWithI18n(l.ctx, "login.userNotRegistered"), nil
|
||||
}
|
||||
encrypt, err := utils.Encrypt(req.Password)
|
||||
if err != nil {
|
||||
return response.ErrorWithI18n(l.ctx, "login.resetPasswordError"), err
|
||||
return nil, err
|
||||
}
|
||||
err = user.Update().SetPassword(encrypt).Exec(l.ctx)
|
||||
if err != nil {
|
||||
return response.ErrorWithI18n(l.ctx, "login.resetPasswordError"), err
|
||||
return nil, err
|
||||
}
|
||||
return response.Success(), nil
|
||||
}
|
||||
|
@@ -45,14 +45,15 @@ type ServiceContext struct {
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
casbinEnforcer := casbinx.NewCasbin(c.Mysql.DataSource)
|
||||
redisClient := redisx.NewRedis(c.Redis.Host, c.Redis.Pass, c.Redis.DB)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
SecurityHeadersMiddleware: middleware.NewSecurityHeadersMiddleware().Handle,
|
||||
CasbinVerifyMiddleware: middleware.NewCasbinVerifyMiddleware(casbinEnforcer).Handle,
|
||||
MySQLClient: mysql.NewMySQL(c.Mysql.DataSource),
|
||||
RedisClient: redisx.NewRedis(c.Redis.Host, c.Redis.Pass, c.Redis.DB),
|
||||
RedisClient: redisClient,
|
||||
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(redisClient),
|
||||
Ip2Region: ip2region.NewIP2Region(),
|
||||
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),
|
||||
|
@@ -13,12 +13,7 @@ import (
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
)
|
||||
|
||||
func NewRedisSession(addr string, password string) *redisstore.RedisStore {
|
||||
client := redis.NewClient(&redis.Options{
|
||||
Addr: addr,
|
||||
Password: password,
|
||||
DB: 0,
|
||||
})
|
||||
func NewRedisSession(client *redis.Client) *redisstore.RedisStore {
|
||||
store, err := redisstore.NewRedisStore(context.Background(), client)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@@ -1,3 +1,5 @@
|
||||
[system]
|
||||
error = "system error!"
|
||||
[captcha]
|
||||
verificationFailure = "verification failure!"
|
||||
[login]
|
||||
|
@@ -1,3 +1,5 @@
|
||||
[system]
|
||||
error = "系统错误!"
|
||||
[captcha]
|
||||
verificationFailure = "验证失败!"
|
||||
[login]
|
||||
|
Reference in New Issue
Block a user