mirror of
https://github.com/sigmasternchen/threadule
synced 2025-03-15 08:09:01 +00:00
adding groups to users now works
This commit is contained in:
parent
82e4d233fe
commit
bb350e6c2d
3 changed files with 23 additions and 3 deletions
|
@ -6,6 +6,8 @@ type Data interface {
|
|||
CountUsers() (int64, error)
|
||||
CreateUser(user *models.User) error
|
||||
GetUserByUsername(username string) (*models.User, error)
|
||||
AddUserToGroup(user *models.User, group *models.Group) error
|
||||
DeleteUserFromGroup(user *models.User, group *models.Group) error
|
||||
|
||||
AddGroup(group *models.Group) error
|
||||
|
||||
|
|
|
@ -33,3 +33,18 @@ func (d *Data) GetUserByUsername(username string) (*models.User, error) {
|
|||
return &user, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Data) AddUserToGroup(user *models.User, group *models.Group) error {
|
||||
return d.db.
|
||||
Model(user).
|
||||
Omit("Groups.*").
|
||||
Association("Groups").
|
||||
Append([]models.Group{*group})
|
||||
}
|
||||
|
||||
func (d *Data) DeleteUserFromGroup(user *models.User, group *models.Group) error {
|
||||
return d.db.
|
||||
Model(user).
|
||||
Association("Groups").
|
||||
Delete(group)
|
||||
}
|
||||
|
|
|
@ -43,21 +43,24 @@ func (l *Logic) firstTimeSetup() error {
|
|||
}
|
||||
|
||||
adminUser := models.GetDefaultAdminUser()
|
||||
adminUser.Groups = []*models.Group{adminGroup}
|
||||
password := l.defaultPassword()
|
||||
adminUser.Password, err = l.hashPassword(password)
|
||||
|
||||
if err != nil {
|
||||
// if this fails we can't recover anyway
|
||||
l.ctx.Log.Fatal(err)
|
||||
}
|
||||
|
||||
err = l.ctx.Data.CreateUser(adminUser)
|
||||
if err != nil {
|
||||
l.ctx.Log.Errorf("couldn't create admin user: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = l.ctx.Data.AddUserToGroup(adminUser, adminGroup)
|
||||
if err != nil {
|
||||
l.ctx.Log.Errorf("couldn't add admin user to admin group: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("initial credentials:")
|
||||
fmt.Printf("Username: %s\n", adminUser.Username)
|
||||
fmt.Printf("Password: %s\n", password)
|
||||
|
|
Loading…
Reference in a new issue