reset_password.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 // import "miniflux.app/cli"
  5. import (
  6. "fmt"
  7. "os"
  8. "miniflux.app/model"
  9. "miniflux.app/storage"
  10. "miniflux.app/validator"
  11. )
  12. func resetPassword(store *storage.Storage) {
  13. username, password := askCredentials()
  14. user, err := store.UserByUsername(username)
  15. if err != nil {
  16. fmt.Fprintf(os.Stderr, "%v\n", err)
  17. os.Exit(1)
  18. }
  19. if user == nil {
  20. fmt.Fprintf(os.Stderr, "User not found!\n")
  21. os.Exit(1)
  22. }
  23. userModificationRequest := &model.UserModificationRequest{
  24. Password: &password,
  25. }
  26. if validationErr := validator.ValidateUserModification(store, user.ID, userModificationRequest); validationErr != nil {
  27. fmt.Fprintf(os.Stderr, "%s\n", validationErr)
  28. os.Exit(1)
  29. }
  30. user.Password = password
  31. if err := store.UpdateUser(user); err != nil {
  32. fmt.Fprintf(os.Stderr, "%v\n", err)
  33. os.Exit(1)
  34. }
  35. fmt.Println("Password changed!")
  36. }