Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

  1. #include <SecuritySettingsService.h>
  2. SecuritySettingsService::SecuritySettingsService(AsyncWebServer* server, FS* fs) :
  3. AdminSettingsService(server, fs, this, SECURITY_SETTINGS_PATH, SECURITY_SETTINGS_FILE),
  4. SecurityManager() {
  5. }
  6. SecuritySettingsService::~SecuritySettingsService() {
  7. }
  8. void SecuritySettingsService::readFromJsonObject(JsonObject& root) {
  9. // secret
  10. _jwtHandler.setSecret(root["jwt_secret"] | DEFAULT_JWT_SECRET);
  11. // users
  12. _users.clear();
  13. if (root["users"].is<JsonArray>()) {
  14. for (JsonVariant user : root["users"].as<JsonArray>()) {
  15. _users.push_back(User(user["username"], user["password"], user["admin"]));
  16. }
  17. }
  18. }
  19. void SecuritySettingsService::writeToJsonObject(JsonObject& root) {
  20. // secret
  21. root["jwt_secret"] = _jwtHandler.getSecret();
  22. // users
  23. JsonArray users = root.createNestedArray("users");
  24. for (User _user : _users) {
  25. JsonObject user = users.createNestedObject();
  26. user["username"] = _user.getUsername();
  27. user["password"] = _user.getPassword();
  28. user["admin"] = _user.isAdmin();
  29. }
  30. }