feat ✨ 验证码store支持go-admin cache

This commit is contained in:
linwenxiang committed 2021-04-08 21:33:36 +08:00
1 parent 40cd55da90
commit b69bc87468
6 files changed
+72 -15

No files matched your search

+60
View File
@@ -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
View File
@@ -3,8 +3,6 @@ package api
import (
"context"
"fmt"
"github.com/go-admin-team/go-admin-core/tools/captcha"
"go-admin/common/middleware/handler"
"log"
"net/http"
"os"
@@ -16,6 +14,7 @@ import (
"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/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/spf13/cobra"
@@ -74,7 +73,7 @@ func setup() {
}
sdk.Runtime.SetCacheAdapter(cacheAdapter)
//5. 设置验证码store
handler.SetStore(captcha.NewCacheStore(cacheAdapter, 600))
captcha.SetStore(captcha.NewCacheStore(cacheAdapter, 600))
usageStr := `starting api server...`
log.Println(usageStr)
+2 -9
View File
@@ -8,23 +8,16 @@ import (
"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/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/captcha"
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/response"
"github.com/mojocn/base64Captcha"
"github.com/mssola/user_agent"
"go-admin/app/admin/models/system"
"go-admin/common/global"
)
var store = base64Captcha.DefaultMemStore
// SetStore 设置store
func SetStore(s base64Captcha.Store) {
store = s
}
func PayloadFunc(data interface{}) jwt.MapClaims {
if v, ok := data.(map[string]interface{}); ok {
u, _ := v["user"].(SysUser)
@@ -90,7 +83,7 @@ func Authenticator(c *gin.Context) (interface{}, error) {
return nil, jwt.ErrMissingLoginValues
}
if config.ApplicationConfig.Mode != "dev" {
if !store.Verify(loginVals.UUID, loginVals.Code, true) {
if !captcha.Verify(loginVals.UUID, loginVals.Code, true) {
username = loginVals.Username
msg = "验证码错误"
status = "1"
+1 -2
View File
@@ -8,9 +8,8 @@ require (
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5
github.com/casbin/casbin/v2 v2.25.1
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/mojocn/base64Captcha v1.3.1
github.com/mssola/user_agent v0.5.2
github.com/opentracing/opentracing-go v1.1.0
github.com/prometheus/client_golang v1.1.0
+6
View File
@@ -0,0 +1,6 @@
FROM alpine
COPY ./go-admin /
EXPOSE 8000
CMD ["/go-admin","server","-c", "/config/settings.yml"]
+1 -1
View File
@@ -35,7 +35,7 @@ spec:
spec:
containers:
- name: go-admin
image: ${IMAGE}
image: registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8000