64 lines
1.5 KiB
C++
Executable File
64 lines
1.5 KiB
C++
Executable File
|
|
|
|
|
|
#include "client_message.h"
|
|
#include "json_keys.h"
|
|
#include "message_handler.h"
|
|
|
|
namespace LtsProjectionWorkstation
|
|
{
|
|
|
|
|
|
|
|
LtsWebSocket::AbstractClientMessage *ClientMessageFactory::createMessage(LtsWebSocket::ReplyHandler *client, const QString &message)
|
|
{
|
|
LtsWebSocket::AbstractClientMessage *result = checkAttributes(client, message);
|
|
|
|
if (result)
|
|
return result;
|
|
|
|
if (m_type == JsonKeys::LOGIN_REQUEST())
|
|
result = new LoginRequest(m_messageHandler, client, m_type, m_uuid, m_data);
|
|
|
|
if (m_type == JsonKeys::LOGOUT_REQUEST())
|
|
result = new LoginRequest(m_messageHandler, client, m_type, m_uuid, m_data);
|
|
|
|
return checkResult(client, message, result);
|
|
}
|
|
|
|
|
|
|
|
void LoginRequest::process()
|
|
{
|
|
if (hasValidData())
|
|
{
|
|
int userId = m_data.toObject().value(JsonKeys::USER_ID()).toInt(-1),
|
|
userPriority = m_data.toObject().value(JsonKeys::USER_PRIORITY()).toInt(-1),
|
|
exerciseId = m_data.toObject().value(JsonKeys::EXERCISE_ID()).toInt(-1);
|
|
m_client->addReply(m_messageHandler->handleLoginRequest(userId, userPriority, exerciseId));
|
|
}
|
|
}
|
|
|
|
bool LoginRequest::hasValidData() const
|
|
{
|
|
return m_data.isObject()
|
|
&& m_data.toObject().value(JsonKeys::USER_ID()).toInt(-1) > -1
|
|
&& m_data.toObject().value(JsonKeys::USER_PRIORITY()).toInt(-1) > -1
|
|
&& m_data.toObject().value(JsonKeys::EXERCISE_ID()).toInt(-1) > -1;
|
|
}
|
|
|
|
|
|
|
|
void LogoutRequest::process()
|
|
{
|
|
m_client->addReply(m_messageHandler->handleLogoutRequest());
|
|
}
|
|
|
|
bool LogoutRequest::hasValidData() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
|
|
}
|