feat ✨ 验证码store支持go-admin cache
This commit is contained in:
1 parent
40cd55da90
commit
b69bc87468
6 files changed
+72
-15
No files matched your search
@@ -0,0 +1,60 @@
|
|||||||
|
name: build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ dev-lwx ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ dev-lwx ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Go 1.15
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.15
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Get dependencies
|
||||||
|
run: |
|
||||||
|
go get -v -t -d ./...
|
||||||
|
if [ -f Gopkg.toml ]; then
|
||||||
|
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||||
|
dep ensure
|
||||||
|
fi
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o go-admin .
|
||||||
|
mv go-admin ./scripts
|
||||||
|
|
||||||
|
- uses: Azure/docker-login@v1
|
||||||
|
with:
|
||||||
|
login-server: registry.cn-shanghai.aliyuncs.com
|
||||||
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
- run: |
|
||||||
|
docker build ./scripts -t registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }}
|
||||||
|
docker push registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }}
|
||||||
|
- uses: Azure/k8s-set-context@v1
|
||||||
|
with:
|
||||||
|
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
||||||
|
|
||||||
|
- uses: Azure/k8s-create-secret@v1
|
||||||
|
with:
|
||||||
|
namespace: 'go-admin'
|
||||||
|
container-registry-url: registry.cn-shanghai.aliyuncs.com
|
||||||
|
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
secret-name: aliyuncs-k8s-secret
|
||||||
|
|
||||||
|
- uses: Azure/k8s-deploy@v1
|
||||||
|
with:
|
||||||
|
namespace: 'go-admin'
|
||||||
|
manifests: 'scripts/k8s/deploy.yml'
|
||||||
|
images: 'registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }}'
|
||||||
|
imagepullsecrets: 'aliyuncs-k8s-secret'
|
||||||
|
kubectl-version: 'latest'
|
||||||
+2
-3
@@ -3,8 +3,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-admin-team/go-admin-core/tools/captcha"
|
|
||||||
"go-admin/common/middleware/handler"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -16,6 +14,7 @@ import (
|
|||||||
"github.com/go-admin-team/go-admin-core/sdk"
|
"github.com/go-admin-team/go-admin-core/sdk"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/config"
|
"github.com/go-admin-team/go-admin-core/sdk/config"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/pkg"
|
"github.com/go-admin-team/go-admin-core/sdk/pkg"
|
||||||
|
"github.com/go-admin-team/go-admin-core/sdk/pkg/captcha"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/logger"
|
"github.com/go-admin-team/go-admin-core/sdk/pkg/logger"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@@ -74,7 +73,7 @@ func setup() {
|
|||||||
}
|
}
|
||||||
sdk.Runtime.SetCacheAdapter(cacheAdapter)
|
sdk.Runtime.SetCacheAdapter(cacheAdapter)
|
||||||
//5. 设置验证码store
|
//5. 设置验证码store
|
||||||
handler.SetStore(captcha.NewCacheStore(cacheAdapter, 600))
|
captcha.SetStore(captcha.NewCacheStore(cacheAdapter, 600))
|
||||||
|
|
||||||
usageStr := `starting api server...`
|
usageStr := `starting api server...`
|
||||||
log.Println(usageStr)
|
log.Println(usageStr)
|
||||||
|
|||||||
@@ -8,23 +8,16 @@ import (
|
|||||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/config"
|
"github.com/go-admin-team/go-admin-core/sdk/config"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/pkg"
|
"github.com/go-admin-team/go-admin-core/sdk/pkg"
|
||||||
|
"github.com/go-admin-team/go-admin-core/sdk/pkg/captcha"
|
||||||
jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
|
jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
||||||
"github.com/mojocn/base64Captcha"
|
|
||||||
"github.com/mssola/user_agent"
|
"github.com/mssola/user_agent"
|
||||||
|
|
||||||
"go-admin/app/admin/models/system"
|
"go-admin/app/admin/models/system"
|
||||||
"go-admin/common/global"
|
"go-admin/common/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
var store = base64Captcha.DefaultMemStore
|
|
||||||
|
|
||||||
// SetStore 设置store
|
|
||||||
func SetStore(s base64Captcha.Store) {
|
|
||||||
store = s
|
|
||||||
}
|
|
||||||
|
|
||||||
func PayloadFunc(data interface{}) jwt.MapClaims {
|
func PayloadFunc(data interface{}) jwt.MapClaims {
|
||||||
if v, ok := data.(map[string]interface{}); ok {
|
if v, ok := data.(map[string]interface{}); ok {
|
||||||
u, _ := v["user"].(SysUser)
|
u, _ := v["user"].(SysUser)
|
||||||
@@ -90,7 +83,7 @@ func Authenticator(c *gin.Context) (interface{}, error) {
|
|||||||
return nil, jwt.ErrMissingLoginValues
|
return nil, jwt.ErrMissingLoginValues
|
||||||
}
|
}
|
||||||
if config.ApplicationConfig.Mode != "dev" {
|
if config.ApplicationConfig.Mode != "dev" {
|
||||||
if !store.Verify(loginVals.UUID, loginVals.Code, true) {
|
if !captcha.Verify(loginVals.UUID, loginVals.Code, true) {
|
||||||
username = loginVals.Username
|
username = loginVals.Username
|
||||||
msg = "验证码错误"
|
msg = "验证码错误"
|
||||||
status = "1"
|
status = "1"
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ require (
|
|||||||
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5
|
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5
|
||||||
github.com/casbin/casbin/v2 v2.25.1
|
github.com/casbin/casbin/v2 v2.25.1
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
github.com/go-admin-team/go-admin-core v1.3.0-rc.0.0.20210407093008-7e27bec63f3e
|
github.com/go-admin-team/go-admin-core v1.3.4
|
||||||
github.com/google/uuid v1.2.0
|
github.com/google/uuid v1.2.0
|
||||||
github.com/mojocn/base64Captcha v1.3.1
|
|
||||||
github.com/mssola/user_agent v0.5.2
|
github.com/mssola/user_agent v0.5.2
|
||||||
github.com/opentracing/opentracing-go v1.1.0
|
github.com/opentracing/opentracing-go v1.1.0
|
||||||
github.com/prometheus/client_golang v1.1.0
|
github.com/prometheus/client_golang v1.1.0
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
FROM alpine
|
||||||
|
|
||||||
|
COPY ./go-admin /
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
CMD ["/go-admin","server","-c", "/config/settings.yml"]
|
||||||
@@ -35,7 +35,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: go-admin
|
- name: go-admin
|
||||||
image: ${IMAGE}
|
image: registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8000
|
- containerPort: 8000
|
||||||
|
|||||||
Reference in new issue
Block a user