This commit is contained in:
cuigh 2022-02-10 11:09:03 +08:00
parent 077d017fd0
commit d90ad871b0
10 changed files with 683 additions and 707 deletions

View File

@ -82,8 +82,11 @@ func systemSummarize(d *docker.Docker) web.HandlerFunc {
func systemCreateAdmin(ub biz.UserBiz) web.HandlerFunc {
return func(c web.Context) (err error) {
user := &dao.User{}
if err = c.Bind(user, true); err != nil {
args := &struct {
Password string `json:"password"`
*dao.User
}{}
if err = c.Bind(args, true); err != nil {
return err
}
@ -95,6 +98,8 @@ func systemCreateAdmin(ub biz.UserBiz) web.HandlerFunc {
return errors.Coded(misc.ErrSystemInitialized, "system was already initialized")
}
user := args.User
user.Password = args.Password
user.Admin = true
user.Type = biz.UserTypeInternal
_, err = ub.Create(ctx, user, nil)

View File

@ -33,8 +33,8 @@ type systemBiz struct {
func (b *systemBiz) Init(ctx context.Context) (err error) {
if versions.LessThan(b.s.System.Version, app.Version) {
// initialize database
err = b.d.Init(ctx)
// upgrade database
err = b.d.Upgrade(ctx)
if err == nil {
err = b.sb.Save(ctx, "system", data.Map{"version": app.Version}, nil)
}

View File

@ -3,7 +3,6 @@ package biz
import (
"context"
"github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/errors"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/auxo/security/passwd"
@ -99,7 +98,6 @@ func (b *userBiz) FindPrivacy(ctx context.Context, loginName string) (privacy *U
}
func (b *userBiz) Create(ctx context.Context, user *dao.User, ctxUser web.User) (id string, err error) {
user.Tokens = data.Options{data.Option{Name: "test", Value: "abc123"}}
user.ID = createId()
user.Status = UserStatusActive
user.CreatedAt = now()

View File

@ -45,14 +45,19 @@ func New(addr string) (dao.Interface, error) {
logger: log.Get("bolt"),
db: db,
}
if err = d.init(); err != nil {
return nil, err
}
run.Schedule(time.Hour, d.SessionPrune, func(err interface{}) {
d.logger.Error("failed to clean up expired sessions: ", err)
})
return d, nil
}
func (d *Dao) Init(ctx context.Context) error {
buckets := []string{"chart", "dashboard", "event", "registry", "role", "setting", "stack", "user" /*"perm","session","template"*/}
func (d *Dao) init() error {
buckets := []string{"chart", "dashboard", "event", "registry", "role", "setting", "stack", "user", "session" /*"perm","template"*/}
return d.db.Update(func(tx *bolt.Tx) error {
for _, bucket := range buckets {
if _, err := tx.CreateBucketIfNotExists([]byte(bucket)); err != nil {
@ -63,6 +68,10 @@ func (d *Dao) Init(ctx context.Context) error {
})
}
func (d *Dao) Upgrade(ctx context.Context) error {
return nil
}
func (d *Dao) replace(bucket, key string, value interface{}) error {
return d.db.Update(func(tx *bolt.Tx) error {
buf, err := encode(value)

View File

@ -11,12 +11,12 @@ import (
const Session = "session"
func (d *Dao) SessionGet(ctx context.Context, id string) (session *dao.Session, err error) {
s := &dao.Session{}
err = d.get(Session, id, s)
session = &dao.Session{}
err = d.get(Session, id, session)
if err == ErrNoRecords {
return nil, nil
} else if err != nil {
s = nil
session = nil
}
return
}

View File

@ -20,7 +20,7 @@ func Register(name string, builder Builder) {
// Interface is the interface that wraps all dao methods.
type Interface interface {
Init(ctx context.Context) error
Upgrade(ctx context.Context) error
RoleGet(ctx context.Context, id string) (*Role, error)
RoleSearch(ctx context.Context, name string) (roles []*Role, err error)

View File

@ -90,7 +90,7 @@ func open(addr string) (*mongo.Database, error) {
return client.Database(db), nil
}
func (d *Dao) Init(ctx context.Context) (err error) {
func (d *Dao) Upgrade(ctx context.Context) (err error) {
for name, models := range indexes {
c := d.db.Collection(name)
_, err = c.Indexes().CreateMany(ctx, models)

View File

@ -33,7 +33,7 @@ var (
func main() {
app.Name = "Swirl"
app.Version = "1.0.0rc1"
app.Version = "1.0.0rc2"
app.Desc = "A web management UI for Docker, focused on swarm cluster"
app.Action = func(ctx *app.Context) error {
return run.Pipeline(misc.LoadOptions, initSystem, scaler.Start, startServer)

View File

@ -16,7 +16,7 @@
ref="formLdap"
label-placement="left"
style="padding: 4px 0 0 12px"
label-width="100"
label-width="auto"
>
<n-form-item :label="t('fields.enabled')" path="ldap.enabled" label-align="right">
<n-switch v-model:value="setting.ldap.enabled" />
@ -48,6 +48,7 @@
<n-form-item
:label="t('fields.bind_dn')"
label-align="right"
label-width="auto"
:show-feedback="false"
v-show="setting.ldap.auth === 'bind'"
>

File diff suppressed because it is too large Load Diff