74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <tl/expected.hpp>
|
|
|
|
#include <variant>
|
|
|
|
#include <rublon/CoreHandler.hpp>
|
|
#include <rublon/pam_action.hpp>
|
|
#include <rublon/pam.hpp>
|
|
|
|
#include "OTP.hpp"
|
|
#include "SMS.hpp"
|
|
|
|
namespace rublon{
|
|
|
|
class Method {
|
|
std::string tid;
|
|
|
|
public:
|
|
Method() {}
|
|
|
|
template < typename Handler_t >
|
|
tl::expected< int , PamAction > fire(const CoreHandlerInterface< Handler_t > & coreHandler) {}
|
|
|
|
private:
|
|
std::variant< method::OTP, method::SMS > _impl;
|
|
};
|
|
|
|
template < typename Pam_t = LinuxPam >
|
|
class MethodFactory {
|
|
const Pam_t & pam;
|
|
|
|
public:
|
|
MethodFactory(const Pam_t & pam) : pam{pam} {}
|
|
|
|
template < typename Array_t >
|
|
tl::expected< Method, PamAction > create(const Array_t & methods) const {
|
|
rublon::debugLog("[TMP] ",__PRETTY_FUNCTION__);
|
|
std::pmr::map< int, std::pmr::string > methods_id;
|
|
pam.print("%s", "");
|
|
int i;
|
|
for(const auto & method : methods) {
|
|
if(method == "email") {
|
|
pam.print("%d: Email Link", i + 1);
|
|
methods_id[++i] = "email";
|
|
}
|
|
if(method == "qrcode") {
|
|
pam.print("%d: QR Code", i + 1);
|
|
methods_id[++i] = "qrcode";
|
|
}
|
|
if(method == "totp") {
|
|
pam.print("%d: Mobile TOTP", i + 1);
|
|
methods_id[++i] = "totp";
|
|
}
|
|
if(method == "push") {
|
|
pam.print("%d: Mobile Push", i + 1);
|
|
methods_id[++i] = "push";
|
|
}
|
|
if(method == "sms") {
|
|
pam.print("%d: SMS code", i + 1);
|
|
methods_id[++i] = "sms";
|
|
}
|
|
}
|
|
|
|
auto methodid = pam.scan([](char * userinput) { return std::stoi(userinput); }, "\nSelect method [1-%d]: ", methods.Size());
|
|
|
|
pam.print("you selected: %s", methods_id.count(methodid.value_or(0)) ? methods_id.at(methodid.value_or(0)).c_str() : "unknown option");
|
|
|
|
return tl::unexpected{PamAction::accept};
|
|
}
|
|
};
|
|
|
|
}
|