Skip to content

Commit f553bfd

Browse files
Merge branch 'dev' into ft/cms1-6
2 parents 47233a4 + 0f53754 commit f553bfd

File tree

13 files changed

+819
-160
lines changed

13 files changed

+819
-160
lines changed

backend/cms-sys/cmd/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ func main() {
6969
return
7070
}
7171

72+
if err := utils.InitRedis(); err != nil {
73+
appLogger.Fatal("Failed to initialize Redis:", err)
74+
}
75+
defer func() {
76+
err := utils.CloseRedis()
77+
if err != nil {
78+
appLogger.WithError(err).Fatal("Failed to close Redis connection")
79+
}
80+
}()
7281
//if err := utils.InitJWTKeysFromVault(); err != nil {
7382
// log.Fatalf("Vault key init failed: %v", err)
7483
//}
@@ -177,6 +186,9 @@ func main() {
177186

178187
func DependencyInjectionSection(logger *logrus.Logger, db *gorm.DB) *DISection {
179188
repo := repository.NewRepo(logger, db)
189+
if err := repo.CreateDefaultRoles(); err != nil {
190+
logger.Fatalf("Failed to create default roles: %v", err)
191+
}
180192
srv := service.NewService(logger, repo)
181193
authHandler := handler.NewHandler(srv)
182194

backend/cms-sys/go.mod

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/gofiber/fiber/v2 v2.52.8
88
github.com/golang-jwt/jwt/v5 v5.2.2
99
github.com/google/uuid v1.6.0
10-
github.com/hashicorp/vault/api v1.20.0
10+
github.com/redis/go-redis/v9 v9.11.0
1111
github.com/sirupsen/logrus v1.9.3
1212
golang.org/x/crypto v0.36.0
1313
gopkg.in/natefinch/lumberjack.v2 v2.2.1
@@ -17,20 +17,11 @@ require (
1717

1818
require (
1919
github.com/andybalholm/brotli v1.1.0 // indirect
20-
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
20+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
21+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
2122
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
22-
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
2323
github.com/go-playground/locales v0.14.1 // indirect
2424
github.com/go-playground/universal-translator v0.18.1 // indirect
25-
github.com/hashicorp/errwrap v1.1.0 // indirect
26-
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
27-
github.com/hashicorp/go-multierror v1.1.1 // indirect
28-
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
29-
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
30-
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect
31-
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
32-
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
33-
github.com/hashicorp/hcl v1.0.1-vault-7 // indirect
3425
github.com/jackc/pgpassfile v1.0.0 // indirect
3526
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
3627
github.com/jackc/pgx/v5 v5.6.0 // indirect
@@ -42,16 +33,13 @@ require (
4233
github.com/mattn/go-colorable v0.1.13 // indirect
4334
github.com/mattn/go-isatty v0.0.20 // indirect
4435
github.com/mattn/go-runewidth v0.0.16 // indirect
45-
github.com/mitchellh/go-homedir v1.1.0 // indirect
46-
github.com/mitchellh/mapstructure v1.5.0 // indirect
4736
github.com/rivo/uniseg v0.2.0 // indirect
48-
github.com/ryanuber/go-glob v1.0.0 // indirect
37+
github.com/stretchr/testify v1.10.0 // indirect
4938
github.com/valyala/bytebufferpool v1.0.0 // indirect
5039
github.com/valyala/fasthttp v1.51.0 // indirect
5140
github.com/valyala/tcplisten v1.0.0 // indirect
5241
golang.org/x/net v0.37.0 // indirect
5342
golang.org/x/sync v0.12.0 // indirect
5443
golang.org/x/sys v0.31.0 // indirect
5544
golang.org/x/text v0.23.0 // indirect
56-
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect
5745
)

backend/cms-sys/go.sum

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
22
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
3-
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
4-
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
5-
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
6-
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
3+
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
4+
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
5+
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
6+
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
7+
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
8+
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
79
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
810
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
911
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10-
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
11-
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
12-
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
12+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
13+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
1314
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
1415
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
15-
github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE=
16-
github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA=
1716
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
1817
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
1918
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
@@ -22,41 +21,12 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
2221
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
2322
github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
2423
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
25-
github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw=
26-
github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
2724
github.com/gofiber/fiber/v2 v2.52.8 h1:xl4jJQ0BV5EJTA2aWiKw/VddRpHrKeZLF0QPUxqn0x4=
2825
github.com/gofiber/fiber/v2 v2.52.8/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
2926
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
3027
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
31-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
32-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3328
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
3429
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
35-
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
36-
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
37-
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
38-
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
39-
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
40-
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
41-
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
42-
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
43-
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
44-
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
45-
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
46-
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
47-
github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc=
48-
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
49-
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 h1:om4Al8Oy7kCm/B86rLCLah4Dt5Aa0Fr5rYBG60OzwHQ=
50-
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6/go.mod h1:QmrqtbKuxxSWTN3ETMPuB+VtEiBJ/A9XhoYGv8E1uD8=
51-
github.com/hashicorp/go-secure-stdlib/strutil v0.1.1/go.mod h1:gKOamz3EwoIoJq7mlMIRBpVTAUn8qPCrEclOKKWhD3U=
52-
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9CdjCtrXrXGuOpxEA7Ts=
53-
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4=
54-
github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc=
55-
github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A=
56-
github.com/hashicorp/hcl v1.0.1-vault-7 h1:ag5OxFVy3QYTFTJODRzTKVZ6xvdfLLCA1cy/Y6xGI0I=
57-
github.com/hashicorp/hcl v1.0.1-vault-7/go.mod h1:XYhtn6ijBSAj6n4YqAaf7RBPS4I06AItNorpy+MoQNM=
58-
github.com/hashicorp/vault/api v1.20.0 h1:KQMHElgudOsr+IbJgmbjHnCTxEpKs9LnozA1D3nozU4=
59-
github.com/hashicorp/vault/api v1.20.0/go.mod h1:GZ4pcjfzoOWpkJ3ijHNpEoAxKEsBJnVljyTe3jM2Sms=
6030
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
6131
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
6232
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
@@ -73,30 +43,19 @@ github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2
7343
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
7444
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
7545
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
76-
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
7746
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
7847
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
79-
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
8048
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
8149
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
8250
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
8351
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
8452
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
85-
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
86-
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
87-
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
88-
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
89-
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
90-
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
91-
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
9253
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
9354
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
94-
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
55+
github.com/redis/go-redis/v9 v9.11.0 h1:E3S08Gl/nJNn5vkxd2i78wZxWAPNZgUNTp8WIJUAiIs=
56+
github.com/redis/go-redis/v9 v9.11.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
9557
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
9658
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
97-
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
98-
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
99-
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
10059
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
10160
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
10261
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -116,16 +75,13 @@ golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
11675
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
11776
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
11877
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
119-
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
12078
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12179
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12280
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12381
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
12482
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
12583
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
12684
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
127-
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
128-
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
12985
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
13086
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
13187
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=

backend/cms-sys/internal/handler/auth_handler.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package handler
22

33
import (
4+
"strings"
5+
46
"github.com/go-playground/validator/v10"
57
"github.com/gofiber/fiber/v2"
68
"github.com/google/uuid"
@@ -73,6 +75,29 @@ func (h *Handler) Register(c *fiber.Ctx) error {
7375
}
7476

7577
func (h *Handler) Logout(c *fiber.Ctx) error {
78+
authHeader := c.Get("Authorization")
79+
var accessToken string
80+
if authHeader != "" && strings.HasPrefix(authHeader, "Bearer ") {
81+
accessToken = strings.TrimPrefix(authHeader, "Bearer ")
82+
}
83+
84+
var refreshToken string
85+
var req struct {
86+
RefreshToken string `json:"refresh_token"`
87+
}
88+
89+
if err := c.BodyParser(&req); err == nil {
90+
refreshToken = req.RefreshToken
91+
}
92+
93+
if accessToken == "" && refreshToken == "" {
94+
return utils.SuccessResponse(c, "Logout successful", nil)
95+
}
96+
97+
if err := h.service.Logout(accessToken, refreshToken); err != nil {
98+
return utils.InternalServerErrorResponse(c, err.Error(), nil)
99+
}
100+
76101
return utils.SuccessResponse(c, "Logout successful", nil)
77102
}
78103

backend/cms-sys/internal/repository/auth_repo.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,43 @@ func (r *Repo) EmailExists(email string) (bool, error) {
8787
}
8888
return count > 0, nil
8989
}
90+
func (r *Repo) CreateRole(role *types.CMSWholeSysRole) error {
91+
if err := r.db.Create(role).Error; err != nil {
92+
r.logger.WithError(err).Error("Failed to create role")
93+
return err
94+
}
95+
return nil
96+
}
97+
98+
func (r *Repo) RoleExists(roleName string) (bool, error) {
99+
var count int64
100+
if err := r.db.Model(&types.CMSWholeSysRole{}).Where("role_name = ?", roleName).Count(&count).Error; err != nil {
101+
r.logger.WithError(err).Error("Failed to check if role exists")
102+
return false, err
103+
}
104+
return count > 0, nil
105+
}
106+
107+
func (r *Repo) CreateDefaultRoles() error {
108+
roles := []types.CMSWholeSysRole{
109+
{RoleName: string(types.RootAdmin)},
110+
{RoleName: string(types.CMSCustomer)},
111+
}
112+
113+
for _, role := range roles {
114+
exists, err := r.RoleExists(role.RoleName)
115+
if err != nil {
116+
return err
117+
}
118+
119+
if !exists {
120+
if err := r.CreateRole(&role); err != nil {
121+
return err
122+
}
123+
r.logger.Infof("Created role: %s", role.RoleName)
124+
} else {
125+
r.logger.Infof("Role already exists: %s", role.RoleName)
126+
}
127+
}
128+
return nil
129+
}

backend/cms-sys/internal/service/auth_service.go

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type AuthService interface {
1717
GetUserProfile(userID uuid.UUID) (*types.UserResponse, error)
1818
GetMe(req types.GetMeRequest) (*types.UserResponse, error)
1919
UpdateUserProfile(id uuid.UUID, req types.UserUpdateRequest) (*types.UserResponse, error)
20+
Logout(accessToken, refreshToken string) error
2021
}
2122

2223
type Service struct {
@@ -113,17 +114,17 @@ func (s *Service) Register(req *types.RegisterRequest) (*types.AuthResponse, err
113114
return nil, errors.New("failed to create user")
114115
}
115116

116-
accessToken, err := utils.GenerateAccessToken(user.CMSUserID, user.CMSUserEmail, user.CMSUserRole)
117-
if err != nil {
118-
s.log.WithError(err).Error("Failed to generate access token")
119-
return nil, errors.New("failed to generate access token")
120-
}
121-
122-
refreshToken, err := utils.GenerateRefreshToken(user.CMSUserID, user.CMSUserEmail, user.CMSUserRole)
123-
if err != nil {
124-
s.log.WithError(err).Error("Failed to generate refresh token")
125-
return nil, errors.New("failed to generate refresh token")
126-
}
117+
//accessToken, err := utils.GenerateAccessToken(user.CMSUserID, user.CMSUserEmail, user.CMSUserRole)
118+
//if err != nil {
119+
// s.log.WithError(err).Error("Failed to generate access token")
120+
// return nil, errors.New("failed to generate access token")
121+
//}
122+
//
123+
//refreshToken, err := utils.GenerateRefreshToken(user.CMSUserID, user.CMSUserEmail, user.CMSUserRole)
124+
//if err != nil {
125+
// s.log.WithError(err).Error("Failed to generate refresh token")
126+
// return nil, errors.New("failed to generate refresh token")
127+
//}
127128

128129
userResponse := types.UserResponse{
129130
ID: user.CMSUserID,
@@ -136,10 +137,10 @@ func (s *Service) Register(req *types.RegisterRequest) (*types.AuthResponse, err
136137
}
137138

138139
return &types.AuthResponse{
139-
User: userResponse,
140-
AccessToken: accessToken,
141-
RefreshToken: refreshToken,
142-
ExpiresAt: time.Now().Add(15 * time.Minute),
140+
User: userResponse,
141+
////AccessToken: accessToken,
142+
////RefreshToken: refreshToken,
143+
//ExpiresAt: time.Now().Add(15 * time.Minute),
143144
}, nil
144145
}
145146

@@ -197,6 +198,7 @@ func (s *Service) GetUserProfile(userID uuid.UUID) (*types.UserResponse, error)
197198
}, nil
198199
}
199200

201+
200202
func (s *Service) GetMe(req types.GetMeRequest) (*types.UserResponse, error) {
201203

202204
user, err := s.repo.GetUserByEmail(req.Email)
@@ -241,4 +243,33 @@ func (s *Service) UpdateUserProfile(id uuid.UUID, req types.UserUpdateRequest) (
241243
UpdatedAt: user.UpdatedAt,
242244
}, nil
243245

246+
247+
func (s *Service) Logout(accessToken, refreshToken string) error {
248+
if accessToken != "" {
249+
accessClaims, err := utils.ValidateToken(accessToken)
250+
if err == nil && accessClaims.ID != "" {
251+
ttl := time.Until(accessClaims.ExpiresAt.Time)
252+
if ttl > 0 {
253+
if err := utils.RevokeToken(accessClaims.ID, ttl); err != nil {
254+
s.log.WithError(err).Error("Failed to revoke access token")
255+
return errors.New("failed to revoke access token")
256+
}
257+
}
258+
}
259+
}
260+
261+
if refreshToken != "" {
262+
refreshClaims, err := utils.ValidateToken(refreshToken)
263+
if err == nil && refreshClaims.ID != "" {
264+
ttl := time.Until(refreshClaims.ExpiresAt.Time)
265+
if ttl > 0 {
266+
if err := utils.RevokeToken(refreshClaims.ID, ttl); err != nil {
267+
s.log.WithError(err).Error("Failed to revoke refresh token")
268+
return errors.New("failed to revoke refresh token")
269+
}
270+
}
271+
}
272+
}
273+
274+
return nil
244275
}

backend/cms-sys/internal/types/response.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77

88
type AuthResponse struct {
99
User UserResponse `json:"user"`
10-
AccessToken string `json:"access_token"`
11-
RefreshToken string `json:"refresh_token"`
12-
ExpiresAt time.Time `json:"expires_at"`
10+
AccessToken string `json:"access_token,omitempty"`
11+
RefreshToken string `json:"refresh_token,omitempty"`
12+
ExpiresAt time.Time `json:"expires_at,omitempty"`
1313
}
1414

1515
type UserResponse struct {

0 commit comments

Comments
 (0)