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