Refactor authentication: replace tuple with DTO, namespace config
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "ZenvyController.h"
|
||||
|
||||
//Authentication
|
||||
AuthenticationContext ZenvyController::login(const std::string& email, const std::string& password)
|
||||
AuthenticationDTO ZenvyController::login(const std::string& email, const std::string& password)
|
||||
{
|
||||
return m_authenticationManagementService->login(email, password);
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
#include "TicketManagementService.h"
|
||||
#include "Enums.h"
|
||||
|
||||
using AuthenticationContext = std::tuple<Enums::LoginStatus, Enums::EmployeeType, Enums::EmployeeDesignation>;
|
||||
|
||||
class ZenvyController
|
||||
{
|
||||
private:
|
||||
@@ -42,7 +40,7 @@ public:
|
||||
m_ticketManagementService(std::make_shared<TicketManagementService>()) {};
|
||||
|
||||
//Authentication
|
||||
AuthenticationContext login(const std::string& email, const std::string& password);
|
||||
AuthenticationDTO login(const std::string& email, const std::string& password);
|
||||
void logout();
|
||||
void changePassword(const std::string&);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace Config
|
||||
{
|
||||
namespace Authentication
|
||||
{
|
||||
constexpr const char* DEFAULT_PASSWORD = "password";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "AuthenticationManagementService.h"
|
||||
#include "ApplicationConfig.h"
|
||||
|
||||
std::tuple<Enums::LoginStatus, Enums::EmployeeType, Enums::EmployeeDesignation> AuthenticationManagementService::login(const std::string& email, const std::string& password)
|
||||
AuthenticationDTO AuthenticationManagementService::login(const std::string& email, const std::string& password)
|
||||
{
|
||||
employeeMap& employees = m_dataStore.getEmployees();
|
||||
Enums::LoginStatus loginStatus = Enums::LoginStatus::USER_NOT_FOUND;
|
||||
@@ -14,7 +14,7 @@ std::tuple<Enums::LoginStatus, Enums::EmployeeType, Enums::EmployeeDesignation>
|
||||
{
|
||||
if (employee.second->getEmployeePassword() == password)
|
||||
{
|
||||
if (password == Config::DEFAULT_PASSWORD)
|
||||
if (password == Config::Authentication::DEFAULT_PASSWORD)
|
||||
{
|
||||
loginStatus = Enums::LoginStatus::FIRST_LOGIN;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
#include "DataStore.h"
|
||||
#include "Enums.h"
|
||||
|
||||
using AuthenticationDTO = std::tuple<Enums::LoginStatus, Enums::EmployeeType, Enums::EmployeeDesignation>;
|
||||
|
||||
class AuthenticationManagementService
|
||||
{
|
||||
private:
|
||||
DataStore& m_dataStore;
|
||||
public:
|
||||
AuthenticationManagementService() : m_dataStore(DataStore::getInstance()) {};
|
||||
std::tuple<Enums::LoginStatus, Enums::EmployeeType, Enums::EmployeeDesignation> login(const std::string& username, const std::string& password);
|
||||
AuthenticationDTO login(const std::string& username, const std::string& password);
|
||||
void logout();
|
||||
void changePassword(const std::string&);
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ bool util::isEmailValid(const std::string& email) {
|
||||
|
||||
bool util::isPasswordValid(const std::string& password)
|
||||
{
|
||||
if (password == Config::DEFAULT_PASSWORD)
|
||||
if (password == Config::Authentication::DEFAULT_PASSWORD)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ void UserInterface::login()
|
||||
util::read(email);
|
||||
std::cout << "Enter password: ";
|
||||
util::read(password);
|
||||
AuthenticationContext authenticationContext = m_controller->login(email, password);
|
||||
AuthenticationDTO authenticationContext = m_controller->login(email, password);
|
||||
Enums::LoginStatus loginStatus = std::get<0>(authenticationContext);
|
||||
Enums::EmployeeType employeeType = std::get<1>(authenticationContext);
|
||||
Enums::EmployeeDesignation employeeDesignation = std::get<2>(authenticationContext);
|
||||
|
||||
Reference in New Issue
Block a user