added user authentication and updated README.md
This commit is contained in:
+39
-11
@@ -2,26 +2,35 @@
|
||||
|
||||
#include "database/UserRepository.h"
|
||||
#include "type/UserFilter.h"
|
||||
#include "type/SaltFilter.h"
|
||||
#include "utility/MetadataRetriever.h"
|
||||
#include "utility/PasswordEncryption.h"
|
||||
|
||||
namespace manager {
|
||||
UserManager::UserManager(const model::BinaryPath& bConf) : m_bConf(bConf) { }
|
||||
|
||||
|
||||
model::User UserManager::userDtoConv(dto::UserDto::ObjectWrapper& userDto)
|
||||
bool UserManager::doesUserExist(const model::User& user)
|
||||
{
|
||||
model::User user;
|
||||
database::UserRepository userRepo(m_bConf);
|
||||
|
||||
user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId->getValue();
|
||||
user.firstname = (userDto->firstname == nullptr) ? "" : userDto->firstname->c_str();
|
||||
user.lastname = (userDto->lastname == nullptr) ? "" : userDto->lastname->c_str();
|
||||
user.phone = (userDto->phone == nullptr) ? "" : userDto->phone->c_str();
|
||||
user.email = (userDto->email == nullptr) ? "" : userDto->email->c_str();
|
||||
user.username = (userDto->username == nullptr) ? "" : userDto->username->c_str();
|
||||
user.password = (userDto->password == nullptr) ? "" : userDto->password->c_str();
|
||||
return userRepo.doesUserRecordExist(user, type::UserFilter::username);
|
||||
}
|
||||
|
||||
return user;
|
||||
bool UserManager::validatePassword(const model::User& user)
|
||||
{
|
||||
database::UserRepository userRepo(m_bConf);
|
||||
model::User usr;
|
||||
usr.username = user.username;
|
||||
usr = userRepo.retrieveUserRecord(usr, type::UserFilter::username);
|
||||
|
||||
model::PassSec userSec;
|
||||
userSec.userId = usr.id;
|
||||
userSec = userRepo.retrieverUserSaltRecord(userSec, type::SaltFilter::userId);
|
||||
userSec.hashPassword = usr.password;
|
||||
|
||||
utility::PasswordEncryption passEnc;
|
||||
|
||||
return passEnc.isPasswordValid(user, userSec);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +62,26 @@ void UserManager::registerUser(model::User& user)
|
||||
|
||||
std::cout << usr.username << std::endl;
|
||||
usr = usrRepo.retrieveUserRecord(usr, type::UserFilter::username);
|
||||
hashed.hashPassword = usr.password;
|
||||
hashed.userId = usr.id;
|
||||
|
||||
usrRepo.saveUserSalt(hashed);
|
||||
printUser(usr);
|
||||
}
|
||||
|
||||
|
||||
model::User UserManager::userDtoConv(dto::UserDto::ObjectWrapper& userDto)
|
||||
{
|
||||
model::User user;
|
||||
|
||||
user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId->getValue();
|
||||
user.firstname = (userDto->firstname == nullptr) ? "" : userDto->firstname->c_str();
|
||||
user.lastname = (userDto->lastname == nullptr) ? "" : userDto->lastname->c_str();
|
||||
user.phone = (userDto->phone == nullptr) ? "" : userDto->phone->c_str();
|
||||
user.email = (userDto->email == nullptr) ? "" : userDto->email->c_str();
|
||||
user.username = (userDto->username == nullptr) ? "" : userDto->username->c_str();
|
||||
user.password = (userDto->password == nullptr) ? "" : userDto->password->c_str();
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user