mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	refactor: oauth2登录优化
This commit is contained in:
		@@ -50,7 +50,7 @@
 | 
				
			|||||||
    "sass": "^1.62.0",
 | 
					    "sass": "^1.62.0",
 | 
				
			||||||
    "sass-loader": "^13.2.0",
 | 
					    "sass-loader": "^13.2.0",
 | 
				
			||||||
    "typescript": "^5.0.2",
 | 
					    "typescript": "^5.0.2",
 | 
				
			||||||
    "vite": "^4.4.2",
 | 
					    "vite": "^4.4.7",
 | 
				
			||||||
    "vue-eslint-parser": "^9.1.1"
 | 
					    "vue-eslint-parser": "^9.1.1"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "browserslist": [
 | 
					  "browserslist": [
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -106,7 +106,7 @@
 | 
				
			|||||||
        </el-dialog>
 | 
					        </el-dialog>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <el-dialog title="修改基本信息" v-model="baseInfoDialog.visible" :close-on-click-modal="false" width="450px" :destroy-on-close="true">
 | 
					        <el-dialog title="修改基本信息" v-model="baseInfoDialog.visible" :close-on-click-modal="false" width="450px" :destroy-on-close="true">
 | 
				
			||||||
            <el-form :model="baseInfoDialog.form" :rules="baseInfoDialog.rules" ref="changePwdFormRef" label-width="auto">
 | 
					            <el-form :model="baseInfoDialog.form" :rules="baseInfoDialog.rules" ref="baseInfoFormRef" label-width="auto">
 | 
				
			||||||
                <el-form-item prop="username" label="用户名" required>
 | 
					                <el-form-item prop="username" label="用户名" required>
 | 
				
			||||||
                    <el-input v-model.trim="baseInfoDialog.form.username"></el-input>
 | 
					                    <el-input v-model.trim="baseInfoDialog.form.username"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
@@ -117,7 +117,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
                <div class="dialog-footer">
 | 
					                <div class="dialog-footer">
 | 
				
			||||||
                    <!-- <el-button @click="cancelChangePwd">取 消</el-button> -->
 | 
					 | 
				
			||||||
                    <el-button @click="updateUserInfo()" type="primary" :loading="loading.updateUserConfirm">确 定</el-button>
 | 
					                    <el-button @click="updateUserInfo()" type="primary" :loading="loading.updateUserConfirm">确 定</el-button>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            </template>
 | 
					            </template>
 | 
				
			||||||
@@ -152,6 +151,7 @@ const loginFormRef: any = ref(null);
 | 
				
			|||||||
const changePwdFormRef: any = ref(null);
 | 
					const changePwdFormRef: any = ref(null);
 | 
				
			||||||
const otpFormRef: any = ref(null);
 | 
					const otpFormRef: any = ref(null);
 | 
				
			||||||
const otpCodeInputRef: any = ref(null);
 | 
					const otpCodeInputRef: any = ref(null);
 | 
				
			||||||
 | 
					const baseInfoFormRef: any = ref(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const state = reactive({
 | 
					const state = reactive({
 | 
				
			||||||
    accountLoginSecurity: {
 | 
					    accountLoginSecurity: {
 | 
				
			||||||
@@ -301,12 +301,22 @@ const onSignIn = async () => {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const updateUserInfo = async () => {
 | 
					const updateUserInfo = async () => {
 | 
				
			||||||
 | 
					    baseInfoFormRef.value.validate(async (valid: boolean) => {
 | 
				
			||||||
 | 
					        if (!valid) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            state.loading.updateUserConfirm = true;
 | 
				
			||||||
            const form = state.baseInfoDialog.form;
 | 
					            const form = state.baseInfoDialog.form;
 | 
				
			||||||
            await personApi.updateAccount.request(state.baseInfoDialog.form);
 | 
					            await personApi.updateAccount.request(state.baseInfoDialog.form);
 | 
				
			||||||
            state.baseInfoDialog.visible = false;
 | 
					            state.baseInfoDialog.visible = false;
 | 
				
			||||||
            useUserInfo().userInfo.username = form.username;
 | 
					            useUserInfo().userInfo.username = form.username;
 | 
				
			||||||
            useUserInfo().userInfo.name = form.name;
 | 
					            useUserInfo().userInfo.name = form.name;
 | 
				
			||||||
            await toIndex();
 | 
					            await toIndex();
 | 
				
			||||||
 | 
					        } finally {
 | 
				
			||||||
 | 
					            state.loading.updateUserConfirm = false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const loginResDeal = (loginRes: any) => {
 | 
					const loginResDeal = (loginRes: any) => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,9 +18,9 @@
 | 
				
			|||||||
                        </transition>
 | 
					                        </transition>
 | 
				
			||||||
                    </el-tab-pane> -->
 | 
					                    </el-tab-pane> -->
 | 
				
			||||||
                </el-tabs>
 | 
					                </el-tabs>
 | 
				
			||||||
                <div class="mt20" v-show="authConfig.enable">
 | 
					                <div class="mt20" v-show="oauth2LoginConfig.enable">
 | 
				
			||||||
                    <el-button link size="small">第三方登录: </el-button>
 | 
					                    <el-button link size="small">第三方登录: </el-button>
 | 
				
			||||||
                    <el-tooltip content="OAuth2登录" placement="top-start">
 | 
					                    <el-tooltip :content="oauth2LoginConfig.name" placement="top-start">
 | 
				
			||||||
                        <el-button link size="small" type="primary" @click="oauth2Login">
 | 
					                        <el-button link size="small" type="primary" @click="oauth2Login">
 | 
				
			||||||
                            <el-icon :size="18">
 | 
					                            <el-icon :size="18">
 | 
				
			||||||
                                <Link />
 | 
					                                <Link />
 | 
				
			||||||
@@ -50,13 +50,14 @@ const state = reactive({
 | 
				
			|||||||
    tabsActiveName: 'account',
 | 
					    tabsActiveName: 'account',
 | 
				
			||||||
    isTabPaneShow: true,
 | 
					    isTabPaneShow: true,
 | 
				
			||||||
    oauth2LoginConfig: {
 | 
					    oauth2LoginConfig: {
 | 
				
			||||||
 | 
					        name: 'OAuth2登录',
 | 
				
			||||||
        enable: false,
 | 
					        enable: false,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const loginForm = ref<{ loginResDeal: (data: any) => void } | null>(null);
 | 
					const loginForm = ref<{ loginResDeal: (data: any) => void } | null>(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const { isTabPaneShow, tabsActiveName, oauth2LoginConfig: authConfig } = toRefs(state);
 | 
					const { isTabPaneShow, tabsActiveName, oauth2LoginConfig: oauth2LoginConfig } = toRefs(state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 切换密码、手机登录
 | 
					// 切换密码、手机登录
 | 
				
			||||||
const onTabsClick = () => {
 | 
					const onTabsClick = () => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1575,10 +1575,10 @@ postcss@^8.1.10:
 | 
				
			|||||||
    picocolors "^1.0.0"
 | 
					    picocolors "^1.0.0"
 | 
				
			||||||
    source-map-js "^1.0.1"
 | 
					    source-map-js "^1.0.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
postcss@^8.4.24:
 | 
					postcss@^8.4.26:
 | 
				
			||||||
  version "8.4.25"
 | 
					  version "8.4.27"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/postcss/-/postcss-8.4.25.tgz#4a133f5e379eda7f61e906c3b1aaa9b81292726f"
 | 
					  resolved "https://registry.npmmirror.com/postcss/-/postcss-8.4.27.tgz#234d7e4b72e34ba5a92c29636734349e0d9c3057"
 | 
				
			||||||
  integrity sha512-7taJ/8t2av0Z+sQEvNzCkpDynl0tX3uJMCODi6nT3PfASC7dYCWV9aQ+uiCf+KBD4SEFcu+GvJdGdwzQ6OSjCw==
 | 
					  integrity sha512-gY/ACJtJPSmUFPDCHtX78+01fHa64FaU4zaaWfuh1MhGJISufJAH4cun6k/8fwsHYeK4UQmENQK+tRLCFJE8JQ==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    nanoid "^3.3.6"
 | 
					    nanoid "^3.3.6"
 | 
				
			||||||
    picocolors "^1.0.0"
 | 
					    picocolors "^1.0.0"
 | 
				
			||||||
@@ -1855,13 +1855,13 @@ uri-js@^4.2.2:
 | 
				
			|||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    punycode "^2.1.0"
 | 
					    punycode "^2.1.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vite@^4.4.2:
 | 
					vite@^4.4.7:
 | 
				
			||||||
  version "4.4.2"
 | 
					  version "4.4.7"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/vite/-/vite-4.4.2.tgz#acd47de771c498aec80e4900f30133d9529b278a"
 | 
					  resolved "https://registry.npmmirror.com/vite/-/vite-4.4.7.tgz#71b8a37abaf8d50561aca084dbb77fa342824154"
 | 
				
			||||||
  integrity sha512-zUcsJN+UvdSyHhYa277UHhiJ3iq4hUBwHavOpsNUGsTgjBeoBlK8eDt+iT09pBq0h9/knhG/SPrZiM7cGmg7NA==
 | 
					  integrity sha512-6pYf9QJ1mHylfVh39HpuSfMPojPSKVxZvnclX1K1FyZ1PXDOcLBibdq5t1qxJSnL63ca8Wf4zts6mD8u8oc9Fw==
 | 
				
			||||||
  dependencies:
 | 
					  dependencies:
 | 
				
			||||||
    esbuild "^0.18.10"
 | 
					    esbuild "^0.18.10"
 | 
				
			||||||
    postcss "^8.4.24"
 | 
					    postcss "^8.4.26"
 | 
				
			||||||
    rollup "^3.25.2"
 | 
					    rollup "^3.25.2"
 | 
				
			||||||
  optionalDependencies:
 | 
					  optionalDependencies:
 | 
				
			||||||
    fsevents "~2.3.2"
 | 
					    fsevents "~2.3.2"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
package constant
 | 
					package consts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "time"
 | 
					import "time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3,7 +3,7 @@ package application
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"database/sql"
 | 
						"database/sql"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"mayfly-go/internal/constant"
 | 
						"mayfly-go/internal/common/consts"
 | 
				
			||||||
	"mayfly-go/internal/db/domain/entity"
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	"mayfly-go/internal/db/domain/repository"
 | 
						"mayfly-go/internal/db/domain/repository"
 | 
				
			||||||
	"mayfly-go/internal/machine/infrastructure/machine"
 | 
						"mayfly-go/internal/machine/infrastructure/machine"
 | 
				
			||||||
@@ -294,7 +294,7 @@ func (d *DbInstance) Close() {
 | 
				
			|||||||
//------------------------------------------------------------------------------
 | 
					//------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 客户端连接缓存,指定时间内没有访问则会被关闭, key为数据库实例id:数据库
 | 
					// 客户端连接缓存,指定时间内没有访问则会被关闭, key为数据库实例id:数据库
 | 
				
			||||||
var dbCache = cache.NewTimedCache(constant.DbConnExpireTime, 5*time.Second).
 | 
					var dbCache = cache.NewTimedCache(consts.DbConnExpireTime, 5*time.Second).
 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
						WithUpdateAccessTime(true).
 | 
				
			||||||
	OnEvicted(func(key any, value any) {
 | 
						OnEvicted(func(key any, value any) {
 | 
				
			||||||
		global.Log.Info(fmt.Sprintf("删除db连接缓存 id = %s", key))
 | 
							global.Log.Info(fmt.Sprintf("删除db连接缓存 id = %s", key))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package machine
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"mayfly-go/internal/constant"
 | 
						"mayfly-go/internal/common/consts"
 | 
				
			||||||
	"mayfly-go/internal/machine/domain/entity"
 | 
						"mayfly-go/internal/machine/domain/entity"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/cache"
 | 
						"mayfly-go/pkg/cache"
 | 
				
			||||||
@@ -139,7 +139,7 @@ func (c *Cli) GetMachine() *Info {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 机器客户端连接缓存,指定时间内没有访问则会被关闭
 | 
					// 机器客户端连接缓存,指定时间内没有访问则会被关闭
 | 
				
			||||||
var cliCache = cache.NewTimedCache(constant.MachineConnExpireTime, 5*time.Second).
 | 
					var cliCache = cache.NewTimedCache(consts.MachineConnExpireTime, 5*time.Second).
 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
						WithUpdateAccessTime(true).
 | 
				
			||||||
	OnEvicted(func(_, value any) {
 | 
						OnEvicted(func(_, value any) {
 | 
				
			||||||
		value.(*Cli).Close()
 | 
							value.(*Cli).Close()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package application
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"mayfly-go/internal/constant"
 | 
						"mayfly-go/internal/common/consts"
 | 
				
			||||||
	machineapp "mayfly-go/internal/machine/application"
 | 
						machineapp "mayfly-go/internal/machine/application"
 | 
				
			||||||
	"mayfly-go/internal/machine/infrastructure/machine"
 | 
						"mayfly-go/internal/machine/infrastructure/machine"
 | 
				
			||||||
	"mayfly-go/internal/mongo/domain/entity"
 | 
						"mayfly-go/internal/mongo/domain/entity"
 | 
				
			||||||
@@ -101,7 +101,7 @@ func (d *mongoAppImpl) GetMongoCli(id uint64) *mongo.Client {
 | 
				
			|||||||
// -----------------------------------------------------------
 | 
					// -----------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// mongo客户端连接缓存,指定时间内没有访问则会被关闭
 | 
					// mongo客户端连接缓存,指定时间内没有访问则会被关闭
 | 
				
			||||||
var mongoCliCache = cache.NewTimedCache(constant.MongoConnExpireTime, 5*time.Second).
 | 
					var mongoCliCache = cache.NewTimedCache(consts.MongoConnExpireTime, 5*time.Second).
 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
						WithUpdateAccessTime(true).
 | 
				
			||||||
	OnEvicted(func(key any, value any) {
 | 
						OnEvicted(func(key any, value any) {
 | 
				
			||||||
		global.Log.Info("删除mongo连接缓存: id = ", key)
 | 
							global.Log.Info("删除mongo连接缓存: id = ", key)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package application
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"mayfly-go/internal/constant"
 | 
						"mayfly-go/internal/common/consts"
 | 
				
			||||||
	machineapp "mayfly-go/internal/machine/application"
 | 
						machineapp "mayfly-go/internal/machine/application"
 | 
				
			||||||
	"mayfly-go/internal/machine/infrastructure/machine"
 | 
						"mayfly-go/internal/machine/infrastructure/machine"
 | 
				
			||||||
	"mayfly-go/internal/redis/domain/entity"
 | 
						"mayfly-go/internal/redis/domain/entity"
 | 
				
			||||||
@@ -254,7 +254,7 @@ func getRedisDialer(machineId int) func(ctx context.Context, network, addr strin
 | 
				
			|||||||
//------------------------------------------------------------------------------
 | 
					//------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// redis客户端连接缓存,指定时间内没有访问则会被关闭
 | 
					// redis客户端连接缓存,指定时间内没有访问则会被关闭
 | 
				
			||||||
var redisCache = cache.NewTimedCache(constant.RedisConnExpireTime, 5*time.Second).
 | 
					var redisCache = cache.NewTimedCache(consts.RedisConnExpireTime, 5*time.Second).
 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
						WithUpdateAccessTime(true).
 | 
				
			||||||
	OnEvicted(func(key any, value any) {
 | 
						OnEvicted(func(key any, value any) {
 | 
				
			||||||
		global.Log.Info(fmt.Sprintf("删除redis连接缓存 id = %s", key))
 | 
							global.Log.Info(fmt.Sprintf("删除redis连接缓存 id = %s", key))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,5 +53,6 @@ func (c *Config) Oauth2Config(rc *req.Ctx) {
 | 
				
			|||||||
	oauth2LoginConfig := c.ConfigApp.GetConfig(entity.ConfigKeyOauth2Login).ToOauth2Login()
 | 
						oauth2LoginConfig := c.ConfigApp.GetConfig(entity.ConfigKeyOauth2Login).ToOauth2Login()
 | 
				
			||||||
	rc.ResData = map[string]any{
 | 
						rc.ResData = map[string]any{
 | 
				
			||||||
		"enable": oauth2LoginConfig.Enable,
 | 
							"enable": oauth2LoginConfig.Enable,
 | 
				
			||||||
 | 
							"name":   oauth2LoginConfig.Name,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,7 +33,7 @@ func (c *Config) BoolValue(defaultValue bool) bool {
 | 
				
			|||||||
	if c.Id == 0 {
 | 
						if c.Id == 0 {
 | 
				
			||||||
		return defaultValue
 | 
							return defaultValue
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return convertBool(c.Value, defaultValue)
 | 
						return c.ConvBool(c.Value, defaultValue)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 值返回json map
 | 
					// 值返回json map
 | 
				
			||||||
@@ -52,7 +52,7 @@ func (c *Config) IntValue(defaultValue int) int {
 | 
				
			|||||||
	if c.Id == 0 {
 | 
						if c.Id == 0 {
 | 
				
			||||||
		return defaultValue
 | 
							return defaultValue
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return convertInt(c.Value, defaultValue)
 | 
						return c.ConvInt(c.Value, defaultValue)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type AccountLoginSecurity struct {
 | 
					type AccountLoginSecurity struct {
 | 
				
			||||||
@@ -67,10 +67,10 @@ type AccountLoginSecurity struct {
 | 
				
			|||||||
func (c *Config) ToAccountLoginSecurity() *AccountLoginSecurity {
 | 
					func (c *Config) ToAccountLoginSecurity() *AccountLoginSecurity {
 | 
				
			||||||
	jm := c.GetJsonMap()
 | 
						jm := c.GetJsonMap()
 | 
				
			||||||
	als := new(AccountLoginSecurity)
 | 
						als := new(AccountLoginSecurity)
 | 
				
			||||||
	als.UseCaptcha = convertBool(jm["useCaptcha"], true)
 | 
						als.UseCaptcha = c.ConvBool(jm["useCaptcha"], true)
 | 
				
			||||||
	als.UseOtp = convertBool(jm["useOtp"], false)
 | 
						als.UseOtp = c.ConvBool(jm["useOtp"], false)
 | 
				
			||||||
	als.LoginFailCount = convertInt(jm["loginFailCount"], 5)
 | 
						als.LoginFailCount = c.ConvInt(jm["loginFailCount"], 5)
 | 
				
			||||||
	als.LoginFailMin = convertInt(jm["loginFailMin"], 10)
 | 
						als.LoginFailMin = c.ConvInt(jm["loginFailMin"], 10)
 | 
				
			||||||
	otpIssuer := jm["otpIssuer"]
 | 
						otpIssuer := jm["otpIssuer"]
 | 
				
			||||||
	if otpIssuer == "" {
 | 
						if otpIssuer == "" {
 | 
				
			||||||
		otpIssuer = "mayfly-go"
 | 
							otpIssuer = "mayfly-go"
 | 
				
			||||||
@@ -81,6 +81,7 @@ func (c *Config) ToAccountLoginSecurity() *AccountLoginSecurity {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type ConfigOauth2Login struct {
 | 
					type ConfigOauth2Login struct {
 | 
				
			||||||
	Enable           bool // 是否启用
 | 
						Enable           bool // 是否启用
 | 
				
			||||||
 | 
						Name             string
 | 
				
			||||||
	ClientId         string `json:"clientId"`
 | 
						ClientId         string `json:"clientId"`
 | 
				
			||||||
	ClientSecret     string `json:"clientSecret"`
 | 
						ClientSecret     string `json:"clientSecret"`
 | 
				
			||||||
	AuthorizationURL string `json:"authorizationURL"`
 | 
						AuthorizationURL string `json:"authorizationURL"`
 | 
				
			||||||
@@ -96,7 +97,8 @@ type ConfigOauth2Login struct {
 | 
				
			|||||||
func (c *Config) ToOauth2Login() *ConfigOauth2Login {
 | 
					func (c *Config) ToOauth2Login() *ConfigOauth2Login {
 | 
				
			||||||
	jm := c.GetJsonMap()
 | 
						jm := c.GetJsonMap()
 | 
				
			||||||
	ol := new(ConfigOauth2Login)
 | 
						ol := new(ConfigOauth2Login)
 | 
				
			||||||
	ol.Enable = convertBool(jm["enable"], false)
 | 
						ol.Enable = c.ConvBool(jm["enable"], false)
 | 
				
			||||||
 | 
						ol.Name = jm["name"]
 | 
				
			||||||
	ol.ClientId = jm["clientId"]
 | 
						ol.ClientId = jm["clientId"]
 | 
				
			||||||
	ol.ClientSecret = jm["clientSecret"]
 | 
						ol.ClientSecret = jm["clientSecret"]
 | 
				
			||||||
	ol.AuthorizationURL = jm["authorizationURL"]
 | 
						ol.AuthorizationURL = jm["authorizationURL"]
 | 
				
			||||||
@@ -105,12 +107,12 @@ func (c *Config) ToOauth2Login() *ConfigOauth2Login {
 | 
				
			|||||||
	ol.Scopes = jm["scopes"]
 | 
						ol.Scopes = jm["scopes"]
 | 
				
			||||||
	ol.ResourceURL = jm["resourceURL"]
 | 
						ol.ResourceURL = jm["resourceURL"]
 | 
				
			||||||
	ol.UserIdentifier = jm["userIdentifier"]
 | 
						ol.UserIdentifier = jm["userIdentifier"]
 | 
				
			||||||
	ol.AutoRegister = convertBool(jm["autoRegister"], true)
 | 
						ol.AutoRegister = c.ConvBool(jm["autoRegister"], true)
 | 
				
			||||||
	return ol
 | 
						return ol
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 转换配置中的值为bool类型(默认"1"或"true"为true,其他为false)
 | 
					// 转换配置中的值为bool类型(默认"1"或"true"为true,其他为false)
 | 
				
			||||||
func convertBool(value string, defaultValue bool) bool {
 | 
					func (c *Config) ConvBool(value string, defaultValue bool) bool {
 | 
				
			||||||
	if value == "" {
 | 
						if value == "" {
 | 
				
			||||||
		return defaultValue
 | 
							return defaultValue
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -118,7 +120,7 @@ func convertBool(value string, defaultValue bool) bool {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 转换配置值中的值为int
 | 
					// 转换配置值中的值为int
 | 
				
			||||||
func convertInt(value string, defaultValue int) int {
 | 
					func (c *Config) ConvInt(value string, defaultValue int) int {
 | 
				
			||||||
	if value == "" {
 | 
						if value == "" {
 | 
				
			||||||
		return defaultValue
 | 
							return defaultValue
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -439,7 +439,7 @@ CREATE TABLE `t_sys_config` (
 | 
				
			|||||||
-- ----------------------------
 | 
					-- ----------------------------
 | 
				
			||||||
BEGIN;
 | 
					BEGIN;
 | 
				
			||||||
INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier) VALUES('账号登录安全设置', 'AccountLoginSecurity', '[{"name":"登录验证码","model":"useCaptcha","placeholder":"是否启用登录验证码","options":"true,false"},{"name":"双因素校验(OTP)","model":"useOtp","placeholder":"是否启用双因素(OTP)校验","options":"true,false"},{"name":"OTP签发人","model":"otpIssuer","placeholder":"otp签发人"},{"name":"允许失败次数","model":"loginFailCount","placeholder":"登录失败n次后禁止登录"},{"name":"禁止登录时间","model":"loginFailMin","placeholder":"登录失败指定次数后禁止m分钟内再次登录"}]', '{"useCaptcha":"true","useOtp":"false","loginFailCount":"5","loginFailMin":"10","otpIssuer":"mayfly-go"}', '系统账号登录相关安全设置', '2023-06-17 11:02:11', 1, 'admin', '2023-06-17 14:18:07', 1, 'admin');
 | 
					INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier) VALUES('账号登录安全设置', 'AccountLoginSecurity', '[{"name":"登录验证码","model":"useCaptcha","placeholder":"是否启用登录验证码","options":"true,false"},{"name":"双因素校验(OTP)","model":"useOtp","placeholder":"是否启用双因素(OTP)校验","options":"true,false"},{"name":"OTP签发人","model":"otpIssuer","placeholder":"otp签发人"},{"name":"允许失败次数","model":"loginFailCount","placeholder":"登录失败n次后禁止登录"},{"name":"禁止登录时间","model":"loginFailMin","placeholder":"登录失败指定次数后禁止m分钟内再次登录"}]', '{"useCaptcha":"true","useOtp":"false","loginFailCount":"5","loginFailMin":"10","otpIssuer":"mayfly-go"}', '系统账号登录相关安全设置', '2023-06-17 11:02:11', 1, 'admin', '2023-06-17 14:18:07', 1, 'admin');
 | 
				
			||||||
INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier, is_deleted, delete_time) VALUES('oauth2登录配置', 'Oauth2Login', '[{"name":"是否启用","model":"enable","placeholder":"是否启用oauth2登录","options":"true,false"},{"name":"Client ID","model":"clientId","placeholder":"Client ID"},{"name":"Client Secret","model":"clientSecret","placeholder":"Client Secret"},{"name":"Authorization URL","model":"authorizationURL","placeholder":"Authorization URL"},{"name":"AccessToken URL","model":"accessTokenURL","placeholder":"AccessToken URL"},{"name":"Redirect URL","model":"redirectURL","placeholder":"本系统地址"},{"name":"Scopes","model":"scopes","placeholder":"Scopes"},{"name":"Resource URL","model":"resourceURL","placeholder":"获取用户信息资源地址"},{"name":"UserIdentifier","model":"userIdentifier","placeholder":"用户唯一标识字段;格式为type:fieldPath(string:username)"},{"name":"是否自动注册","model":"autoRegister","placeholder":"","options":"true,false"}]', '', 'oauth2登录相关配置信息', '2023-07-22 13:58:51', 1, 'admin', '2023-07-22 19:34:37', 1, 'admin', 0, NULL);
 | 
					INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier, is_deleted, delete_time) VALUES('oauth2登录配置', 'Oauth2Login', '[{"name":"是否启用","model":"enable","placeholder":"是否启用oauth2登录","options":"true,false"},{"name":"名称","model":"name","placeholder":"oauth2名称"},{"name":"Client ID","model":"clientId","placeholder":"Client ID"},{"name":"Client Secret","model":"clientSecret","placeholder":"Client Secret"},{"name":"Authorization URL","model":"authorizationURL","placeholder":"Authorization URL"},{"name":"AccessToken URL","model":"accessTokenURL","placeholder":"AccessToken URL"},{"name":"Redirect URL","model":"redirectURL","placeholder":"本系统地址"},{"name":"Scopes","model":"scopes","placeholder":"Scopes"},{"name":"Resource URL","model":"resourceURL","placeholder":"获取用户信息资源地址"},{"name":"UserIdentifier","model":"userIdentifier","placeholder":"用户唯一标识字段;格式为type:fieldPath(string:username)"},{"name":"是否自动注册","model":"autoRegister","placeholder":"","options":"true,false"}]', '', 'oauth2登录相关配置信息', '2023-07-22 13:58:51', 1, 'admin', '2023-07-22 19:34:37', 1, 'admin', 0, NULL);
 | 
				
			||||||
INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier)VALUES ('是否启用水印', 'UseWartermark', NULL, '1', '1: 启用、0: 不启用', '2022-08-25 23:36:35', 1, 'admin', '2022-08-26 10:02:52', 1, 'admin');
 | 
					INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier)VALUES ('是否启用水印', 'UseWartermark', NULL, '1', '1: 启用、0: 不启用', '2022-08-25 23:36:35', 1, 'admin', '2022-08-26 10:02:52', 1, 'admin');
 | 
				
			||||||
INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier)VALUES ('数据库查询最大结果集', 'DbQueryMaxCount', '[]', '200', '允许sql查询的最大结果集数。注: 0=不限制', '2023-02-11 14:29:03', 1, 'admin', '2023-02-11 14:40:56', 1, 'admin');
 | 
					INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier)VALUES ('数据库查询最大结果集', 'DbQueryMaxCount', '[]', '200', '允许sql查询的最大结果集数。注: 0=不限制', '2023-02-11 14:29:03', 1, 'admin', '2023-02-11 14:40:56', 1, 'admin');
 | 
				
			||||||
INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier)VALUES ('数据库是否记录查询SQL', 'DbSaveQuerySQL', '[]', '0', '1: 记录、0:不记录', '2023-02-11 16:07:14', 1, 'admin', '2023-02-11 16:44:17', 1, 'admin');
 | 
					INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier)VALUES ('数据库是否记录查询SQL', 'DbSaveQuerySQL', '[]', '0', '1: 记录、0:不记录', '2023-02-11 16:07:14', 1, 'admin', '2023-02-11 16:44:17', 1, 'admin');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,5 @@
 | 
				
			|||||||
package collx
 | 
					package collx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "fmt"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 数组比较
 | 
					// 数组比较
 | 
				
			||||||
// 依次返回,新增值,删除值,以及不变值
 | 
					// 依次返回,新增值,删除值,以及不变值
 | 
				
			||||||
func ArrayCompare[T any](newArr []T, oldArr []T, compareFun func(T, T) bool) ([]T, []T, []T) {
 | 
					func ArrayCompare[T any](newArr []T, oldArr []T, compareFun func(T, T) bool) ([]T, []T, []T) {
 | 
				
			||||||
@@ -38,18 +36,6 @@ func ArrayCompare[T any](newArr []T, oldArr []T, compareFun func(T, T) bool) ([]
 | 
				
			|||||||
	return newArr, oldArr, unmodifierValue
 | 
						return newArr, oldArr, unmodifierValue
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type NumT interface {
 | 
					 | 
				
			||||||
	~int | ~int32 | ~uint64
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func NumberArr2StrArr[T NumT](numberArr []T) []string {
 | 
					 | 
				
			||||||
	strArr := make([]string, 0)
 | 
					 | 
				
			||||||
	for _, v := range numberArr {
 | 
					 | 
				
			||||||
		strArr = append(strArr, fmt.Sprintf("%d", v))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return strArr
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 判断数组中是否含有指定元素
 | 
					// 判断数组中是否含有指定元素
 | 
				
			||||||
func ArrayContains[T comparable](arr []T, el T) bool {
 | 
					func ArrayContains[T comparable](arr []T, el T) bool {
 | 
				
			||||||
	for _, v := range arr {
 | 
						for _, v := range arr {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user