Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6450f8e62f | |||
| 6971663d33 | |||
| edd0c60e40 | |||
| 79d6b47aa8 |
+4
-16
@@ -10,8 +10,6 @@ Date:19-May-2026
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "AuthenticationManagementService.h"
|
#include "AuthenticationManagementService.h"
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
#include "Utility.h"
|
|
||||||
#include "DataStoreLockGuard.h"
|
|
||||||
|
|
||||||
User* AuthenticationManagementService::m_authenticatedUser = nullptr;
|
User* AuthenticationManagementService::m_authenticatedUser = nullptr;
|
||||||
|
|
||||||
@@ -26,12 +24,11 @@ Return type: bool - true if login successful, false otherwise
|
|||||||
*/
|
*/
|
||||||
bool AuthenticationManagementService::login(const std::string& username, const std::string& password)
|
bool AuthenticationManagementService::login(const std::string& username, const std::string& password)
|
||||||
{
|
{
|
||||||
DataStoreLockGuard lock(m_dataStore);
|
util::Map<std::string, User*> users = m_dataStore.getUsers();
|
||||||
auto& trackedUserMap = m_dataStore.getUsers();
|
int usersMapSize = users.getSize();
|
||||||
int trackedUserMapSize = trackedUserMap.getSize();
|
for (int index = 0; index < usersMapSize; index++)
|
||||||
for (int index = 0; index < trackedUserMapSize; index++)
|
|
||||||
{
|
{
|
||||||
User* user = trackedUserMap.getValueAt(index).data;
|
User* user = users.getValueAt(index);
|
||||||
if (username == user->getUserName())
|
if (username == user->getUserName())
|
||||||
{
|
{
|
||||||
if (password == user->getPassword())
|
if (password == user->getPassword())
|
||||||
@@ -77,18 +74,9 @@ Return type: void
|
|||||||
*/
|
*/
|
||||||
void AuthenticationManagementService::changePassword(const std::string& newPassword)
|
void AuthenticationManagementService::changePassword(const std::string& newPassword)
|
||||||
{
|
{
|
||||||
DataStoreLockGuard lock(m_dataStore);
|
|
||||||
auto& trackedUsersMap = m_dataStore.getUsers();
|
|
||||||
if (m_authenticatedUser == nullptr)
|
if (m_authenticatedUser == nullptr)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("There is no user currently logged in!");
|
throw std::runtime_error("There is no user currently logged in!");
|
||||||
}
|
}
|
||||||
int index = trackedUsersMap.find(m_authenticatedUser->getId());
|
|
||||||
if (index == -1)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("User does not exist!\n");
|
|
||||||
}
|
|
||||||
m_authenticatedUser->setPassword(newPassword);
|
m_authenticatedUser->setPassword(newPassword);
|
||||||
trackedUsersMap.getValueAt(index).state = RecordState::MODIFIED;
|
|
||||||
m_dataStore.saveUsers();
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -180,6 +180,7 @@ util::Vector<Notification*> UserManagementService::getUserNotifications(const st
|
|||||||
notificationsVector.push_back(notification);
|
notificationsVector.push_back(notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_dataStore.unlockDataStore();
|
||||||
return notificationsVector;
|
return notificationsVector;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user