diff --git a/.caches/master.jpg b/.caches/master.jpg new file mode 100644 index 0000000..891c664 Binary files /dev/null and b/.caches/master.jpg differ diff --git a/.caches/thumb.png b/.caches/thumb.png new file mode 100644 index 0000000..25baa74 Binary files /dev/null and b/.caches/thumb.png differ diff --git a/api/api.go b/api/api.go index 9520d9e..869a6d5 100644 --- a/api/api.go +++ b/api/api.go @@ -1,10 +1,14 @@ package api -import "schisandra-cloud-album/api/auth_api" +import ( + "schisandra-cloud-album/api/auth_api" + //"schisandra-cloud-album/api/captcha_api" +) // Apis 统一导出的api type Apis struct { AuthApi auth_api.AuthAPI + //CaptchaAPI captcha_api.CaptchaAPI } // Api new函数实例化,实例化完成后会返回结构体地指针类型 diff --git a/api/auth_api/auth_api.go b/api/auth_api/auth_api.go index 4d2fd77..4c972ba 100644 --- a/api/auth_api/auth_api.go +++ b/api/auth_api/auth_api.go @@ -2,7 +2,9 @@ package auth_api import ( "github.com/gin-gonic/gin" + "reflect" "schisandra-cloud-album/common/result" + "schisandra-cloud-album/model" "schisandra-cloud-album/service" ) @@ -17,3 +19,67 @@ func (AuthAPI) GetUserList(c *gin.Context) { userList := authService.GetUserList() result.OkWithData(userList, c) } + +// QueryUserByUsername +// @Summary 根据用户名查询用户 +// @Tags 鉴权模块 +// @Param username query string true "用户名" +// @Success 200 {string} json +// @Router /api/auth/user/query_by_username [get] +func (AuthAPI) QueryUserByUsername(c *gin.Context) { + username := c.Query("username") + user := authService.QueryUserByName(username) + if reflect.DeepEqual(user, model.ScaAuthUser{}) { + result.FailWithMessage("用户不存在!", c) + return + } + result.OkWithData(user, c) +} + +// QueryUserByUuid +// @Summary 根据uuid查询用户 +// @Tags 鉴权模块 +// @Param uuid query string true "用户uuid" +// @Success 200 {string} json +// @Router /api/auth/user/query_by_uuid [get] +func (AuthAPI) QueryUserByUuid(c *gin.Context) { + uuid := c.Query("uuid") + user := authService.QueryUserByUuid(uuid) + if reflect.DeepEqual(user, model.ScaAuthUser{}) { + result.FailWithMessage("用户不存在!", c) + return + } + result.OkWithData(user, c) +} + +// DeleteUser 删除用户 +// @Summary 删除用户 +// @Tags 鉴权模块 +// @Param uuid query string true "用户uuid" +// @Success 200 {string} json +// @Router /api/auth/user/delete [delete] +func (AuthAPI) DeleteUser(c *gin.Context) { + uuid := c.Query("uuid") + err := authService.DeleteUser(uuid) + if err != nil { + result.FailWithMessage("用户删除失败!", c) + return + } + result.OkWithMessage("用户删除成功!", c) +} + +// QueryUserByPhone 根据手机号查询用户 +// @Summary 根据手机号查询用户 +// @Tags 鉴权模块 +// @Param phone query string true "手机号" +// @Success 200 {string} json +// @Router /api/auth/user/query_by_phone [get] +func (AuthAPI) QueryUserByPhone(c *gin.Context) { + phone := c.Query("phone") + user := authService.QueryUserByPhone(phone) + if reflect.DeepEqual(user, model.ScaAuthUser{}) { + result.FailWithMessage("用户不存在!", c) + return + } + result.OkWithData(user, c) +} diff --git a/api/auth_api/enter.go b/api/auth_api/index.go similarity index 100% rename from api/auth_api/enter.go rename to api/auth_api/index.go diff --git a/api/captcha_api/captcha_api.go b/api/captcha_api/captcha_api.go new file mode 100644 index 0000000..2598b43 --- /dev/null +++ b/api/captcha_api/captcha_api.go @@ -0,0 +1,40 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/wenlng/go-captcha/v2/base/option" + "github.com/wenlng/go-captcha/v2/click" +) + +var textCapt click.Captcha + +func init() { + +} + +func main() { + captData, err := textCapt.Generate() + if err != nil { + log.Fatalln(err) + } + + dotData := captData.GetData() + if dotData == nil { + log.Fatalln(">>>>> generate err") + } + + dots, _ := json.Marshal(dotData) + fmt.Println(">>>>> ", string(dots)) + + err = captData.GetMasterImage().SaveToFile("./.caches/master.jpg", option.QualityNone) + if err != nil { + fmt.Println(err) + } + err = captData.GetThumbImage().SaveToFile("./.caches/thumb.png") + if err != nil { + fmt.Println(err) + } +} diff --git a/api/captcha_api/index.go b/api/captcha_api/index.go new file mode 100644 index 0000000..fcaa46d --- /dev/null +++ b/api/captcha_api/index.go @@ -0,0 +1,3 @@ +package main + +type CaptchaAPI struct{} diff --git a/cmd/gen/gen.go b/cmd/gen/gen.go index 2fa6ee3..ee48771 100644 --- a/cmd/gen/gen.go +++ b/cmd/gen/gen.go @@ -99,19 +99,19 @@ func initInfo() (db *gorm.DB, g *gen.Generator, fieldOpts []gen.ModelOpt) { // 将非默认字段名的字段定义为自动时间戳和软删除字段; // 自动时间戳默认字段名为:`updated_at`、`created_at, 表字段数据类型为: INT 或 DATETIME // 软删除默认字段名为:`deleted_at`, 表字段数据类型为: DATETIME - autoUpdateTimeField := gen.FieldGORMTag("update_time", func(tag field.GormTag) field.GormTag { - return tag.Append("autoUpdateTime") - }) - autoCreateTimeField := gen.FieldGORMTag("created_time", func(tag field.GormTag) field.GormTag { - return tag.Append("autoCreateTime") - }) + //autoUpdateTimeField := gen.FieldGORMTag("update_time", func(tag field.GormTag) field.GormTag { + // return tag.Append("autoUpdateTime") + //}) + //autoCreateTimeField := gen.FieldGORMTag("created_time", func(tag field.GormTag) field.GormTag { + // return tag.Append("autoCreateTime") + //}) //softDeleteField := gen.FieldType("deletedAt", "gorm.DeletedAt") // 模型自定义选项组 fieldOpts = []gen.ModelOpt{ // jsonField, - autoCreateTimeField, - autoUpdateTimeField, + //autoCreateTimeField, + //autoUpdateTimeField, //softDeleteField, } diff --git a/common/enum/deleted.go b/common/enum/deleted.go new file mode 100644 index 0000000..0cc0112 --- /dev/null +++ b/common/enum/deleted.go @@ -0,0 +1,6 @@ +package enum + +var ( + UNDELETED int64 = 0 + DELETED int64 = 1 +) diff --git a/core/captcha.go b/core/captcha.go new file mode 100644 index 0000000..291e7a9 --- /dev/null +++ b/core/captcha.go @@ -0,0 +1,100 @@ +package core + +import ( + "github.com/golang/freetype/truetype" + "github.com/wenlng/go-captcha-assets/bindata/chars" + "github.com/wenlng/go-captcha-assets/resources/fonts/fzshengsksjw" + "github.com/wenlng/go-captcha-assets/resources/images" + "github.com/wenlng/go-captcha-assets/resources/tiles" + "github.com/wenlng/go-captcha/v2/base/option" + "github.com/wenlng/go-captcha/v2/click" + "github.com/wenlng/go-captcha/v2/rotate" + "github.com/wenlng/go-captcha/v2/slide" + "log" + "schisandra-cloud-album/global" +) + +// initTextCaptcha 初始化点选验证码 +func initTextCaptcha() { + builder := click.NewBuilder() + + // fonts + fonts, err := fzshengsksjw.GetFont() + if err != nil { + global.LOG.Fatalln(err) + } + + // background images + imgs, err := images.GetImages() + if err != nil { + global.LOG.Fatalln(err) + } + + builder.SetResources( + click.WithChars(chars.GetChineseChars()), + click.WithFonts([]*truetype.Font{fonts}), + click.WithBackgrounds(imgs), + ) + global.TextCaptcha = builder.Make() +} + +// initSlideCaptcha 初始化滑动验证码 +func initsSlideCaptcha() { + builder := slide.NewBuilder( + //slide.WithGenGraphNumber(2), + slide.WithEnableGraphVerticalRandom(true), + ) + + // background images + imgs, err := images.GetImages() + if err != nil { + log.Fatalln(err) + } + + graphs, err := tiles.GetTiles() + if err != nil { + log.Fatalln(err) + } + + var newGraphs = make([]*slide.GraphImage, 0, len(graphs)) + for i := 0; i < len(graphs); i++ { + graph := graphs[i] + newGraphs = append(newGraphs, &slide.GraphImage{ + OverlayImage: graph.OverlayImage, + MaskImage: graph.MaskImage, + ShadowImage: graph.ShadowImage, + }) + } + + // set resources + builder.SetResources( + slide.WithGraphImages(newGraphs), + slide.WithBackgrounds(imgs), + ) + + global.SlideCaptcha = builder.Make() +} + +// initRotateCaptcha 初始化旋转验证码 +func initRotateCaptcha() { + builder := rotate.NewBuilder(rotate.WithRangeAnglePos([]option.RangeVal{ + {Min: 20, Max: 330}, + })) + + // background images + imgs, err := images.GetImages() + if err != nil { + log.Fatalln(err) + } + + // set resources + builder.SetResources( + rotate.WithImages(imgs), + ) + + global.RotateCaptcha = builder.Make() +} + +func InitCaptcha() { + initTextCaptcha() +} diff --git a/core/gorm.go b/core/gorm.go index 44928f8..72908b2 100644 --- a/core/gorm.go +++ b/core/gorm.go @@ -26,19 +26,22 @@ func MySQlConnect() *gorm.DB { mysqlLogger = logger.New( log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{ - SlowThreshold: time.Second, //慢sql日志 - LogLevel: logger.Info, //级别 - Colorful: true, //颜色 + SlowThreshold: time.Second, //慢sql日志 + LogLevel: logger.Info, //级别 + Colorful: true, //颜色 + IgnoreRecordNotFoundError: true, //忽略RecordNotFoundError + ParameterizedQueries: true, //格式化SQL语句 }) } else { mysqlLogger = logger.New( log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{ - SlowThreshold: time.Second, //慢sql日志 - LogLevel: logger.Error, //级别 - Colorful: true, //颜色 - + SlowThreshold: time.Second, //慢sql日志 + LogLevel: logger.Error, //级别 + Colorful: true, //颜色 + IgnoreRecordNotFoundError: true, //忽略RecordNotFoundError + ParameterizedQueries: true, //格式化SQL语句 }) } diff --git a/core/logrus.go b/core/logrus.go index 7d6c1ec..60480c2 100644 --- a/core/logrus.go +++ b/core/logrus.go @@ -63,11 +63,11 @@ func InitLogger() *logrus.Logger { } newLog.SetLevel(level) //设置日志级别 global.LOG = newLog - InitDefaultLogger() + initDefaultLogger() return newLog } -func InitDefaultLogger() { +func initDefaultLogger() { //全局日志 logrus.SetOutput(os.Stdout) //设置输出类型 logrus.SetReportCaller(global.CONFIG.Logger.ShowLine) //设置是否显示函数名和行号 diff --git a/docs/docs.go b/docs/docs.go index ef997ed..659cf1e 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -30,6 +30,106 @@ const docTemplate = `{ } } } + }, + "/api/auth/user/delete": { + "delete": { + "tags": [ + "鉴权模块" + ], + "summary": "删除用户", + "parameters": [ + { + "type": "string", + "description": "用户uuid", + "name": "uuid", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/auth/user/query_by_phone": { + "get": { + "tags": [ + "鉴权模块" + ], + "summary": "根据手机号查询用户", + "parameters": [ + { + "type": "string", + "description": "手机号", + "name": "phone", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/auth/user/query_by_username": { + "get": { + "tags": [ + "鉴权模块" + ], + "summary": "根据用户名查询用户", + "parameters": [ + { + "type": "string", + "description": "用户名", + "name": "username", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/auth/user/query_by_uuid": { + "get": { + "tags": [ + "鉴权模块" + ], + "summary": "根据uuid查询用户", + "parameters": [ + { + "type": "string", + "description": "用户uuid", + "name": "uuid", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } } } }` diff --git a/docs/swagger.json b/docs/swagger.json index fc2e332..5aeda8f 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -19,6 +19,106 @@ } } } + }, + "/api/auth/user/delete": { + "delete": { + "tags": [ + "鉴权模块" + ], + "summary": "删除用户", + "parameters": [ + { + "type": "string", + "description": "用户uuid", + "name": "uuid", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/auth/user/query_by_phone": { + "get": { + "tags": [ + "鉴权模块" + ], + "summary": "根据手机号查询用户", + "parameters": [ + { + "type": "string", + "description": "手机号", + "name": "phone", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/auth/user/query_by_username": { + "get": { + "tags": [ + "鉴权模块" + ], + "summary": "根据用户名查询用户", + "parameters": [ + { + "type": "string", + "description": "用户名", + "name": "username", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/auth/user/query_by_uuid": { + "get": { + "tags": [ + "鉴权模块" + ], + "summary": "根据uuid查询用户", + "parameters": [ + { + "type": "string", + "description": "用户uuid", + "name": "uuid", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index fee9e38..07df8de 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -11,4 +11,68 @@ paths: summary: 获取所有用户列表 tags: - 鉴权模块 + /api/auth/user/delete: + delete: + parameters: + - description: 用户uuid + in: query + name: uuid + required: true + type: string + responses: + "200": + description: OK + schema: + type: string + summary: 删除用户 + tags: + - 鉴权模块 + /api/auth/user/query_by_phone: + get: + parameters: + - description: 手机号 + in: query + name: phone + required: true + type: string + responses: + "200": + description: OK + schema: + type: string + summary: 根据手机号查询用户 + tags: + - 鉴权模块 + /api/auth/user/query_by_username: + get: + parameters: + - description: 用户名 + in: query + name: username + required: true + type: string + responses: + "200": + description: OK + schema: + type: string + summary: 根据用户名查询用户 + tags: + - 鉴权模块 + /api/auth/user/query_by_uuid: + get: + parameters: + - description: 用户uuid + in: query + name: uuid + required: true + type: string + responses: + "200": + description: OK + schema: + type: string + summary: 根据uuid查询用户 + tags: + - 鉴权模块 swagger: "2.0" diff --git a/global/global.go b/global/global.go index 46cb640..aed262d 100644 --- a/global/global.go +++ b/global/global.go @@ -2,13 +2,19 @@ package global import ( "github.com/sirupsen/logrus" + "github.com/wenlng/go-captcha/v2/click" + "github.com/wenlng/go-captcha/v2/rotate" + "github.com/wenlng/go-captcha/v2/slide" "gorm.io/gorm" "schisandra-cloud-album/config" ) // Config 全局配置文件 var ( - CONFIG *config.Config - DB *gorm.DB - LOG *logrus.Logger + CONFIG *config.Config + DB *gorm.DB + LOG *logrus.Logger + TextCaptcha click.Captcha + SlideCaptcha slide.Captcha + RotateCaptcha rotate.Captcha ) diff --git a/go.mod b/go.mod index 8e4039f..f0cc483 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/cloudwego/iasm v0.2.0 // indirect github.com/gabriel-vasile/mimetype v1.4.5 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/jsonreference v0.21.0 // indirect github.com/go-openapi/spec v0.21.0 // indirect @@ -32,6 +33,7 @@ require ( github.com/go-playground/validator/v10 v10.22.0 // indirect github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/goccy/go-json v0.10.3 // indirect + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -45,8 +47,11 @@ require ( github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect + github.com/wenlng/go-captcha-assets v1.0.1 // indirect + github.com/wenlng/go-captcha/v2 v2.0.0 // indirect golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.25.0 // indirect + golang.org/x/image v0.18.0 // indirect golang.org/x/mod v0.19.0 // indirect golang.org/x/net v0.27.0 // indirect golang.org/x/sync v0.7.0 // indirect diff --git a/go.sum b/go.sum index 97bcc73..085b184 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE= +github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo= github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= @@ -47,6 +49,8 @@ github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0kt github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -120,6 +124,10 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/wenlng/go-captcha-assets v1.0.1 h1:AdjRFMKmadPRWRTv0XEYfjDvcaayZ2yExITDvlK/7bk= +github.com/wenlng/go-captcha-assets v1.0.1/go.mod h1:yQqc7rRbxgLCg+tWtVp+7Y317D1wIZDan/yIwt8wSac= +github.com/wenlng/go-captcha/v2 v2.0.0 h1:7Z4Zy09SIHgvj9e8ZxP4VhYOwg7IHt8kGlVrE5jP5Z8= +github.com/wenlng/go-captcha/v2 v2.0.0/go.mod h1:5hac1em3uXoyC5ipZ0xFv9umNM/waQvYAQdr0cx/h34= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= @@ -127,17 +135,23 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs= +golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= +golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -157,11 +171,13 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go index f8d4495..b8649c6 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ func main() { core.InitConfig() core.InitLogger() core.InitGorm() + core.InitCaptcha() // 命令行参数绑定 option := cmd.Parse() if cmd.IsStopWeb(&option) { diff --git a/model/sca_auth_permission.gen.go b/model/sca_auth_permission.gen.go index 0ec2be6..b1b9588 100644 --- a/model/sca_auth_permission.gen.go +++ b/model/sca_auth_permission.gen.go @@ -12,21 +12,21 @@ const TableNameScaAuthPermission = "sca_auth_permission" // ScaAuthPermission 权限表 type ScaAuthPermission struct { - ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID - PermissionName *string `gorm:"column:permission_name;type:varchar(64);comment:权限名称" json:"permission_name"` // 权限名称 - ParentID *int64 `gorm:"column:parent_id;type:bigint(20);comment:父ID" json:"parent_id"` // 父ID - Type *int64 `gorm:"column:type;type:tinyint(4);comment:类型 0 菜单 1 目录 2 按钮 -1其他" json:"type"` // 类型 0 菜单 1 目录 2 按钮 -1其他 - Path *string `gorm:"column:path;type:varchar(255);comment:路径" json:"path"` // 路径 - Status *int64 `gorm:"column:status;type:tinyint(4);comment:状态 0 启用 1 停用" json:"status"` // 状态 0 启用 1 停用 - Icon *string `gorm:"column:icon;type:varchar(128);comment:图标" json:"icon"` // 图标 - PermissionKey *string `gorm:"column:permission_key;type:varchar(64);comment:权限关键字" json:"permission_key"` // 权限关键字 - Order *int64 `gorm:"column:order;type:int(11);comment:排序" json:"order"` // 排序 - CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 - CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间" json:"created_time"` // 创建时间 - UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 - UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间" json:"update_time"` // 更新时间 - Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 - Remark *string `gorm:"column:remark;type:varchar(255);comment:备注 描述" json:"remark"` // 备注 描述 + ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID + PermissionName *string `gorm:"column:permission_name;type:varchar(64);comment:权限名称" json:"permission_name"` // 权限名称 + ParentID *int64 `gorm:"column:parent_id;type:bigint(20);comment:父ID" json:"parent_id"` // 父ID + Type *int64 `gorm:"column:type;type:tinyint(4);comment:类型 0 菜单 1 目录 2 按钮 -1其他" json:"type"` // 类型 0 菜单 1 目录 2 按钮 -1其他 + Path *string `gorm:"column:path;type:varchar(255);comment:路径" json:"path"` // 路径 + Status *int64 `gorm:"column:status;type:tinyint(4);comment:状态 0 启用 1 停用" json:"status"` // 状态 0 启用 1 停用 + Icon *string `gorm:"column:icon;type:varchar(128);comment:图标" json:"icon"` // 图标 + PermissionKey *string `gorm:"column:permission_key;type:varchar(64);comment:权限关键字" json:"permission_key"` // 权限关键字 + Order *int64 `gorm:"column:order;type:int(11);comment:排序" json:"order"` // 排序 + CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 + CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` // 创建时间 + UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 + UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` // 更新时间 + Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 + Remark *string `gorm:"column:remark;type:varchar(255);comment:备注 描述" json:"remark"` // 备注 描述 } // TableName ScaAuthPermission's table name diff --git a/model/sca_auth_role.gen.go b/model/sca_auth_role.gen.go index 3b5be7c..e5a9dd7 100644 --- a/model/sca_auth_role.gen.go +++ b/model/sca_auth_role.gen.go @@ -12,14 +12,14 @@ const TableNameScaAuthRole = "sca_auth_role" // ScaAuthRole 角色表 type ScaAuthRole struct { - ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID - RoleName string `gorm:"column:role_name;type:varchar(32);not null;comment:角色名称" json:"role_name"` // 角色名称 - RoleKey string `gorm:"column:role_key;type:varchar(64);not null;comment:角色关键字" json:"role_key"` // 角色关键字 - CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 - CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间" json:"created_time"` // 创建时间 - UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 - UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间" json:"update_time"` // 更新时间 - Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除 0 未删除 1已删除" json:"deleted"` // 是否删除 0 未删除 1已删除 + ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID + RoleName string `gorm:"column:role_name;type:varchar(32);not null;comment:角色名称" json:"role_name"` // 角色名称 + RoleKey string `gorm:"column:role_key;type:varchar(64);not null;comment:角色关键字" json:"role_key"` // 角色关键字 + CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 + CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` // 创建时间 + UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 + UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` // 更新时间 + Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除 0 未删除 1已删除" json:"deleted"` // 是否删除 0 未删除 1已删除 } // TableName ScaAuthRole's table name diff --git a/model/sca_auth_role_permission.gen.go b/model/sca_auth_role_permission.gen.go index d677ff7..61db414 100644 --- a/model/sca_auth_role_permission.gen.go +++ b/model/sca_auth_role_permission.gen.go @@ -12,14 +12,14 @@ const TableNameScaAuthRolePermission = "sca_auth_role_permission" // ScaAuthRolePermission 角色-权限映射表 type ScaAuthRolePermission struct { - ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID - RoleID int64 `gorm:"column:role_id;type:bigint(20);not null;comment:角色ID" json:"role_id"` // 角色ID - PermissionID int64 `gorm:"column:permission_id;type:bigint(20);not null;comment:权限ID" json:"permission_id"` // 权限ID - CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 - CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间" json:"created_time"` // 创建时间 - UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 - UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间" json:"update_time"` // 更新时间 - Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 + ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID + RoleID int64 `gorm:"column:role_id;type:bigint(20);not null;comment:角色ID" json:"role_id"` // 角色ID + PermissionID int64 `gorm:"column:permission_id;type:bigint(20);not null;comment:权限ID" json:"permission_id"` // 权限ID + CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 + CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` // 创建时间 + UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 + UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` // 更新时间 + Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 } // TableName ScaAuthRolePermission's table name diff --git a/model/sca_auth_user.gen.go b/model/sca_auth_user.gen.go index 14442f7..66e6eb2 100644 --- a/model/sca_auth_user.gen.go +++ b/model/sca_auth_user.gen.go @@ -12,26 +12,26 @@ const TableNameScaAuthUser = "sca_auth_user" // ScaAuthUser 用户表 type ScaAuthUser struct { - ID int64 `gorm:"column:id;type:bigint(255);primaryKey;autoIncrement:true;comment:自增ID" json:"id"` // 自增ID - UUID *string `gorm:"column:uuid;type:varchar(255);comment:唯一ID" json:"uuid"` // 唯一ID - Username *string `gorm:"column:username;type:varchar(32);comment:用户名" json:"username"` // 用户名 - Nickname *string `gorm:"column:nickname;type:varchar(32);comment:昵称" json:"nickname"` // 昵称 - Email *string `gorm:"column:email;type:varchar(32);comment:邮箱" json:"email"` // 邮箱 - Phone *string `gorm:"column:phone;type:varchar(32);comment:电话" json:"phone"` // 电话 - Password *string `gorm:"column:password;type:varchar(64);comment:密码" json:"password"` // 密码 - Gender *string `gorm:"column:gender;type:varchar(32);comment:性别" json:"gender"` // 性别 - Avatar *string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` // 头像 - Status *int64 `gorm:"column:status;type:tinyint(4);comment:状态 0 正常 1 封禁" json:"status"` // 状态 0 正常 1 封禁 - Introduce *string `gorm:"column:introduce;type:varchar(255);comment:介绍" json:"introduce"` // 介绍 - ExtJSON *string `gorm:"column:ext_json;type:varchar(255);comment:额外字段" json:"ext_json"` // 额外字段 - CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 - CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间" json:"created_time"` // 创建时间 - UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 - UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间" json:"update_time"` // 更新时间 - Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除 0 未删除 1 已删除" json:"deleted"` // 是否删除 0 未删除 1 已删除 - Blog *string `gorm:"column:blog;type:varchar(255);comment:博客" json:"blog"` // 博客 - Location *string `gorm:"column:location;type:varchar(255);comment:地址" json:"location"` // 地址 - Company *string `gorm:"column:company;type:varchar(255);comment:公司" json:"company"` // 公司 + ID int64 `gorm:"column:id;type:bigint(255);primaryKey;autoIncrement:true;comment:自增ID" json:"id"` // 自增ID + UUID *string `gorm:"column:uuid;type:varchar(255);comment:唯一ID" json:"uuid"` // 唯一ID + Username *string `gorm:"column:username;type:varchar(32);comment:用户名" json:"username"` // 用户名 + Nickname *string `gorm:"column:nickname;type:varchar(32);comment:昵称" json:"nickname"` // 昵称 + Email *string `gorm:"column:email;type:varchar(32);comment:邮箱" json:"email"` // 邮箱 + Phone *string `gorm:"column:phone;type:varchar(32);comment:电话" json:"phone"` // 电话 + Password *string `gorm:"column:password;type:varchar(64);comment:密码" json:"password"` // 密码 + Gender *string `gorm:"column:gender;type:varchar(32);comment:性别" json:"gender"` // 性别 + Avatar *string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` // 头像 + Status *int64 `gorm:"column:status;type:tinyint(4);comment:状态 0 正常 1 封禁" json:"status"` // 状态 0 正常 1 封禁 + Introduce *string `gorm:"column:introduce;type:varchar(255);comment:介绍" json:"introduce"` // 介绍 + ExtJSON *string `gorm:"column:ext_json;type:varchar(255);comment:额外字段" json:"ext_json"` // 额外字段 + CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 + CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` // 创建时间 + UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 + UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` // 更新时间 + Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除 0 未删除 1 已删除" json:"deleted"` // 是否删除 0 未删除 1 已删除 + Blog *string `gorm:"column:blog;type:varchar(255);comment:博客" json:"blog"` // 博客 + Location *string `gorm:"column:location;type:varchar(255);comment:地址" json:"location"` // 地址 + Company *string `gorm:"column:company;type:varchar(255);comment:公司" json:"company"` // 公司 } // TableName ScaAuthUser's table name diff --git a/model/sca_auth_user_device.gen.go b/model/sca_auth_user_device.gen.go index bcdf1df..57589a3 100644 --- a/model/sca_auth_user_device.gen.go +++ b/model/sca_auth_user_device.gen.go @@ -12,20 +12,20 @@ const TableNameScaAuthUserDevice = "sca_auth_user_device" // ScaAuthUserDevice 用户设备信息 type ScaAuthUserDevice struct { - ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID - UserID *int64 `gorm:"column:user_id;type:bigint(20);comment:用户ID" json:"user_id"` // 用户ID - IP *string `gorm:"column:ip;type:varchar(255);comment:登录IP" json:"ip"` // 登录IP - Location *string `gorm:"column:location;type:varchar(255);comment:地址" json:"location"` // 地址 - Agent *string `gorm:"column:agent;type:varchar(255);comment:设备信息" json:"agent"` // 设备信息 - ExtJSON *string `gorm:"column:ext_json;type:varchar(255);comment:额外字段" json:"ext_json"` // 额外字段 - CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 - CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间" json:"created_time"` // 创建时间 - UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 - UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间" json:"update_time"` // 更新时间 - Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 - Browser *string `gorm:"column:browser;type:varchar(255);comment:浏览器" json:"browser"` // 浏览器 - OperatingSystem *string `gorm:"column:operating_system;type:varchar(255);comment:操作系统" json:"operating_system"` // 操作系统 - BrowserVersion *string `gorm:"column:browser_version;type:varchar(255);comment:浏览器版本" json:"browser_version"` // 浏览器版本 + ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID + UserID *int64 `gorm:"column:user_id;type:bigint(20);comment:用户ID" json:"user_id"` // 用户ID + IP *string `gorm:"column:ip;type:varchar(255);comment:登录IP" json:"ip"` // 登录IP + Location *string `gorm:"column:location;type:varchar(255);comment:地址" json:"location"` // 地址 + Agent *string `gorm:"column:agent;type:varchar(255);comment:设备信息" json:"agent"` // 设备信息 + ExtJSON *string `gorm:"column:ext_json;type:varchar(255);comment:额外字段" json:"ext_json"` // 额外字段 + CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 + CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` // 创建时间 + UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 + UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` // 更新时间 + Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 + Browser *string `gorm:"column:browser;type:varchar(255);comment:浏览器" json:"browser"` // 浏览器 + OperatingSystem *string `gorm:"column:operating_system;type:varchar(255);comment:操作系统" json:"operating_system"` // 操作系统 + BrowserVersion *string `gorm:"column:browser_version;type:varchar(255);comment:浏览器版本" json:"browser_version"` // 浏览器版本 } // TableName ScaAuthUserDevice's table name diff --git a/model/sca_auth_user_role.gen.go b/model/sca_auth_user_role.gen.go index 5453311..066f379 100644 --- a/model/sca_auth_user_role.gen.go +++ b/model/sca_auth_user_role.gen.go @@ -12,14 +12,14 @@ const TableNameScaAuthUserRole = "sca_auth_user_role" // ScaAuthUserRole 用户-角色映射表 type ScaAuthUserRole struct { - ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID - UserID int64 `gorm:"column:user_id;type:bigint(20);not null;comment:用户ID" json:"user_id"` // 用户ID - RoleID int64 `gorm:"column:role_id;type:bigint(20);not null;comment:角色ID" json:"role_id"` // 角色ID - CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 - CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间" json:"created_time"` // 创建时间 - UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 - UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间" json:"update_time"` // 更新时间 - Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 + ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID + UserID int64 `gorm:"column:user_id;type:bigint(20);not null;comment:用户ID" json:"user_id"` // 用户ID + RoleID int64 `gorm:"column:role_id;type:bigint(20);not null;comment:角色ID" json:"role_id"` // 角色ID + CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 + CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` // 创建时间 + UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 + UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` // 更新时间 + Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 } // TableName ScaAuthUserRole's table name diff --git a/model/sca_auth_user_social.gen.go b/model/sca_auth_user_social.gen.go index e09f941..9a1cbeb 100644 --- a/model/sca_auth_user_social.gen.go +++ b/model/sca_auth_user_social.gen.go @@ -12,32 +12,32 @@ const TableNameScaAuthUserSocial = "sca_auth_user_social" // ScaAuthUserSocial 社会用户信息表 type ScaAuthUserSocial struct { - ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID - UserID int64 `gorm:"column:user_id;type:bigint(20);not null;comment:用户ID" json:"user_id"` // 用户ID - UUID *string `gorm:"column:uuid;type:varchar(255);comment:第三方系统的唯一ID" json:"uuid"` // 第三方系统的唯一ID - Source *string `gorm:"column:source;type:varchar(255);comment:第三方用户来源" json:"source"` // 第三方用户来源 - AccessToken *string `gorm:"column:access_token;type:varchar(255);comment:用户的授权令牌" json:"access_token"` // 用户的授权令牌 - ExpireIn *int64 `gorm:"column:expire_in;type:int(11);comment:第三方用户的授权令牌的有效期" json:"expire_in"` // 第三方用户的授权令牌的有效期 - RefreshToken *string `gorm:"column:refresh_token;type:varchar(255);comment:刷新令牌" json:"refresh_token"` // 刷新令牌 - OpenID *string `gorm:"column:open_id;type:varchar(255);comment:第三方用户的 open id" json:"open_id"` // 第三方用户的 open id - UID *string `gorm:"column:uid;type:varchar(255);comment:第三方用户的 ID" json:"uid"` // 第三方用户的 ID - AccessCode *string `gorm:"column:access_code;type:varchar(255);comment:个别平台的授权信息" json:"access_code"` // 个别平台的授权信息 - UnionID *string `gorm:"column:union_id;type:varchar(255);comment:第三方用户的 union id" json:"union_id"` // 第三方用户的 union id - Scope *string `gorm:"column:scope;type:varchar(255);comment:第三方用户授予的权限" json:"scope"` // 第三方用户授予的权限 - TokenType *string `gorm:"column:token_type;type:varchar(255);comment:个别平台的授权信息" json:"token_type"` // 个别平台的授权信息 - IDToken *string `gorm:"column:id_token;type:varchar(255);comment:id token" json:"id_token"` // id token - MacAlgorithm *string `gorm:"column:mac_algorithm;type:varchar(255);comment:小米平台用户的附带属性" json:"mac_algorithm"` // 小米平台用户的附带属性 - MacKey *string `gorm:"column:mac_key;type:varchar(255);comment:小米平台用户的附带属性" json:"mac_key"` // 小米平台用户的附带属性 - Code *string `gorm:"column:code;type:varchar(255);comment:用户的授权code" json:"code"` // 用户的授权code - OauthToken *string `gorm:"column:oauth_token;type:varchar(255);comment:Twitter平台用户的附带属性" json:"oauth_token"` // Twitter平台用户的附带属性 - OauthTokenSecret *string `gorm:"column:oauth_token_secret;type:varchar(255);comment:Twitter平台用户的附带属性" json:"oauth_token_secret"` // Twitter平台用户的附带属性 - Status *string `gorm:"column:status;type:varchar(255);comment:状态 0正常 1 封禁" json:"status"` // 状态 0正常 1 封禁 - ExtJSON *string `gorm:"column:ext_json;type:varchar(255);comment:额外字段" json:"ext_json"` // 额外字段 - CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 - CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间" json:"created_time"` // 创建时间 - UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 - UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间" json:"update_time"` // 更新时间 - Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 + ID int64 `gorm:"column:id;type:bigint(20);primaryKey;comment:主键ID" json:"id"` // 主键ID + UserID int64 `gorm:"column:user_id;type:bigint(20);not null;comment:用户ID" json:"user_id"` // 用户ID + UUID *string `gorm:"column:uuid;type:varchar(255);comment:第三方系统的唯一ID" json:"uuid"` // 第三方系统的唯一ID + Source *string `gorm:"column:source;type:varchar(255);comment:第三方用户来源" json:"source"` // 第三方用户来源 + AccessToken *string `gorm:"column:access_token;type:varchar(255);comment:用户的授权令牌" json:"access_token"` // 用户的授权令牌 + ExpireIn *int64 `gorm:"column:expire_in;type:int(11);comment:第三方用户的授权令牌的有效期" json:"expire_in"` // 第三方用户的授权令牌的有效期 + RefreshToken *string `gorm:"column:refresh_token;type:varchar(255);comment:刷新令牌" json:"refresh_token"` // 刷新令牌 + OpenID *string `gorm:"column:open_id;type:varchar(255);comment:第三方用户的 open id" json:"open_id"` // 第三方用户的 open id + UID *string `gorm:"column:uid;type:varchar(255);comment:第三方用户的 ID" json:"uid"` // 第三方用户的 ID + AccessCode *string `gorm:"column:access_code;type:varchar(255);comment:个别平台的授权信息" json:"access_code"` // 个别平台的授权信息 + UnionID *string `gorm:"column:union_id;type:varchar(255);comment:第三方用户的 union id" json:"union_id"` // 第三方用户的 union id + Scope *string `gorm:"column:scope;type:varchar(255);comment:第三方用户授予的权限" json:"scope"` // 第三方用户授予的权限 + TokenType *string `gorm:"column:token_type;type:varchar(255);comment:个别平台的授权信息" json:"token_type"` // 个别平台的授权信息 + IDToken *string `gorm:"column:id_token;type:varchar(255);comment:id token" json:"id_token"` // id token + MacAlgorithm *string `gorm:"column:mac_algorithm;type:varchar(255);comment:小米平台用户的附带属性" json:"mac_algorithm"` // 小米平台用户的附带属性 + MacKey *string `gorm:"column:mac_key;type:varchar(255);comment:小米平台用户的附带属性" json:"mac_key"` // 小米平台用户的附带属性 + Code *string `gorm:"column:code;type:varchar(255);comment:用户的授权code" json:"code"` // 用户的授权code + OauthToken *string `gorm:"column:oauth_token;type:varchar(255);comment:Twitter平台用户的附带属性" json:"oauth_token"` // Twitter平台用户的附带属性 + OauthTokenSecret *string `gorm:"column:oauth_token_secret;type:varchar(255);comment:Twitter平台用户的附带属性" json:"oauth_token_secret"` // Twitter平台用户的附带属性 + Status *string `gorm:"column:status;type:varchar(255);comment:状态 0正常 1 封禁" json:"status"` // 状态 0正常 1 封禁 + ExtJSON *string `gorm:"column:ext_json;type:varchar(255);comment:额外字段" json:"ext_json"` // 额外字段 + CreatedBy *string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` // 创建人 + CreatedTime *time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` // 创建时间 + UpdateBy *string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` // 更新人 + UpdateTime *time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` // 更新时间 + Deleted *int64 `gorm:"column:deleted;type:int(11);comment:是否删除" json:"deleted"` // 是否删除 } // TableName ScaAuthUserSocial's table name diff --git a/router/modules/auth_user_router.go b/router/modules/auth_user_router.go index 0fefbf7..6ad7434 100644 --- a/router/modules/auth_user_router.go +++ b/router/modules/auth_user_router.go @@ -10,4 +10,8 @@ var authApi = api.Api.AuthApi func AuthRouter(router *gin.RouterGroup) { group := router.Group("auth") group.GET("/user/List", authApi.GetUserList) + group.GET("/user/query_by_username", authApi.QueryUserByUsername) + group.GET("/user/query_by_uuid", authApi.QueryUserByUuid) + group.DELETE("/user/delete", authApi.DeleteUser) + group.GET("/user/query_by_phone", authApi.QueryUserByPhone) } diff --git a/service/auth_service/auth_service.go b/service/auth_service/auth_service.go index b82baf4..53724c0 100644 --- a/service/auth_service/auth_service.go +++ b/service/auth_service/auth_service.go @@ -1,12 +1,60 @@ package auth_service import ( + "gorm.io/gorm" + "schisandra-cloud-album/common/enum" "schisandra-cloud-album/global" "schisandra-cloud-album/model" ) +// GetUserList 获取所有用户列表 func (AuthService) GetUserList() []*model.ScaAuthUser { data := make([]*model.ScaAuthUser, 0) - global.DB.Find(&data) + global.DB.Where("deleted = 0 ").Find(&data) return data } + +// QueryUserByName 根据用户名查询用户 +func (AuthService) QueryUserByName(username string) model.ScaAuthUser { + authUser := model.ScaAuthUser{} + global.DB.Where("username = ? and deleted = 0", username).First(&authUser) + return authUser +} + +// QueryUserByUuid 根据用户uuid查询用户 +func (AuthService) QueryUserByUuid(uuid string) model.ScaAuthUser { + authUser := model.ScaAuthUser{} + global.DB.Where("uuid = ? and deleted = 0", uuid).First(&authUser) + return authUser +} + +// AddUser 添加用户 +func (AuthService) AddUser(user model.ScaAuthUser) error { + return global.DB.Create(&user).Error +} + +// UpdateUser 更新用户 +func (AuthService) UpdateUser(user model.ScaAuthUser) *gorm.DB { + authUser := model.ScaAuthUser{} + return global.DB.Model(&authUser).Where("uuid = ?", user.UUID).Updates(user) +} + +// DeleteUser 删除用户 +func (AuthService) DeleteUser(uuid string) error { + authUser := model.ScaAuthUser{} + return global.DB.Model(&authUser).Where("uuid = ?", uuid).Updates(&model.ScaAuthUser{Deleted: &enum.DELETED}).Error +} + +// QueryUserByPhone 根据手机号查询用户 +func (AuthService) QueryUserByPhone(phone string) model.ScaAuthUser { + authUser := model.ScaAuthUser{} + global.DB.Where("phone = ? and deleted = 0", phone).First(&authUser) + return authUser +} + +// QueryUserByEmail 根据邮箱查询用户 +func (AuthService) QueryUserByEmail(email string) model.ScaAuthUser { + authUser := model.ScaAuthUser{} + global.DB.Where("email = ? and deleted = 0", email).First(&authUser) + return authUser +} diff --git a/service/auth_service/enter.go b/service/auth_service/index.go similarity index 100% rename from service/auth_service/enter.go rename to service/auth_service/index.go