Working on User authentication

This commit is contained in:
kdeng00
2019-09-22 23:57:14 -04:00
parent 89ed9f9252
commit 4bd794c288
19 changed files with 627 additions and 11 deletions
+40
View File
@@ -0,0 +1,40 @@
#ifndef REGISTERCONTROLLER_H_
#define REGISTERCONTROLLER_H_
#include <iostream>
#include <memory>
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
#include "dto/LoginResultDto.hpp"
#include "manager/UserManager.h"
#include "model/Models.h"
namespace controller
{
class RegisterController : public oatpp::web::server::api::ApiController
{
public:
RegisterController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
#include OATPP_CODEGEN_BEGIN(ApiController)
ENDPOINT("POST", "api/v1/register", registerUser, BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
manager::UserManager usrMgr(m_bConf);
auto user = usrMgr.userDtoConv(usr);
usrMgr.registerUser(user);
return createResponse(Status::CODE_200, "Reg");
}
#include OATPP_CODEGEN_END(ApiController)
private:
model::BinaryPath m_bConf;
};
}
#endif
+60
View File
@@ -0,0 +1,60 @@
#ifndef USERREPOSITORY_H_
#define USERREPOSITORY_H_
#include <iostream>
#include <memory>
#include "database/BaseRepository.h"
#include "model/Models.h"
#include "type/UserFilter.h"
namespace database {
class UserRepository : BaseRepository {
public:
UserRepository(const model::BinaryPath&);
model::User retrieveUserRecord(model::User&, type::UserFilter);
void saveUserRecord(const model::User&);
private:
struct UserLengths;
struct UserLengths
{
unsigned long firstnameLength;
unsigned long lastnameLength;
unsigned long phoneLength;
unsigned long emailLength;
unsigned long usernameLength;
unsigned long passwordLength;
};
struct UserVals
{
/**
std::shared_ptr<char*> firstname;
std::shared_ptr<char*> lastname;
std::shared_ptr<char*> phone;
std::shared_ptr<char*> email;
std::shared_ptr<char*> username;
std::shared_ptr<char*> password;
*/
char firstname[1024];
char lastname[1024];
char phone[1024];
char email[1024];
char username[1024];
char password[1024];
};
std::shared_ptr<MYSQL_BIND> insertUserValues(const model::User&, std::shared_ptr<UserLengths>);
std::shared_ptr<MYSQL_BIND> valueBind(model::User&, std::shared_ptr<UserVals>);
std::shared_ptr<MYSQL_BIND> valueBind(model::User&, UserVals&);
std::shared_ptr<MYSQL_BIND> valueBind(model::User&);
std::shared_ptr<UserLengths> fetchUserLengths(const model::User&);
std::shared_ptr<UserVals> fetchUserVals();
model::User parseRecord(MYSQL_STMT*);
};
}
#endif
+5
View File
@@ -24,6 +24,11 @@ namespace dto
{
DTO_INIT(UserDto, Object)
DTO_FIELD(Int32, userId);
DTO_FIELD(String, firstname);
DTO_FIELD(String, lastname);
DTO_FIELD(String, phone);
DTO_FIELD(String, email);
DTO_FIELD(String, username);
DTO_FIELD(String, password);
};
+25
View File
@@ -0,0 +1,25 @@
#ifndef USERMANAGER_H_
#define USERMANAGER_H_
#include <iostream>
#include "dto/LoginResultDto.hpp"
#include "model/Models.h"
namespace manager
{
class UserManager
{
public:
UserManager(const model::BinaryPath&);
model::User userDtoConv(dto::UserDto::ObjectWrapper&);
void printUser(const model::User&);
void registerUser(model::User&);
private:
model::BinaryPath m_bConf;
};
}
#endif
+17
View File
@@ -116,6 +116,23 @@ namespace model
int expiration;
};
struct User
{
int id;
std::string firstname;
std::string lastname;
std::string email;
std::string phone;
std::string username;
std::string password;
};
struct PassSec
{
std::string hashPassword;
std::string salt;
};
struct AuthCredentials
{
std::string domain;
+12
View File
@@ -0,0 +1,12 @@
#ifndef SALTFILTER_H_
#define SALTFILTER_H_
namespace type {
enum class SaltFilter
{
id = 0,
salt
};
}
#endif
+12
View File
@@ -0,0 +1,12 @@
#ifndef USERFILTER_H_
#define USERFILTER_H_
namespace type {
enum class UserFilter
{
id = 0,
username
};
}
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef PASSWORDENCRYPTION_H_
#define PASSWORDENCRYPTION_H_
#include <string>
#include "model/Models.h"
namespace utility {
class PasswordEncryption {
public:
model::PassSec hashPassword(const model::User&);
private:
int saltSize();
};
}
#endif
+4
View File
@@ -1,6 +1,8 @@
#ifndef INITIALIZATION_H_
#define INITIALIZATION_H_
#include <string>
#include "model/Models.h"
namespace verify
@@ -8,6 +10,8 @@ namespace verify
class Initialization
{
public:
static bool skipVerification(const std::string&);
static void checkIcarus(const model::BinaryPath&);
private:
static bool confirmConfigAuth(const model::BinaryPath&);