Files
wlan-cloud-ucentralsec/src/RESTAPI/RESTAPI_totp_handler.cpp
2023-02-21 12:23:18 -08:00

37 lines
942 B
C++

//
// Created by stephane bourque on 2022-01-31.
//
#include "RESTAPI_totp_handler.h"
#include "TotpCache.h"
namespace OpenWifi {
void RESTAPI_totp_handler::DoGet() {
auto Reset = GetBoolParameter("reset", false);
std::string QRCode;
if (TotpCache()->StartValidation(UserInfo_.userinfo, false, QRCode, Reset)) {
return SendFileContent(QRCode, "image/svg+xml", "qrcode.svg");
}
return BadRequest(RESTAPI::Errors::InvalidCommand);
}
void RESTAPI_totp_handler::DoPut() {
auto Value = GetParameter("value", "");
auto nextIndex = GetParameter("index", 0);
bool moreCodes = false;
RESTAPI::Errors::msg Err;
if (TotpCache()->ContinueValidation(UserInfo_.userinfo, false, Value, nextIndex, moreCodes,
Err)) {
Poco::JSON::Object Answer;
Answer.set("nextIndex", nextIndex);
Answer.set("moreCodes", moreCodes);
return ReturnObject(Answer);
}
return BadRequest(Err);
}
} // namespace OpenWifi