配置更新,去除无用包
This commit is contained in:
+51
-47
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/kataras/iris/v12/context"
|
||||
"io"
|
||||
"pet-house.com/business/models"
|
||||
"pet-house.com/business/utils"
|
||||
"pet-house.com/core/server/database"
|
||||
"pet-house.com/core/server/web"
|
||||
"pet-house.com/core/server/web/web_iris"
|
||||
@@ -30,54 +31,57 @@ var defaultHeadImgUrl = "http://" + web.CONFIG.System.Addr + "/static/img/202403
|
||||
|
||||
// 登录
|
||||
func (p DefParty) login() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(AuthBase+"/login", func(ctx *context.Context) {
|
||||
body, _ := io.ReadAll(ctx.Request().Body)
|
||||
var loginRequest LoginRequest
|
||||
json.Unmarshal(body, &loginRequest)
|
||||
if len(loginRequest.Code) == 0 {
|
||||
ParamError.Fail(ctx, nil)
|
||||
return
|
||||
}
|
||||
//获取code
|
||||
/*info, err := utils.GetWxUserInfo(loginRequest.Code)
|
||||
if err != nil {
|
||||
utils.LoginError.DefFail(ctx, loginRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if info.ErrCode != 0 {
|
||||
utils.LoginError.DefFail(ctx, loginRequest, info.ErrMsg)
|
||||
return
|
||||
}*/
|
||||
var userInfo models.User
|
||||
database.Instance().Model(&models.User{}).Where("open_id = ? or union_id = ?", "1", "2").Find(&userInfo)
|
||||
if userInfo.Id == 0 {
|
||||
newUser := models.User{
|
||||
NickName: defaultNickName,
|
||||
HeadImgUrl: defaultHeadImgUrl,
|
||||
Amount: 0,
|
||||
OpenId: NextId.Generate().String(),
|
||||
UnionId: NextId.Generate().String(),
|
||||
UserType: 0,
|
||||
Mobile: "",
|
||||
Role: 0,
|
||||
return web_iris.Party{
|
||||
Perfix: p.Perfix,
|
||||
PartyFunc: func(index iris.Party) {
|
||||
index.Post(AuthBase+"/login", func(ctx *context.Context) {
|
||||
body, _ := io.ReadAll(ctx.Request().Body)
|
||||
var loginRequest LoginRequest
|
||||
json.Unmarshal(body, &loginRequest)
|
||||
if len(loginRequest.Code) == 0 {
|
||||
ParamError.Fail(ctx, nil)
|
||||
return
|
||||
}
|
||||
database.Instance().Model(&models.User{}).Create(&newUser)
|
||||
userInfo = newUser
|
||||
}
|
||||
token := genToken(userInfo.Id)
|
||||
response := LoginResponse{
|
||||
Token: token,
|
||||
Uid: userInfo.Id,
|
||||
NickName: userInfo.NickName,
|
||||
HeadImgUrl: userInfo.HeadImgUrl,
|
||||
Amount: userInfo.Amount,
|
||||
Role: userInfo.Role,
|
||||
}
|
||||
response.UserPets = GetUserPets(userInfo.Id)
|
||||
Success(ctx, loginRequest, response)
|
||||
})
|
||||
}}
|
||||
//获取code
|
||||
info, err := utils.GetWxUserInfo(loginRequest.Code)
|
||||
if err != nil {
|
||||
LoginError.DefFail(ctx, loginRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if info.ErrCode != 0 {
|
||||
LoginError.DefFail(ctx, loginRequest, info.ErrMsg)
|
||||
return
|
||||
}
|
||||
var userInfo models.User
|
||||
database.Instance().Model(&models.User{}).Where("open_id = ? or union_id = ?", "1", "2").Find(&userInfo)
|
||||
if userInfo.Id == 0 {
|
||||
newUser := models.User{
|
||||
NickName: defaultNickName,
|
||||
HeadImgUrl: defaultHeadImgUrl,
|
||||
Amount: 0,
|
||||
OpenId: NextId.Generate().String(),
|
||||
UnionId: NextId.Generate().String(),
|
||||
UserType: 0,
|
||||
Mobile: "",
|
||||
Role: 0,
|
||||
}
|
||||
database.Instance().Model(&models.User{}).Create(&newUser)
|
||||
userInfo = newUser
|
||||
}
|
||||
token := genToken(userInfo.Id)
|
||||
response := LoginResponse{
|
||||
Token: token,
|
||||
Uid: userInfo.Id,
|
||||
NickName: userInfo.NickName,
|
||||
HeadImgUrl: userInfo.HeadImgUrl,
|
||||
Amount: userInfo.Amount,
|
||||
Role: userInfo.Role,
|
||||
}
|
||||
response.UserPets = GetUserPets(userInfo.Id)
|
||||
Success(ctx, loginRequest, response)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type GetUserInfoResponse struct {
|
||||
|
||||
@@ -46,6 +46,7 @@ var (
|
||||
ServiceAddrNotExistError = Error{Code: 208, Msg: "服务地址区域,请重新配置地址"}
|
||||
NotInServiceExistError = Error{Code: 209, Msg: "不在服务范围"}
|
||||
OrderCreateError = Error{Code: 210, Msg: "订单创建失败"}
|
||||
LoginError = Error{Code: 211, Msg: "授权登录失败"}
|
||||
)
|
||||
|
||||
func Success(ctx *context.Context, request any, data any) {
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
_ "github.com/GoAdminGroup/go-admin/adapter/iris"
|
||||
"github.com/GoAdminGroup/go-admin/engine"
|
||||
"github.com/GoAdminGroup/go-admin/examples/datamodel"
|
||||
"github.com/GoAdminGroup/go-admin/modules/config"
|
||||
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
|
||||
"github.com/GoAdminGroup/go-admin/modules/language"
|
||||
"github.com/GoAdminGroup/go-admin/plugins/example"
|
||||
"github.com/GoAdminGroup/go-admin/template"
|
||||
"github.com/GoAdminGroup/go-admin/template/chartjs"
|
||||
_ "github.com/GoAdminGroup/themes/adminlte"
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/context"
|
||||
"go.uber.org/zap"
|
||||
@@ -20,7 +10,6 @@ import (
|
||||
"pet-house.com/core/server/web/web_iris"
|
||||
"pet-house.com/core/server/zap_server"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Root = "/pet-house"
|
||||
@@ -49,57 +38,6 @@ func ModuleInit() {
|
||||
DataInit()
|
||||
DataCacheJob()
|
||||
}
|
||||
|
||||
func GoAdminInit(app *iris.Application) {
|
||||
eng := engine.Default()
|
||||
|
||||
cfg := config.Config{
|
||||
Env: config.EnvLocal,
|
||||
Databases: config.DatabaseList{
|
||||
"default": {
|
||||
Dsn: database.CONFIG.Dsn(),
|
||||
MaxIdleConns: 5,
|
||||
MaxOpenConns: 10,
|
||||
ConnMaxLifetime: time.Hour,
|
||||
Driver: config.DriverMysql,
|
||||
},
|
||||
},
|
||||
Theme: "adminlte",
|
||||
UrlPrefix: Root + "/admin",
|
||||
Store: config.Store{
|
||||
Path: "./static/uploads",
|
||||
Prefix: "/static/uploads",
|
||||
},
|
||||
IndexUrl: Root + "/admin",
|
||||
Debug: true,
|
||||
Language: language.CN,
|
||||
Title: "pet-house",
|
||||
LoginTitle: "pet-house-admin",
|
||||
Logo: "<span class=\"logo-lg\"><b>Pet</b>Admin</span>",
|
||||
}
|
||||
|
||||
template.AddComp(chartjs.NewChart())
|
||||
examplePlugin := example.NewExample()
|
||||
|
||||
if err := eng.AddConfig(&cfg).
|
||||
AddGenerators(datamodel.Generators).
|
||||
AddDisplayFilterXssJsFilter().
|
||||
// add generator, first parameter is the url prefix of table when visit.
|
||||
// example:
|
||||
//
|
||||
// "user" => http://localhost:9033/admin/info/user
|
||||
//
|
||||
AddGenerator("user", datamodel.GetUserTable).
|
||||
AddPlugins(examplePlugin).Use(app); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
app.HandleDir("/static/uploads", "./static/uploads", iris.DirOptions{
|
||||
IndexName: "/index.html",
|
||||
ShowList: false,
|
||||
})
|
||||
eng.HTML("GET", Root+"/admin", datamodel.GetContent)
|
||||
}
|
||||
|
||||
func FrontAuth(ctx *context.Context) {
|
||||
if strings.Contains(ctx.Path(), ExcludeBase) {
|
||||
ctx.Next()
|
||||
|
||||
Reference in New Issue
Block a user