Commit b6724199 authored by jan.koester's avatar jan.koester
Browse files

test

parent e57947b5
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@

#include <iostream>
#include <algorithm>
#include <cctype>
#include <confplus/exception.h>

#include "webedit_config.h"
@@ -150,10 +151,29 @@ webedit::Config::Config(const std::string &path) : confplus::Config(path) {
}

const blogi::AuthSource *webedit::Config::findAuthSource(const std::string &domain) const {
    auto normalizeDomain = [](std::string value) {
        for (auto &c : value)
            c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
        if (value == "admin.local")
            value = "admin";
        return value;
    };

    const std::string wanted = normalizeDomain(domain);

    for (auto &src : _authSources) {
        if (normalizeDomain(src.domain) == wanted)
            return &src;
    }

    if (!wanted.empty() && wanted == "admin") {
        for (auto &src : _authSources) {
        if (src.domain == domain)
            const std::string srcDomain = normalizeDomain(src.domain);
            if (srcDomain.empty() || srcDomain == "admin")
                return &src;
        }
    }

    if (!_authSources.empty())
        return &_authSources[0];
    return nullptr;