2024-12-16 18:58:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
#include "../defines.hpp"
|
2025-04-02 22:13:22 +02:00
|
|
|
#include "../core/Timer.hpp"
|
2025-03-05 08:35:43 +01:00
|
|
|
|
2024-12-16 18:58:36 +00:00
|
|
|
enum eAuthImplementations {
|
|
|
|
|
AUTH_IMPL_PAM = 0,
|
|
|
|
|
AUTH_IMPL_FINGERPRINT = 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IAuthImplementation {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~IAuthImplementation() = default;
|
|
|
|
|
|
|
|
|
|
virtual eAuthImplementations getImplType() = 0;
|
|
|
|
|
virtual void init() = 0;
|
|
|
|
|
virtual void handleInput(const std::string& input) = 0;
|
|
|
|
|
virtual bool checkWaiting() = 0;
|
|
|
|
|
virtual std::optional<std::string> getLastFailText() = 0;
|
|
|
|
|
virtual std::optional<std::string> getLastPrompt() = 0;
|
|
|
|
|
virtual void terminate() = 0;
|
|
|
|
|
|
|
|
|
|
friend class CAuth;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CAuth {
|
|
|
|
|
public:
|
|
|
|
|
CAuth();
|
|
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
void start();
|
2024-12-16 18:58:36 +00:00
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
void submitInput(const std::string& input);
|
|
|
|
|
bool checkWaiting();
|
2024-12-16 18:58:36 +00:00
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
const std::string& getCurrentFailText();
|
2024-12-16 18:58:36 +00:00
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
std::optional<std::string> getFailText(eAuthImplementations implType);
|
|
|
|
|
std::optional<std::string> getPrompt(eAuthImplementations implType);
|
|
|
|
|
size_t getFailedAttempts();
|
2024-12-16 18:58:36 +00:00
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
SP<IAuthImplementation> getImpl(eAuthImplementations implType);
|
2024-12-16 18:58:36 +00:00
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
void terminate();
|
2024-12-16 18:58:36 +00:00
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
void enqueueUnlock();
|
|
|
|
|
void enqueueFail(const std::string& failText, eAuthImplementations implType);
|
2024-12-16 18:58:36 +00:00
|
|
|
|
2025-04-02 22:13:22 +02:00
|
|
|
void resetDisplayFail();
|
|
|
|
|
|
2025-01-12 17:18:18 +00:00
|
|
|
// Should only be set via the main thread
|
|
|
|
|
bool m_bDisplayFailText = false;
|
2024-12-16 18:58:36 +00:00
|
|
|
|
|
|
|
|
private:
|
2025-01-12 17:18:18 +00:00
|
|
|
struct {
|
|
|
|
|
std::string failText = "";
|
|
|
|
|
eAuthImplementations failSource = AUTH_IMPL_PAM;
|
|
|
|
|
size_t failedAttempts = 0;
|
|
|
|
|
} m_sCurrentFail;
|
|
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
std::vector<SP<IAuthImplementation>> m_vImpls;
|
2025-04-02 22:13:22 +02:00
|
|
|
std::shared_ptr<CTimer> m_resetDisplayFailTimer;
|
2024-12-16 18:58:36 +00:00
|
|
|
};
|
|
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
inline UP<CAuth> g_pAuth;
|