diff --git a/api/backend/login.go b/api/backend/login.go index 05d2b2d..f39d275 100644 --- a/api/backend/login.go +++ b/api/backend/login.go @@ -2,25 +2,39 @@ package backend import ( "github.com/gogf/gf/v2/frame/g" + + "novel/internal/model/entity" ) // verify code type GetCodeReq struct { - g.Meta `path:"/get-code" method:"post" tags:"获取验证码" summary:"获取验证码"` + g.Meta `path:"/get-phone-code" method:"post" tags:"获取验证码" summary:"获取验证码"` Phone string `json:"phone" v:"required|phone" description:"手机号"` CodeType int `json:"codeType" v:"required|in:1,2#类型不合法" description:"验证码类型"` } + type GetCodeRes struct { Code int } // createOrLogin type CreateOrLoginReq struct { - g.Meta `path:"/create-or-login" method:"post" tags:"注册或登录" summary:"注册或者登录"` - Phone string `json:"phone" v:"required|phone" description:"手机号"` - Code int `json:"code" v:"required|size:6" description:"验证码"` + // g.Meta `path:"/create-or-login" method:"post" tags:"注册或登录" summary:"注册或者登录"` + Phone string `json:"phone" v:"required|phone" description:"手机号"` + Code int `json:"code" v:"required|size:6" description:"验证码"` } -type CreateOrLoginRes struct { - Id uint +type CreateLoginRes struct { + Id uint + PenName string +} + +// for gtoken +type CreateOrLoginRes struct { + Type string `json:"type"` + Token string `json:"token"` + ExpireIn int `json:"expire_in"` + IsAdmin uint `json:"is_admin"` // 是否超管 + RoleIds string `json:"role_ids"` // 角色 + Permissions []entity.PermissionInfo `json:"permissions"` // 权限列表 } diff --git a/api/backend/writer.go b/api/backend/writer.go new file mode 100644 index 0000000..1587759 --- /dev/null +++ b/api/backend/writer.go @@ -0,0 +1,64 @@ +package backend + +import ( + "github.com/gogf/gf/v2/frame/g" +) + +// type WriterReq struct { +// g.Meta `path:"/writer/add" tags:"writer" method:"post" summary:"writer add api"` +// Name string `json:"name" v:"required#用户名不能为空" dc:"用户名"` +// Password string `json:"password" v:"required#密码不能为空" dc:"密码"` +// RoleIds string `json:"role_ids" dc:"角色ids"` +// IsAdmin int `json:"is_admin" dc:"是否超级管理员"` +// } +// +// type WriterRes struct { +// AdminId int `json:"admin_id"` +// } +// +// type AdminDeleteReq struct { +// g.Meta `path:"/admin/delete" method:"delete" tags:"管理员" summary:"删除管理员接口"` +// Id uint `v:"min:1#请选择需要删除的管理员" dc:"管理员id"` +// } +// type AdminDeleteRes struct{} +// +// type AdminUpdateReq struct { +// g.Meta `path:"/admin/update/{Id}" method:"post" tags:"管理员" summary:"修改管理员接口"` +// Id uint `json:"id" v:"min:1#请选择需要修改的管理员" dc:"管理员Id"` +// Name string `json:"name" v:"required#用户名不能为空" dc:"用户名"` +// Password string `json:"password" v:"required#密码不能为空" dc:"密码"` +// RoleIds string `json:"role_ids" dc:"角色ids"` +// IsAdmin int `json:"is_admin" dc:"是否超级管理员"` +// } +// type AdminUpdateRes struct { +// Id uint `json:"id"` +// } +// type AdminGetListCommonReq struct { +// g.Meta `path:"/admin/list" method:"get" tags:"管理员" summary:"管理员列表接口"` +// // CommonPaginationReq +// } +// type AdminGetListCommonRes struct { +// List interface{} `json:"list" description:"列表"` +// Page int `json:"page" description:"分页码"` +// Size int `json:"size" description:"分页数量"` +// Total int `json:"total" description:"数据总数"` +// } + +type WriterGetInfoReq struct { + g.Meta `path:"/writer/info" method:"get"` +} + +// for jwt +// type AdminGetInfoRes struct { +// Id int `json:"id"` +// IdentityKey string `json:"identity_key"` +// Payload string `json:"payload"` +// } + +// for gtoken +type WriterGetInfoRes struct { + Id int `json:"id"` + PenName string `json:"pen_name"` + RoleIds string `json:"role_ids"` + IsAdmin int `json:"is_admin"` +} diff --git a/go.mod b/go.mod index 9beb982..4f8b458 100644 --- a/go.mod +++ b/go.mod @@ -2,29 +2,41 @@ module novel go 1.18 -require github.com/gogf/gf/v2 v2.6.1 +require ( + github.com/goflyfox/gtoken v1.5.10 + github.com/gogf/gf/v2 v2.6.1 +) require ( - github.com/BurntSushi/toml v1.2.0 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/go-sql-driver/mysql v1.7.1 // indirect + github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.1 // indirect + github.com/redis/go-redis/v9 v9.4.0 // indirect + go.opentelemetry.io/otel/metric v1.21.0 // indirect +) + +require ( + github.com/BurntSushi/toml v1.3.2 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/fatih/color v1.15.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.1 // indirect + github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.1 github.com/gorilla/websocket v1.5.0 // indirect github.com/grokify/html-strip-tags-go v0.0.1 // indirect - github.com/magiconair/properties v1.8.6 // indirect + github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.4 // indirect - go.opentelemetry.io/otel v1.14.0 // indirect - go.opentelemetry.io/otel/sdk v1.14.0 // indirect - go.opentelemetry.io/otel/trace v1.14.0 // indirect + go.opentelemetry.io/otel v1.21.0 // indirect + go.opentelemetry.io/otel/sdk v1.21.0 // indirect + go.opentelemetry.io/otel/trace v1.21.0 // indirect golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/sys v0.16.0 // indirect + golang.org/x/text v0.14.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f73ff2e..2576ef0 100644 --- a/go.sum +++ b/go.sum @@ -1,33 +1,55 @@ github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME= github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/goflyfox/gtoken v1.5.10 h1:oj/v5r/1TjMMZvxpyEZYdsEvG2ZK/SGGnyjvsKi4uHk= +github.com/goflyfox/gtoken v1.5.10/go.mod h1:YpoSAn9tbfrSBoQnY7raQP0HaiRjQAE+4J179ecRH5I= github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.1 h1:5VW1vlaFNSHHhMliRkGTcDshMeA52Il8T+gffJJaVMc= github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.1/go.mod h1:jxCa1WV/W+q0F4ILebakUsqRrl7iL3qvP+Uci0eXAew= +github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.1 h1:5NWx7rZa8CbPNw1vbLzIXQFEMbKvoJVQM0GyReBRvJ8= +github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.1/go.mod h1:iy1Dwp5xWfGfuWixCgGQ06ZX6lp+d9onbmSWWzi111A= +github.com/gogf/gf/v2 v2.5.4/go.mod h1:7yf5qp0BznfsYx7Sw49m3mQvBsHpwAjJk3Q9ZnKoUEc= github.com/gogf/gf/v2 v2.6.1 h1:n/cfXM506WjhPa6Z1CEDuHNM1XZ7C8JzSDPn2AfuxgQ= github.com/gogf/gf/v2 v2.6.1/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -36,25 +58,87 @@ github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/redis/go-redis/v9 v9.4.0 h1:Yzoz33UZw9I/mFhx4MNrB6Fk+XHO1VukNcCa1+lwyKk= +github.com/redis/go-redis/v9 v9.4.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM= go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU= +go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= +go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= +go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= +go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY= go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM= +go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= +go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M= go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8= +go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= +go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +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/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.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +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/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= +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.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +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/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 77b3131..ae61f48 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -2,12 +2,23 @@ package cmd import ( "context" + "strconv" + "github.com/goflyfox/gtoken/gtoken" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/os/gcmd" + "github.com/gogf/gf/v2/text/gstr" + "github.com/gogf/gf/v2/util/gconv" + apiBackend "novel/api/backend" + "novel/internal/consts" "novel/internal/controller/backend" + "novel/internal/dao" + "novel/internal/model" + "novel/internal/model/entity" + "novel/internal/service" + "novel/utility/response" ) var ( @@ -18,6 +29,22 @@ var ( Func: func(ctx context.Context, parser *gcmd.Parser) (err error) { s := g.Server() + // 认证接口 + // loginFunc := Login + // 启动 + gfToken := >oken.GfToken{ + CacheMode: consts.CacheModeRedis, + ServerName: "novel", + LoginPath: "/create-or-login", + LoginBeforeFunc: loginFunc, + LoginAfterFunc: loginAfterFunc, + LogoutPath: "/backend/logout", + AuthPaths: g.SliceStr{"/backend/admin/info"}, + AuthExcludePaths: g.SliceStr{"/admin/user/info", "/admin/system/user/info"}, // 不拦截路径 /user/info,/system/user/info,/system/user, + AuthAfterFunc: authAfterFunc, + MultiLogin: true, + } + // s.Group("/backend", func(group *ghttp.RouterGroup) { // group.Middleware(ghttp.MiddlewareHandlerResponse) // group.Group("/writer", func(group2 *ghttp.RouterGroup) { @@ -27,24 +54,33 @@ var ( // 管理后台路由组 s.Group("/backend", func(group *ghttp.RouterGroup) { + group.Middleware(ghttp.MiddlewareHandlerResponse) // group.Middleware( // service.Middleware().CORS, // service.Middleware().Ctx, // service.Middleware().ResponseHandler, // ) + + // // gtoken中间件绑定 + // err := gfToken.Middleware(ctx, group) + // if nil != nil { + // panic(err) + // } + // 不需要登录的路由组绑定 - // group.Bind( - // controller.Admin.Create, // 管理员 - // controller.Login, // 登录 - // ) + group.Bind( + // backend.Login, // 登录相关 + backend.Login.GetPhoneCode, // 验证码 + backend.Login.CreateOrLogin, // 登录 + ) // 需要登录的路由组绑定 group.Group("/", func(group *ghttp.RouterGroup) { - // err := gfAdminToken.Middleware(ctx, group) + err := gfToken.Middleware(ctx, group) if err != nil { panic(err) } group.Bind( - backend.Login, // 数据大屏相关 + backend.Writer.Info, // 查询当前管理员信息 ) }) }) @@ -54,3 +90,87 @@ var ( }, } ) + +func loginFunc(r *ghttp.Request) (string, interface{}) { + phone := r.Get("phone").String() + code := r.Get("code").Int() + if phone == "" || code <= 0 { + r.Response.WriteJson(gtoken.Fail("手机号或者验证码不能为空")) + r.ExitAll() + } + + ctx := context.TODO() + writer, err := service.Writer().CreateOrLogin(ctx, model.WriterCreateOrLoginInput{ + Phone: phone, + Code: code, + }) + + if err != nil { + r.Response.WriteJson(gtoken.Fail("手机号或者验证码错误")) + r.ExitAll() + } + return consts.GtokenWriterPrefix + strconv.Itoa(int(writer.Id)), writer +} + +// 自定义的登录之后的函数 +func loginAfterFunc(r *ghttp.Request, respData gtoken.Resp) { + if !respData.Success() { + respData.Code = 0 + r.Response.WriteJson(respData) + return + } else { + respData.Code = 1 + // 获得登录用户id + userKey := respData.GetString("userKey") + adminId := gstr.StrEx(userKey, consts.GtokenWriterPrefix) + // 根据id获得登录用户其他信息 + writerInfo := entity.Writer{} + err := dao.Writer.Ctx(context.TODO()).WherePri(adminId).Scan(&writerInfo) + if err != nil { + return + } + // 通过角色查询权限 + // 先通过角色查询权限id + var rolePermissionInfos []entity.RolePermissionInfo + err = dao.RolePermissionInfo.Ctx(context.TODO()).WhereIn(dao.RolePermissionInfo.Columns().RoleId, g.Slice{writerInfo.RoleIds}).Scan(&rolePermissionInfos) + if err != nil { + return + } + permissionIds := g.Slice{} + for _, info := range rolePermissionInfos { + permissionIds = append(permissionIds, info.PermissionId) + } + + var permissions []entity.PermissionInfo + err = dao.PermissionInfo.Ctx(context.TODO()).WhereIn(dao.PermissionInfo.Columns().Id, permissionIds).Scan(&permissions) + if err != nil { + return + } + data := &apiBackend.CreateOrLoginRes{ + Type: consts.TokenType, + Token: respData.GetString("token"), + ExpireIn: consts.GTokenExpireIn, // 单位秒, + IsAdmin: writerInfo.IsAdmin, + RoleIds: writerInfo.RoleIds, + Permissions: permissions, + } + response.JsonExit(r, 0, "", data) + } + return +} + +// 登录鉴权中间件for后台 +func authAfterFunc(r *ghttp.Request, respData gtoken.Resp) { + var writerInfo entity.Writer + err := gconv.Struct(respData.GetString("data"), &writerInfo) + if err != nil { + response.Auth(r) + return + } + // todo 这里可以写账号前置校验、是否被拉黑、有无权限等逻辑 + r.SetCtxVar(consts.CtxWriterId, writerInfo.Id) + r.SetCtxVar(consts.CtxWriterName, writerInfo.PenName) + r.SetCtxVar(consts.CtxWriterIsAdmin, writerInfo.IsAdmin) + r.SetCtxVar(consts.CtxWriterRoleIds, writerInfo.RoleIds) + r.Middleware.Next() +} diff --git a/internal/consts/consts.go b/internal/consts/consts.go index 8e7da78..4c9187b 100644 --- a/internal/consts/consts.go +++ b/internal/consts/consts.go @@ -5,4 +5,19 @@ const ( PhoneVerifyType1 = 1 // 1-注册/登录 PhoneVerifyType2 = 2 // 2-找回密码 ContextKey = "ContextKey" // 上下文变量存储键名,前后端系统共享 + + // for 登录相关 + TokenType = "Bearer" + CacheModeRedis = 2 + GtokenWriterPrefix = "Writer:" // gtoken登录,小说作者后台前缀区分 + BackendServerName = "小说系统" + MultiLogin = true + FrontendMultiLogin = true + GTokenExpireIn = 10 * 24 * 60 * 60 + + // for writer + CtxWriterId = "CtxAdminId" + CtxWriterName = "CtxAdminName" + CtxWriterIsAdmin = "CtxAdminIsAdmin" + CtxWriterRoleIds = "CtxAdminRoleIds" ) diff --git a/internal/controller/backend/login.go b/internal/controller/backend/login.go index de4a3d1..cfadde4 100644 --- a/internal/controller/backend/login.go +++ b/internal/controller/backend/login.go @@ -25,7 +25,7 @@ func New() *cLogin { return &cLogin{} } -func (c *cLogin) CreateOrLogin(ctx context.Context, req *backend.CreateOrLoginReq) (res *backend.CreateOrLoginRes, err error) { +func (c *cLogin) CreateOrLogin(ctx context.Context, req *backend.CreateOrLoginReq) (res *backend.CreateLoginRes, err error) { input := model.WriterCreateOrLoginInput{} err = gconv.Scan(req, &input) if err != nil { @@ -40,8 +40,8 @@ func (c *cLogin) CreateOrLogin(ctx context.Context, req *backend.CreateOrLoginRe if err != nil { return nil, err } - - return &backend.CreateOrLoginRes{Id: writer.Id}, nil + return &backend.CreateLoginRes{Id: writer.Id, PenName: writer.PenName}, nil + // return &backend.CreateOrLoginRes{Id: writer.Id}, nil } func (c *cLogin) GetPhoneCode(ctx context.Context, req *backend.GetCodeReq) (res *backend.GetCodeRes, err error) { diff --git a/internal/controller/backend/writer.go b/internal/controller/backend/writer.go new file mode 100644 index 0000000..0041da4 --- /dev/null +++ b/internal/controller/backend/writer.go @@ -0,0 +1,31 @@ +// Package backend ----------------------------- +// @file : writer.go +// @author : Allen zhang +// @contact : 364438619@qq.com +// @time : 2024/1/15 15:15 +// ------------------------------------------- +package backend + +import ( + "context" + + "github.com/gogf/gf/v2/util/gconv" + + "novel/api/backend" + "novel/internal/consts" +) + +// Writer 内容管理 +var Writer = cWriter{} + +type cWriter struct{} + +// gtoken 版本返回结果 +func (c *cWriter) Info(ctx context.Context, req *backend.WriterGetInfoReq) (res *backend.WriterGetInfoRes, err error) { + return &backend.WriterGetInfoRes{ + Id: gconv.Int(ctx.Value(consts.CtxWriterId)), + PenName: gconv.String(ctx.Value(consts.CtxWriterName)), + IsAdmin: gconv.Int(ctx.Value(consts.CtxWriterIsAdmin)), + RoleIds: gconv.String(ctx.Value(consts.CtxWriterRoleIds)), + }, err +} diff --git a/internal/dao/internal/permission_info.go b/internal/dao/internal/permission_info.go new file mode 100644 index 0000000..8abdac9 --- /dev/null +++ b/internal/dao/internal/permission_info.go @@ -0,0 +1,83 @@ +// ========================================================================== +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package internal + +import ( + "context" + + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// PermissionInfoDao is the data access object for table nv_permission_info. +type PermissionInfoDao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of current DAO. + columns PermissionInfoColumns // columns contains all the column names of Table for convenient usage. +} + +// PermissionInfoColumns defines and stores column names for table nv_permission_info. +type PermissionInfoColumns struct { + Id string // + Name string // 权限名称 + Path string // 路径 + CreatedAt string // + UpdatedAt string // + DeletedAt string // +} + +// permissionInfoColumns holds the columns for table nv_permission_info. +var permissionInfoColumns = PermissionInfoColumns{ + Id: "id", + Name: "name", + Path: "path", + CreatedAt: "created_at", + UpdatedAt: "updated_at", + DeletedAt: "deleted_at", +} + +// NewPermissionInfoDao creates and returns a new DAO object for table data access. +func NewPermissionInfoDao() *PermissionInfoDao { + return &PermissionInfoDao{ + group: "default", + table: "nv_permission_info", + columns: permissionInfoColumns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *PermissionInfoDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *PermissionInfoDao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *PermissionInfoDao) Columns() PermissionInfoColumns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *PermissionInfoDao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *PermissionInfoDao) Ctx(ctx context.Context) *gdb.Model { + return dao.DB().Model(dao.table).Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note that, you should not Commit or Rollback the transaction in function f +// as it is automatically handled by this function. +func (dao *PermissionInfoDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/internal/dao/internal/role_info.go b/internal/dao/internal/role_info.go new file mode 100644 index 0000000..62022f3 --- /dev/null +++ b/internal/dao/internal/role_info.go @@ -0,0 +1,83 @@ +// ========================================================================== +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package internal + +import ( + "context" + + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// RoleInfoDao is the data access object for table nv_role_info. +type RoleInfoDao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of current DAO. + columns RoleInfoColumns // columns contains all the column names of Table for convenient usage. +} + +// RoleInfoColumns defines and stores column names for table nv_role_info. +type RoleInfoColumns struct { + Id string // + Name string // 角色名称 + Desc string // 描述 + CreatedAt string // + UpdatedAt string // + DeletedAt string // +} + +// roleInfoColumns holds the columns for table nv_role_info. +var roleInfoColumns = RoleInfoColumns{ + Id: "id", + Name: "name", + Desc: "desc", + CreatedAt: "created_at", + UpdatedAt: "updated_at", + DeletedAt: "deleted_at", +} + +// NewRoleInfoDao creates and returns a new DAO object for table data access. +func NewRoleInfoDao() *RoleInfoDao { + return &RoleInfoDao{ + group: "default", + table: "nv_role_info", + columns: roleInfoColumns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *RoleInfoDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *RoleInfoDao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *RoleInfoDao) Columns() RoleInfoColumns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *RoleInfoDao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *RoleInfoDao) Ctx(ctx context.Context) *gdb.Model { + return dao.DB().Model(dao.table).Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note that, you should not Commit or Rollback the transaction in function f +// as it is automatically handled by this function. +func (dao *RoleInfoDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/internal/dao/internal/role_permission_info.go b/internal/dao/internal/role_permission_info.go new file mode 100644 index 0000000..3d52fdc --- /dev/null +++ b/internal/dao/internal/role_permission_info.go @@ -0,0 +1,81 @@ +// ========================================================================== +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package internal + +import ( + "context" + + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// RolePermissionInfoDao is the data access object for table nv_role_permission_info. +type RolePermissionInfoDao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of current DAO. + columns RolePermissionInfoColumns // columns contains all the column names of Table for convenient usage. +} + +// RolePermissionInfoColumns defines and stores column names for table nv_role_permission_info. +type RolePermissionInfoColumns struct { + Id string // + RoleId string // 角色id + PermissionId string // 权限id + CreatedAt string // + UpdatedAt string // +} + +// rolePermissionInfoColumns holds the columns for table nv_role_permission_info. +var rolePermissionInfoColumns = RolePermissionInfoColumns{ + Id: "id", + RoleId: "role_id", + PermissionId: "permission_id", + CreatedAt: "created_at", + UpdatedAt: "updated_at", +} + +// NewRolePermissionInfoDao creates and returns a new DAO object for table data access. +func NewRolePermissionInfoDao() *RolePermissionInfoDao { + return &RolePermissionInfoDao{ + group: "default", + table: "nv_role_permission_info", + columns: rolePermissionInfoColumns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *RolePermissionInfoDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *RolePermissionInfoDao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *RolePermissionInfoDao) Columns() RolePermissionInfoColumns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *RolePermissionInfoDao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *RolePermissionInfoDao) Ctx(ctx context.Context) *gdb.Model { + return dao.DB().Model(dao.table).Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note that, you should not Commit or Rollback the transaction in function f +// as it is automatically handled by this function. +func (dao *RolePermissionInfoDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/internal/dao/internal/writer.go b/internal/dao/internal/writer.go index 2b4003d..5aa2a1e 100644 --- a/internal/dao/internal/writer.go +++ b/internal/dao/internal/writer.go @@ -29,6 +29,8 @@ type WriterColumns struct { Qq string // RealName string // 真名 IdNo string // 身份证号 + IsAdmin string // 是否是管理员 + RoleIds string // 角色id CreatedAt string // UpdatedAt string // DeletedAt string // @@ -45,6 +47,8 @@ var writerColumns = WriterColumns{ Qq: "qq", RealName: "real_name", IdNo: "id_no", + IsAdmin: "is_admin", + RoleIds: "role_ids", CreatedAt: "created_at", UpdatedAt: "updated_at", DeletedAt: "deleted_at", diff --git a/internal/dao/permission_info.go b/internal/dao/permission_info.go new file mode 100644 index 0000000..d99c4c7 --- /dev/null +++ b/internal/dao/permission_info.go @@ -0,0 +1,27 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package dao + +import ( + "novel/internal/dao/internal" +) + +// internalPermissionInfoDao is internal type for wrapping internal DAO implements. +type internalPermissionInfoDao = *internal.PermissionInfoDao + +// permissionInfoDao is the data access object for table nv_permission_info. +// You can define custom methods on it to extend its functionality as you wish. +type permissionInfoDao struct { + internalPermissionInfoDao +} + +var ( + // PermissionInfo is globally public accessible object for table nv_permission_info operations. + PermissionInfo = permissionInfoDao{ + internal.NewPermissionInfoDao(), + } +) + +// Fill with you ideas below. diff --git a/internal/dao/role_info.go b/internal/dao/role_info.go new file mode 100644 index 0000000..ed25606 --- /dev/null +++ b/internal/dao/role_info.go @@ -0,0 +1,27 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package dao + +import ( + "novel/internal/dao/internal" +) + +// internalRoleInfoDao is internal type for wrapping internal DAO implements. +type internalRoleInfoDao = *internal.RoleInfoDao + +// roleInfoDao is the data access object for table nv_role_info. +// You can define custom methods on it to extend its functionality as you wish. +type roleInfoDao struct { + internalRoleInfoDao +} + +var ( + // RoleInfo is globally public accessible object for table nv_role_info operations. + RoleInfo = roleInfoDao{ + internal.NewRoleInfoDao(), + } +) + +// Fill with you ideas below. diff --git a/internal/dao/role_permission_info.go b/internal/dao/role_permission_info.go new file mode 100644 index 0000000..f4a0c85 --- /dev/null +++ b/internal/dao/role_permission_info.go @@ -0,0 +1,27 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package dao + +import ( + "novel/internal/dao/internal" +) + +// internalRolePermissionInfoDao is internal type for wrapping internal DAO implements. +type internalRolePermissionInfoDao = *internal.RolePermissionInfoDao + +// rolePermissionInfoDao is the data access object for table nv_role_permission_info. +// You can define custom methods on it to extend its functionality as you wish. +type rolePermissionInfoDao struct { + internalRolePermissionInfoDao +} + +var ( + // RolePermissionInfo is globally public accessible object for table nv_role_permission_info operations. + RolePermissionInfo = rolePermissionInfoDao{ + internal.NewRolePermissionInfoDao(), + } +) + +// Fill with you ideas below. diff --git a/internal/logic/writer/writer.go b/internal/logic/writer/writer.go index 7f1de14..4dc3180 100644 --- a/internal/logic/writer/writer.go +++ b/internal/logic/writer/writer.go @@ -8,7 +8,6 @@ package writer import ( "context" - "fmt" "time" "github.com/gogf/gf/v2/errors/gerror" @@ -72,8 +71,8 @@ func (s *sWriter) CreateOrLogin(ctx context.Context, in model.WriterCreateOrLogi // if writerInfo == nil { // return gerror.New(`Passport or Password not correct`) // } - fmt.Println("-------------------------") - fmt.Println(writerInfo) + // fmt.Println("-------------------------") + // fmt.Println(writerInfo) // err1 := service.Session().SetWriter(ctx, &writerInfo) // if err1 != nil { @@ -84,12 +83,12 @@ func (s *sWriter) CreateOrLogin(ctx context.Context, in model.WriterCreateOrLogi // Id: writerInfo.Id, // }) - return &model.WriterCreateOrLoginOutput{Id: writerInfo.Id}, nil + return &model.WriterCreateOrLoginOutput{Id: writerInfo.Id, PenName: writerInfo.PenName}, nil } func (s *sWriter) CheckPhoneVerifyCode(ctx context.Context, phone string, code, codeType int) (bool, error) { - time1 := time.Now().Add(-1 * time.Minute) + time1 := time.Now().Add(-10 * time.Minute) dateTime := time1.Format("2006-01-02 15:04:05") count, err := dao.PhoneVerify.Ctx(ctx).Where(do.PhoneVerify{ diff --git a/internal/model/do/permission_info.go b/internal/model/do/permission_info.go new file mode 100644 index 0000000..8ff01e2 --- /dev/null +++ b/internal/model/do/permission_info.go @@ -0,0 +1,21 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" +) + +// PermissionInfo is the golang structure of table nv_permission_info for DAO operations like Where/Data. +type PermissionInfo struct { + g.Meta `orm:"table:nv_permission_info, do:true"` + Id interface{} // + Name interface{} // 权限名称 + Path interface{} // 路径 + CreatedAt *gtime.Time // + UpdatedAt *gtime.Time // + DeletedAt *gtime.Time // +} diff --git a/internal/model/do/role_info.go b/internal/model/do/role_info.go new file mode 100644 index 0000000..5802797 --- /dev/null +++ b/internal/model/do/role_info.go @@ -0,0 +1,21 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" +) + +// RoleInfo is the golang structure of table nv_role_info for DAO operations like Where/Data. +type RoleInfo struct { + g.Meta `orm:"table:nv_role_info, do:true"` + Id interface{} // + Name interface{} // 角色名称 + Desc interface{} // 描述 + CreatedAt *gtime.Time // + UpdatedAt *gtime.Time // + DeletedAt *gtime.Time // +} diff --git a/internal/model/do/role_permission_info.go b/internal/model/do/role_permission_info.go new file mode 100644 index 0000000..49d7aae --- /dev/null +++ b/internal/model/do/role_permission_info.go @@ -0,0 +1,20 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" +) + +// RolePermissionInfo is the golang structure of table nv_role_permission_info for DAO operations like Where/Data. +type RolePermissionInfo struct { + g.Meta `orm:"table:nv_role_permission_info, do:true"` + Id interface{} // + RoleId interface{} // 角色id + PermissionId interface{} // 权限id + CreatedAt *gtime.Time // + UpdatedAt *gtime.Time // +} diff --git a/internal/model/do/writer.go b/internal/model/do/writer.go index 7da0ada..be61284 100644 --- a/internal/model/do/writer.go +++ b/internal/model/do/writer.go @@ -21,6 +21,8 @@ type Writer struct { Qq interface{} // RealName interface{} // 真名 IdNo interface{} // 身份证号 + IsAdmin interface{} // 是否是管理员 + RoleIds interface{} // 角色id CreatedAt *gtime.Time // UpdatedAt *gtime.Time // DeletedAt *gtime.Time // diff --git a/internal/model/entity/permission_info.go b/internal/model/entity/permission_info.go new file mode 100644 index 0000000..e603b8f --- /dev/null +++ b/internal/model/entity/permission_info.go @@ -0,0 +1,19 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +import ( + "github.com/gogf/gf/v2/os/gtime" +) + +// PermissionInfo is the golang structure for table permission_info. +type PermissionInfo struct { + Id int `json:"id" description:""` + Name string `json:"name" description:"权限名称"` + Path string `json:"path" description:"路径"` + CreatedAt *gtime.Time `json:"createdAt" description:""` + UpdatedAt *gtime.Time `json:"updatedAt" description:""` + DeletedAt *gtime.Time `json:"deletedAt" description:""` +} diff --git a/internal/model/entity/role_info.go b/internal/model/entity/role_info.go new file mode 100644 index 0000000..3f062fd --- /dev/null +++ b/internal/model/entity/role_info.go @@ -0,0 +1,19 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +import ( + "github.com/gogf/gf/v2/os/gtime" +) + +// RoleInfo is the golang structure for table role_info. +type RoleInfo struct { + Id int `json:"id" description:""` + Name string `json:"name" description:"角色名称"` + Desc string `json:"desc" description:"描述"` + CreatedAt *gtime.Time `json:"createdAt" description:""` + UpdatedAt *gtime.Time `json:"updatedAt" description:""` + DeletedAt *gtime.Time `json:"deletedAt" description:""` +} diff --git a/internal/model/entity/role_permission_info.go b/internal/model/entity/role_permission_info.go new file mode 100644 index 0000000..0f50128 --- /dev/null +++ b/internal/model/entity/role_permission_info.go @@ -0,0 +1,18 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +import ( + "github.com/gogf/gf/v2/os/gtime" +) + +// RolePermissionInfo is the golang structure for table role_permission_info. +type RolePermissionInfo struct { + Id int `json:"id" description:""` + RoleId int `json:"roleId" description:"角色id"` + PermissionId int `json:"permissionId" description:"权限id"` + CreatedAt *gtime.Time `json:"createdAt" description:""` + UpdatedAt *gtime.Time `json:"updatedAt" description:""` +} diff --git a/internal/model/entity/writer.go b/internal/model/entity/writer.go index 2ef413f..0f372d9 100644 --- a/internal/model/entity/writer.go +++ b/internal/model/entity/writer.go @@ -19,6 +19,8 @@ type Writer struct { Qq string `json:"qq" description:""` RealName string `json:"realName" description:"真名"` IdNo string `json:"idNo" description:"身份证号"` + IsAdmin uint `json:"isAdmin" description:"是否是管理员"` + RoleIds string `json:"roleIds" description:"角色id"` CreatedAt *gtime.Time `json:"createdAt" description:""` UpdatedAt *gtime.Time `json:"updatedAt" description:""` DeletedAt *gtime.Time `json:"deletedAt" description:""` diff --git a/internal/model/writer.go b/internal/model/writer.go index 9ddded2..5ae3680 100644 --- a/internal/model/writer.go +++ b/internal/model/writer.go @@ -12,7 +12,8 @@ type WriterCreateOrLoginInput struct { } type WriterCreateOrLoginOutput struct { - Id uint + Id uint + PenName string } // type GetCodeInput struct { diff --git a/main.exe~ b/main.exe~ index 6f8d88c..b8cd1cd 100644 Binary files a/main.exe~ and b/main.exe~ differ diff --git a/main.go b/main.go index 8d1e71f..ac1eee1 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "novel/internal/cmd" _ "github.com/gogf/gf/contrib/drivers/mysql/v2" + _ "github.com/gogf/gf/contrib/nosql/redis/v2" ) func main() { diff --git a/utility/response/response.go b/utility/response/response.go new file mode 100644 index 0000000..6ee3fea --- /dev/null +++ b/utility/response/response.go @@ -0,0 +1,105 @@ +package response + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/util/gconv" +) + +// JsonRes 数据返回通用JSON数据结构 +type JsonRes struct { + Code int `json:"code"` // 错误码((0:成功, 1:失败, >1:错误码)) + Message string `json:"msg"` // 提示信息 + Data interface{} `json:"data"` // 返回数据(业务接口定义具体数据结构) + //Redirect string `json:"redirect"` // 引导客户端跳转到指定路由 +} + +// Json 返回标准JSON数据。 +func Json(r *ghttp.Request, code int, message string, data ...interface{}) { + var responseData interface{} + if len(data) > 0 { + responseData = data[0] + } else { + responseData = g.Map{} + } + r.Response.WriteJson(JsonRes{ + Code: code, + Message: message, + Data: responseData, + }) +} + +// JsonExit 返回标准JSON数据并退出当前HTTP执行函数。 +func JsonExit(r *ghttp.Request, code int, message string, data ...interface{}) { + Json(r, code, message, data...) + r.Exit() +} + +func dataReturn(r *ghttp.Request, code int, req ...interface{}) *JsonRes { + var msg string + var data interface{} + if len(req) > 0 { + msg = gconv.String(req[0]) + } + if len(req) > 1 { + data = req[1] + } + //msg = GetCodeMsg(code, msg) + if code != 1 && !gconv.Bool(r.GetCtxVar("api_code")) { + code = 0 + } + response := &JsonRes{ + //ID: r.GetCtxVar("RequestId").String(), + Code: code, + Message: msg, + Data: data, + } + r.SetParam("apiReturnRes", response) + return response +} + +// Auth 认证失败 +func Auth(r *ghttp.Request) { + res := dataReturn(r, 999, "请登录") + r.Response.WriteJsonExit(res) +} + +// Auth 认证失败 被冻结拉黑 +func AuthBlack(r *ghttp.Request) { + res := dataReturn(r, 888, "您的账号被冻结拉黑,请联系管理员") + r.Response.WriteJsonExit(res) +} + +// JsonRedirect 返回标准JSON数据引导客户端跳转。 +func JsonRedirect(r *ghttp.Request, code int, message, redirect string, data ...interface{}) { + responseData := interface{}(nil) + if len(data) > 0 { + responseData = data[0] + } + r.Response.WriteJson(JsonRes{ + Code: code, + Message: message, + Data: responseData, + //Redirect: redirect, + }) +} + +// JsonRedirectExit 返回标准JSON数据引导客户端跳转,并退出当前HTTP执行函数。 +func JsonRedirectExit(r *ghttp.Request, code int, message, redirect string, data ...interface{}) { + JsonRedirect(r, code, message, redirect, data...) + r.Exit() +} + +func SuccessWithData(r *ghttp.Request, data interface{}) { + res := dataReturn(r, 1, "ok", data) + r.Response.WriteJsonExit(res) +} + +// JsonResponse 数据返回通用JSON数据结构 +type JsonResponse struct { + //ID string `json:"id"` // + Code int `json:"code"` // 错误码((1:成功, 0:失败, >1:错误码)) + Message string `json:"message"` // 提示信息 + Data interface{} `json:"data,omitempty"` // 返回数据(业务接口定义具体数据结构) + Redirect string `json:"redirect,omitempty"` // 引导客户端跳转到指定路由 +}