home
This commit is contained in:
+10
-16
@@ -5,7 +5,6 @@ import (
|
||||
"OneAuth/libs/auth"
|
||||
"OneAuth/models"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/veypi/utils/cmd"
|
||||
"github.com/veypi/utils/log"
|
||||
"strconv"
|
||||
)
|
||||
@@ -20,6 +19,7 @@ func runInit(c *cli.Context) error {
|
||||
}
|
||||
|
||||
// 初始化项目
|
||||
var appid uint
|
||||
|
||||
func InitSystem() error {
|
||||
db()
|
||||
@@ -27,15 +27,9 @@ func InitSystem() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.CFG.APPID = self.ID
|
||||
cfg.CFG.APPKey = self.Key
|
||||
err = cmd.DumpCfg(cfg.Path, cfg.CFG)
|
||||
// TODO
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
appid = self.ID
|
||||
err = role(self.InitRoleID == 0)
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func db() {
|
||||
@@ -56,14 +50,14 @@ func selfApp() (*models.App, error) {
|
||||
self := &models.App{
|
||||
Name: "OA",
|
||||
Icon: "",
|
||||
UUID: "jU5Jo5hM",
|
||||
UUID: cfg.CFG.APPUUID,
|
||||
Des: "",
|
||||
Creator: 0,
|
||||
UserCount: 0,
|
||||
Hide: false,
|
||||
Host: "",
|
||||
UserRefreshUrl: "/",
|
||||
Key: "cB43wF94MLTksyBK",
|
||||
Key: cfg.CFG.APPKey,
|
||||
EnableRegister: true,
|
||||
EnableUserKey: true,
|
||||
EnableUser: true,
|
||||
@@ -86,7 +80,7 @@ func role(reset_init_role bool) error {
|
||||
}
|
||||
var err error
|
||||
adminRole := &models.Role{
|
||||
AppID: cfg.CFG.APPID,
|
||||
AppID: appid,
|
||||
Name: "admin",
|
||||
IsUnique: false,
|
||||
}
|
||||
@@ -96,7 +90,7 @@ func role(reset_init_role bool) error {
|
||||
}
|
||||
for _, na := range n {
|
||||
a := &models.Resource{
|
||||
AppID: cfg.CFG.APPID,
|
||||
AppID: appid,
|
||||
Name: na,
|
||||
Tag: "",
|
||||
Des: "",
|
||||
@@ -112,7 +106,7 @@ func role(reset_init_role bool) error {
|
||||
}
|
||||
}
|
||||
userRole := &models.Role{
|
||||
AppID: cfg.CFG.APPID,
|
||||
AppID: appid,
|
||||
Name: "user",
|
||||
IsUnique: false,
|
||||
}
|
||||
@@ -120,12 +114,12 @@ func role(reset_init_role bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = auth.BindRoleAuth(cfg.DB(), userRole.ID, authMap[auth.APP].ID, models.AuthRead, strconv.Itoa(int(cfg.CFG.APPID)))
|
||||
err = auth.BindRoleAuth(cfg.DB(), userRole.ID, authMap[auth.APP].ID, models.AuthRead, strconv.Itoa(int(appid)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if reset_init_role {
|
||||
return cfg.DB().Model(&models.App{}).Where("id = ?", cfg.CFG.APPID).Update("init_role_id", adminRole.ID).Error
|
||||
return cfg.DB().Model(&models.App{}).Where("id = ?", appid).Update("init_role_id", adminRole.ID).Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+17
-1
@@ -1 +1,17 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>oaf</title><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css"><link href="/css/chunk-6cfd0404.487f8d50.css" rel="prefetch"><link href="/js/about.a3055c06.js" rel="prefetch"><link href="/js/chunk-6cfd0404.65d5baaf.js" rel="prefetch"><link href="/app.b131f8d0f62acd99ab8e.js" rel="preload" as="script"><link href="/css/app.dafd5329.css" rel="preload" as="style"><link href="/css/chunk-vendors.dfe6062e.css" rel="preload" as="style"><link href="/js/chunk-vendors.83bac771.js" rel="preload" as="script"><link href="/css/chunk-vendors.dfe6062e.css" rel="stylesheet"><link href="/css/app.dafd5329.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but oaf doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.83bac771.js"></script><script src="/app.b131f8d0f62acd99ab8e.js"></script></body></html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite App</title>
|
||||
<script type="module" crossorigin src="/static/index.dddecd43.js"></script>
|
||||
<link rel="modulepreload" href="/static/vendor.ba3bd51d.js">
|
||||
<link rel="stylesheet" href="/static/vendor.3a295b6b.css">
|
||||
<link rel="stylesheet" href="/static/index.c49db26f.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+10
-30
@@ -6,16 +6,15 @@ import (
|
||||
"embed"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/veypi/OneBD"
|
||||
"github.com/veypi/OneBD/core"
|
||||
"github.com/veypi/OneBD/rfc"
|
||||
"github.com/veypi/utils/log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
//go:embed static
|
||||
//go:embed static/static
|
||||
var staticFiles embed.FS
|
||||
|
||||
//go:embed static/favicon.ico
|
||||
var icon []byte
|
||||
|
||||
//go:embed static/index.html
|
||||
var indexFile []byte
|
||||
|
||||
@@ -37,34 +36,15 @@ func RunWeb(c *cli.Context) error {
|
||||
LoggerPath: cfg.CFG.LoggerPath,
|
||||
LoggerLevel: ll,
|
||||
})
|
||||
app.Router().EmbedFile("/", indexFile)
|
||||
app.Router().EmbedDir("/", staticFiles, "static/")
|
||||
|
||||
// TODO media 文件需要检验权限
|
||||
//app.Router().SubRouter("/media/").Static("/", cfg.CFG.EXEDir+"/media")
|
||||
|
||||
app.Router().SetNotFoundFunc(func(m core.Meta) {
|
||||
f, err := os.Open(cfg.CFG.EXEDir + "/static/index.html")
|
||||
if err != nil {
|
||||
m.WriteHeader(rfc.StatusNotFound)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
info, err := f.Stat()
|
||||
if err != nil {
|
||||
m.WriteHeader(rfc.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if info.IsDir() {
|
||||
// TODO:: dir list
|
||||
m.WriteHeader(rfc.StatusNotFound)
|
||||
return
|
||||
}
|
||||
http.ServeContent(m, m.Request(), info.Name(), info.ModTime(), f)
|
||||
})
|
||||
|
||||
api.Router(app.Router().SubRouter("api"))
|
||||
|
||||
// TODO media 文件需要检验权限
|
||||
app.Router().SubRouter("/media/").Static("/", cfg.CFG.MediaDir)
|
||||
app.Router().EmbedDir("/static", staticFiles, "static/static/")
|
||||
app.Router().EmbedFile("/favicon.ico", icon)
|
||||
app.Router().EmbedFile("/*", indexFile)
|
||||
|
||||
log.Info().Msg("\nRouting Table\n" + app.Router().String())
|
||||
return app.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user