create_admin.go 741 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package cli
  5. import (
  6. "fmt"
  7. "os"
  8. "github.com/miniflux/miniflux/model"
  9. "github.com/miniflux/miniflux/storage"
  10. )
  11. func createAdmin(store *storage.Storage) {
  12. user := model.NewUser()
  13. user.Username = os.Getenv("ADMIN_USERNAME")
  14. user.Password = os.Getenv("ADMIN_PASSWORD")
  15. user.IsAdmin = true
  16. if user.Username == "" || user.Password == "" {
  17. user.Username, user.Password = askCredentials()
  18. }
  19. if err := user.ValidateUserCreation(); err != nil {
  20. fmt.Println(err)
  21. os.Exit(1)
  22. }
  23. if err := store.CreateUser(user); err != nil {
  24. fmt.Println(err)
  25. os.Exit(1)
  26. }
  27. }