Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
45 lines
1.7 KiB
C++
45 lines
1.7 KiB
C++
#include <settings/wifi/wifi.hpp>
|
|
#include <colors.h>
|
|
#include <json.hpp>
|
|
#include <types.hpp>
|
|
#include <QR-Code-generator/qrcodegen.hpp>
|
|
#include <QR-Code-generator/qrtosvg.hpp>
|
|
#include <auth/auth.hpp>
|
|
#include <helpers.hpp>
|
|
#include <config/config.hpp>
|
|
|
|
namespace api
|
|
{
|
|
namespace settings
|
|
{
|
|
namespace wifi
|
|
{
|
|
void get_wifi_qr(const httplib::Request& request, httplib::Response& response)
|
|
{
|
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
|
response.set_header("Access-Control-Allow-Origin", "*");
|
|
if (!check_body(request))
|
|
{
|
|
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
|
return;
|
|
}
|
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
|
|
|
if (!authenticate(json_body["token"]))
|
|
{
|
|
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
|
return;
|
|
}
|
|
std::string wifi_password = config::config.getConfig()["settings"]["wifi"]["password"];
|
|
std::string wifi_name = config::config.getConfig()["settings"]["wifi"]["name"];
|
|
std::stringstream toqrstring;
|
|
toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";";
|
|
|
|
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
|
|
std::string responsedata = toSvgString(qr0, 4);
|
|
response.set_content(responsedata, SVG_TYPE);
|
|
}
|
|
}
|
|
}
|
|
}
|