Almost completed registration

* added missing bits of serverside code;
 * added fronted in client;
 * removed demo python scripts;
This commit is contained in:
Fabio Bas 2015-05-23 20:13:03 +02:00
parent 735fcbf311
commit 5ace0dd892
20 changed files with 585 additions and 112 deletions

View file

@ -6,6 +6,7 @@
#include "pb/commands.pb.h"
#include "pb/session_commands.pb.h"
#include "pb/response_login.pb.h"
#include "pb/response_register.pb.h"
#include "pb/server_message.pb.h"
#include "pb/event_server_identification.pb.h"
@ -28,6 +29,7 @@ RemoteClient::RemoteClient(QObject *parent)
connect(this, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed)), this, SLOT(processConnectionClosedEvent(Event_ConnectionClosed)));
connect(this, SIGNAL(sigConnectToServer(QString, unsigned int, QString, QString)), this, SLOT(doConnectToServer(QString, unsigned int, QString, QString)));
connect(this, SIGNAL(sigDisconnectFromServer()), this, SLOT(doDisconnectFromServer()));
connect(this, SIGNAL(sigRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)), this, SLOT(doRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)));
}
RemoteClient::~RemoteClient()
@ -52,8 +54,6 @@ void RemoteClient::slotConnected()
sendCommandContainer(CommandContainer());
getNewCmdId();
// end of hack
setStatus(StatusAwaitingWelcome);
}
void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentification &event)
@ -63,6 +63,24 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica
setStatus(StatusDisconnecting);
return;
}
if(getStatus() == StatusRegistering)
{
Command_Register cmdRegister;
cmdRegister.set_user_name(userName.toStdString());
cmdRegister.set_password(password.toStdString());
cmdRegister.set_email(email.toStdString());
cmdRegister.set_gender((ServerInfo_User_Gender) gender);
cmdRegister.set_country(country.toStdString());
cmdRegister.set_real_name(realName.toStdString());
PendingCommand *pend = prepareSessionCommand(cmdRegister);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(registerResponse(Response)));
sendCommand(pend);
return;
}
setStatus(StatusLoggingIn);
Command_Login cmdLogin;
@ -101,6 +119,18 @@ void RemoteClient::loginResponse(const Response &response)
}
}
void RemoteClient::registerResponse(const Response &response)
{
const Response_Register &resp = response.GetExtension(Response_Register::ext);
if (response.response_code() == Response::RespRegistrationAccepted) {
emit registerAccepted();
} else {
emit registerError(response.response_code(), QString::fromStdString(resp.denied_reason_str()), resp.denied_end_time());
}
setStatus(StatusDisconnecting);
doDisconnectFromServer();
}
void RemoteClient::readData()
{
lastDataReceived = timeRunning;
@ -175,6 +205,21 @@ void RemoteClient::doConnectToServer(const QString &hostname, unsigned int port,
setStatus(StatusConnecting);
}
void RemoteClient::doRegisterToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname)
{
doDisconnectFromServer();
userName = _userName;
password = _password;
email = _email;
gender = _gender;
country = _country;
realName = _realname;
socket->connectToHost(hostname, port);
setStatus(StatusRegistering);
}
void RemoteClient::doDisconnectFromServer()
{
timer->stop();
@ -225,6 +270,11 @@ void RemoteClient::connectToServer(const QString &hostname, unsigned int port, c
emit sigConnectToServer(hostname, port, _userName, _password);
}
void RemoteClient::registerToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname)
{
emit sigRegisterToServer(hostname, port, _userName, _password, _email, _gender, _country, _realname);
}
void RemoteClient::disconnectFromServer()
{
emit sigDisconnectFromServer();