mirror of
https://gitlab.com/comunic/comunicmessages
synced 2025-06-20 00:45:17 +00:00
Can perform user sign in.
This commit is contained in:
26
data/accountloginrequest.cpp
Normal file
26
data/accountloginrequest.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "accountloginrequest.h"
|
||||
|
||||
AccountLoginRequest::AccountLoginRequest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString AccountLoginRequest::emailAddress() const
|
||||
{
|
||||
return mEmailAddress;
|
||||
}
|
||||
|
||||
void AccountLoginRequest::setEmailAddress(const QString &emailAddress)
|
||||
{
|
||||
mEmailAddress = emailAddress;
|
||||
}
|
||||
|
||||
QString AccountLoginRequest::password() const
|
||||
{
|
||||
return mPassword;
|
||||
}
|
||||
|
||||
void AccountLoginRequest::setPassword(const QString &password)
|
||||
{
|
||||
mPassword = password;
|
||||
}
|
43
data/accountloginrequest.h
Normal file
43
data/accountloginrequest.h
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Account login request
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
#ifndef ACCOUNTLOGINREQUEST_H
|
||||
#define ACCOUNTLOGINREQUEST_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
/**
|
||||
* Possible login results
|
||||
*/
|
||||
enum LoginResult {
|
||||
LOGIN_SUCCESS,
|
||||
INVALID_CREDENTIALS,
|
||||
TOO_MANY_REQUEST,
|
||||
NETWORK_ERROR,
|
||||
OTHER_ERROR
|
||||
};
|
||||
|
||||
/**
|
||||
* Login request
|
||||
*/
|
||||
class AccountLoginRequest
|
||||
{
|
||||
|
||||
public:
|
||||
AccountLoginRequest();
|
||||
|
||||
QString emailAddress() const;
|
||||
void setEmailAddress(const QString &emailAddress);
|
||||
|
||||
QString password() const;
|
||||
void setPassword(const QString &password);
|
||||
|
||||
private:
|
||||
QString mEmailAddress;
|
||||
QString mPassword;
|
||||
};
|
||||
|
||||
#endif // ACCOUNTLOGINREQUEST_H
|
54
data/apirequest.cpp
Normal file
54
data/apirequest.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "apirequest.h"
|
||||
|
||||
APIRequest::APIRequest(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
APIRequest::~APIRequest()
|
||||
{
|
||||
if(mNetworkReply != nullptr)
|
||||
mNetworkReply->deleteLater();
|
||||
}
|
||||
|
||||
QString APIRequest::URI() const
|
||||
{
|
||||
return mURI;
|
||||
}
|
||||
|
||||
void APIRequest::setURI(const QString &uRI)
|
||||
{
|
||||
mURI = uRI;
|
||||
}
|
||||
|
||||
void APIRequest::addString(QString name, QString value)
|
||||
{
|
||||
mArguments.append(APIRequestParameter(name, value));
|
||||
}
|
||||
|
||||
void APIRequest::addInt(QString name, int value)
|
||||
{
|
||||
mArguments.append(APIRequestParameter(name, QString::number(value)));
|
||||
}
|
||||
|
||||
void APIRequest::addBool(QString name, bool value)
|
||||
{
|
||||
mArguments.append(APIRequestParameter(name, value ? "true" : "false"));
|
||||
}
|
||||
|
||||
QList<APIRequestParameter> APIRequest::arguments() const
|
||||
{
|
||||
return mArguments;
|
||||
}
|
||||
|
||||
QNetworkReply *APIRequest::networkReply() const
|
||||
{
|
||||
return mNetworkReply;
|
||||
}
|
||||
|
||||
void APIRequest::setNetworkReply(QNetworkReply *networkReply)
|
||||
{
|
||||
mNetworkReply = networkReply;
|
||||
}
|
88
data/apirequest.h
Normal file
88
data/apirequest.h
Normal file
@ -0,0 +1,88 @@
|
||||
/**
|
||||
* This object contains information about a single
|
||||
* object.
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
#ifndef APIREQUEST_H
|
||||
#define APIREQUEST_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
#include "apirequestparameter.h"
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class APIRequest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit APIRequest(QObject *parent = nullptr);
|
||||
~APIRequest();
|
||||
|
||||
//Get and set URI target
|
||||
QString URI() const;
|
||||
void setURI(const QString &URI);
|
||||
|
||||
/**
|
||||
* Add a string parameter to the request
|
||||
*
|
||||
* @param name The name of the field to add
|
||||
* @param value The value of the argument to add
|
||||
*/
|
||||
void addString(QString name, QString value);
|
||||
|
||||
/**
|
||||
* Add an integer parameter to the request
|
||||
*
|
||||
* @param name The name of the field to add
|
||||
* @param value The value of the argument to add
|
||||
*/
|
||||
void addInt(QString name, int value);
|
||||
|
||||
/**
|
||||
* Add a boolean parameter to the request
|
||||
*
|
||||
* @param name The name of the field to add
|
||||
* @param value The value of the argument to add
|
||||
*/
|
||||
void addBool(QString name, bool value);
|
||||
|
||||
/**
|
||||
* Get the entire list of arguments of the request
|
||||
*
|
||||
* @return The list of arguments
|
||||
*/
|
||||
QList<APIRequestParameter> arguments() const;
|
||||
|
||||
//Get and set network reply associated with the request
|
||||
QNetworkReply *networkReply() const;
|
||||
void setNetworkReply(QNetworkReply *networkReply);
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
* Signal emitted when an error occurred
|
||||
*
|
||||
* @param code The code of the error
|
||||
*/
|
||||
void error(int code);
|
||||
|
||||
/**
|
||||
* Signal emitted once we have got the response for our request
|
||||
*
|
||||
* @param document JSON Response
|
||||
*/
|
||||
void success(const QJsonDocument &document);
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QString mURI;
|
||||
QList<APIRequestParameter> mArguments;
|
||||
QNetworkReply *mNetworkReply = nullptr;
|
||||
};
|
||||
|
||||
#endif // APIREQUEST_H
|
32
data/apirequestparameter.cpp
Normal file
32
data/apirequestparameter.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "apirequestparameter.h"
|
||||
|
||||
APIRequestParameter::APIRequestParameter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
APIRequestParameter::APIRequestParameter(const QString &name, const QString &value) :
|
||||
mName(name), mValue(value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString APIRequestParameter::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
void APIRequestParameter::setName(const QString &name)
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
QString APIRequestParameter::value() const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
void APIRequestParameter::setValue(const QString &value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
29
data/apirequestparameter.h
Normal file
29
data/apirequestparameter.h
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Single API request parameter
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
#ifndef APIREQUESTPARAMETER_H
|
||||
#define APIREQUESTPARAMETER_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class APIRequestParameter
|
||||
{
|
||||
public:
|
||||
APIRequestParameter();
|
||||
APIRequestParameter(const QString &name, const QString &value);
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QString value() const;
|
||||
void setValue(const QString &value);
|
||||
|
||||
private:
|
||||
QString mName;
|
||||
QString mValue;
|
||||
};
|
||||
|
||||
#endif // APIREQUESTPARAMETER_H
|
29
data/apirequestslist.cpp
Normal file
29
data/apirequestslist.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "apirequest.h"
|
||||
#include "apirequestslist.h"
|
||||
|
||||
APIRequestsList::APIRequestsList() : QList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
APIRequest *APIRequestsList::findForReply(QNetworkReply *reply, bool delete_from_list)
|
||||
{
|
||||
bool found = false;
|
||||
int i;
|
||||
for(i = 0; i < size(); i++){
|
||||
if(at(i)->networkReply() == reply){
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
APIRequest *request = nullptr;
|
||||
|
||||
if(found)
|
||||
request = at(i);
|
||||
|
||||
if(found && delete_from_list)
|
||||
removeAt(i);
|
||||
|
||||
return request;
|
||||
}
|
25
data/apirequestslist.h
Normal file
25
data/apirequestslist.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef APIREQUESTSLIST_H
|
||||
#define APIREQUESTSLIST_H
|
||||
|
||||
#include <QList>
|
||||
|
||||
class APIRequest;
|
||||
class QNetworkReply;
|
||||
|
||||
class APIRequestsList : public QList<APIRequest *>
|
||||
{
|
||||
public:
|
||||
APIRequestsList();
|
||||
|
||||
/**
|
||||
* Search and return the API Request that contains a specific NetworkReply
|
||||
*
|
||||
* @param reply The reply to search
|
||||
* @param delete_from_list Specify whether the entry should be removed
|
||||
* from the list or not
|
||||
* @return The request / null if none found
|
||||
*/
|
||||
APIRequest *findForReply(QNetworkReply *reply, bool delete_from_list);
|
||||
};
|
||||
|
||||
#endif // APIREQUESTSLIST_H
|
Reference in New Issue
Block a user