mirror of
https://github.com/cuigh/swirl
synced 2024-12-28 14:51:57 +00:00
Close #37
This commit is contained in:
parent
077d017fd0
commit
d90ad871b0
@ -82,8 +82,11 @@ func systemSummarize(d *docker.Docker) web.HandlerFunc {
|
|||||||
|
|
||||||
func systemCreateAdmin(ub biz.UserBiz) web.HandlerFunc {
|
func systemCreateAdmin(ub biz.UserBiz) web.HandlerFunc {
|
||||||
return func(c web.Context) (err error) {
|
return func(c web.Context) (err error) {
|
||||||
user := &dao.User{}
|
args := &struct {
|
||||||
if err = c.Bind(user, true); err != nil {
|
Password string `json:"password"`
|
||||||
|
*dao.User
|
||||||
|
}{}
|
||||||
|
if err = c.Bind(args, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +98,8 @@ func systemCreateAdmin(ub biz.UserBiz) web.HandlerFunc {
|
|||||||
return errors.Coded(misc.ErrSystemInitialized, "system was already initialized")
|
return errors.Coded(misc.ErrSystemInitialized, "system was already initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user := args.User
|
||||||
|
user.Password = args.Password
|
||||||
user.Admin = true
|
user.Admin = true
|
||||||
user.Type = biz.UserTypeInternal
|
user.Type = biz.UserTypeInternal
|
||||||
_, err = ub.Create(ctx, user, nil)
|
_, err = ub.Create(ctx, user, nil)
|
||||||
|
@ -33,8 +33,8 @@ type systemBiz struct {
|
|||||||
|
|
||||||
func (b *systemBiz) Init(ctx context.Context) (err error) {
|
func (b *systemBiz) Init(ctx context.Context) (err error) {
|
||||||
if versions.LessThan(b.s.System.Version, app.Version) {
|
if versions.LessThan(b.s.System.Version, app.Version) {
|
||||||
// initialize database
|
// upgrade database
|
||||||
err = b.d.Init(ctx)
|
err = b.d.Upgrade(ctx)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = b.sb.Save(ctx, "system", data.Map{"version": app.Version}, nil)
|
err = b.sb.Save(ctx, "system", data.Map{"version": app.Version}, nil)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package biz
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/cuigh/auxo/data"
|
|
||||||
"github.com/cuigh/auxo/errors"
|
"github.com/cuigh/auxo/errors"
|
||||||
"github.com/cuigh/auxo/net/web"
|
"github.com/cuigh/auxo/net/web"
|
||||||
"github.com/cuigh/auxo/security/passwd"
|
"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) {
|
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.ID = createId()
|
||||||
user.Status = UserStatusActive
|
user.Status = UserStatusActive
|
||||||
user.CreatedAt = now()
|
user.CreatedAt = now()
|
||||||
|
@ -45,14 +45,19 @@ func New(addr string) (dao.Interface, error) {
|
|||||||
logger: log.Get("bolt"),
|
logger: log.Get("bolt"),
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = d.init(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
run.Schedule(time.Hour, d.SessionPrune, func(err interface{}) {
|
run.Schedule(time.Hour, d.SessionPrune, func(err interface{}) {
|
||||||
d.logger.Error("failed to clean up expired sessions: ", err)
|
d.logger.Error("failed to clean up expired sessions: ", err)
|
||||||
})
|
})
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) Init(ctx context.Context) error {
|
func (d *Dao) init() error {
|
||||||
buckets := []string{"chart", "dashboard", "event", "registry", "role", "setting", "stack", "user" /*"perm","session","template"*/}
|
buckets := []string{"chart", "dashboard", "event", "registry", "role", "setting", "stack", "user", "session" /*"perm","template"*/}
|
||||||
return d.db.Update(func(tx *bolt.Tx) error {
|
return d.db.Update(func(tx *bolt.Tx) error {
|
||||||
for _, bucket := range buckets {
|
for _, bucket := range buckets {
|
||||||
if _, err := tx.CreateBucketIfNotExists([]byte(bucket)); err != nil {
|
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 {
|
func (d *Dao) replace(bucket, key string, value interface{}) error {
|
||||||
return d.db.Update(func(tx *bolt.Tx) error {
|
return d.db.Update(func(tx *bolt.Tx) error {
|
||||||
buf, err := encode(value)
|
buf, err := encode(value)
|
||||||
|
@ -11,12 +11,12 @@ import (
|
|||||||
const Session = "session"
|
const Session = "session"
|
||||||
|
|
||||||
func (d *Dao) SessionGet(ctx context.Context, id string) (session *dao.Session, err error) {
|
func (d *Dao) SessionGet(ctx context.Context, id string) (session *dao.Session, err error) {
|
||||||
s := &dao.Session{}
|
session = &dao.Session{}
|
||||||
err = d.get(Session, id, s)
|
err = d.get(Session, id, session)
|
||||||
if err == ErrNoRecords {
|
if err == ErrNoRecords {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
s = nil
|
session = nil
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Register(name string, builder Builder) {
|
|||||||
|
|
||||||
// Interface is the interface that wraps all dao methods.
|
// Interface is the interface that wraps all dao methods.
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
Init(ctx context.Context) error
|
Upgrade(ctx context.Context) error
|
||||||
|
|
||||||
RoleGet(ctx context.Context, id string) (*Role, error)
|
RoleGet(ctx context.Context, id string) (*Role, error)
|
||||||
RoleSearch(ctx context.Context, name string) (roles []*Role, err error)
|
RoleSearch(ctx context.Context, name string) (roles []*Role, err error)
|
||||||
|
@ -90,7 +90,7 @@ func open(addr string) (*mongo.Database, error) {
|
|||||||
return client.Database(db), nil
|
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 {
|
for name, models := range indexes {
|
||||||
c := d.db.Collection(name)
|
c := d.db.Collection(name)
|
||||||
_, err = c.Indexes().CreateMany(ctx, models)
|
_, err = c.Indexes().CreateMany(ctx, models)
|
||||||
|
2
main.go
2
main.go
@ -33,7 +33,7 @@ var (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app.Name = "Swirl"
|
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.Desc = "A web management UI for Docker, focused on swarm cluster"
|
||||||
app.Action = func(ctx *app.Context) error {
|
app.Action = func(ctx *app.Context) error {
|
||||||
return run.Pipeline(misc.LoadOptions, initSystem, scaler.Start, startServer)
|
return run.Pipeline(misc.LoadOptions, initSystem, scaler.Start, startServer)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
ref="formLdap"
|
ref="formLdap"
|
||||||
label-placement="left"
|
label-placement="left"
|
||||||
style="padding: 4px 0 0 12px"
|
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-form-item :label="t('fields.enabled')" path="ldap.enabled" label-align="right">
|
||||||
<n-switch v-model:value="setting.ldap.enabled" />
|
<n-switch v-model:value="setting.ldap.enabled" />
|
||||||
@ -48,6 +48,7 @@
|
|||||||
<n-form-item
|
<n-form-item
|
||||||
:label="t('fields.bind_dn')"
|
:label="t('fields.bind_dn')"
|
||||||
label-align="right"
|
label-align="right"
|
||||||
|
label-width="auto"
|
||||||
:show-feedback="false"
|
:show-feedback="false"
|
||||||
v-show="setting.ldap.auth === 'bind'"
|
v-show="setting.ldap.auth === 'bind'"
|
||||||
>
|
>
|
||||||
|
1347
ui/yarn.lock
1347
ui/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user