mirror of
https://github.com/QuasarApp/Hanoi-Towers.git
synced 2025-05-13 09:59:34 +00:00
fix run client
This commit is contained in:
parent
bf7adf3e8a
commit
4435002ccf
HanoiTowers
Heart@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS UsersData (
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Avatars (
|
||||
id INTEGER PRIMARY KEY NOT NULL
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
user_id VARCHAR(64) NOT NULL,
|
||||
data BLOB default NULL,
|
||||
|
||||
|
@ -13,15 +13,16 @@
|
||||
#include <localuser.h>
|
||||
#include <authrequest.h>
|
||||
#include <userdatarequest.h>
|
||||
#include <sqldbwriter.h>
|
||||
#include <asyncsqldbwriter.h>
|
||||
#include <useravatar.h>
|
||||
#include <sqldb.h>
|
||||
#include "hanoierrorcodes.h"
|
||||
#include "localrecordstable.h"
|
||||
|
||||
HanoiClient::HanoiClient() {
|
||||
initSqlDb("",
|
||||
new QH::SqlDBCache(DEFAULT_UPDATE_INTERVAL, QH::SqlDBCasheWriteMode::Force),
|
||||
new QH::SqlDBWriter());
|
||||
new QH::SqlDB(),
|
||||
new QH::AsyncSqlDbWriter());
|
||||
|
||||
}
|
||||
|
||||
@ -85,7 +86,7 @@ void HanoiClient::handleError(unsigned char status, const QString &error) {
|
||||
QmlNotificationService::NotificationData::Error);
|
||||
}
|
||||
|
||||
bool HanoiClient::p_login(const QByteArray& userId, const QByteArray &hashPassword) {
|
||||
bool HanoiClient::p_login(const QString& userId, const QByteArray &hashPassword) {
|
||||
QH::PKG::AuthRequest request;
|
||||
request.setId(userId);
|
||||
request.setRequest(QH::PKG::UserRequestType::Login);
|
||||
@ -103,7 +104,7 @@ bool HanoiClient::p_login(const QByteArray& userId, const QByteArray &hashPasswo
|
||||
return sendData(&request, _serverAddress);
|
||||
}
|
||||
|
||||
bool HanoiClient::p_signIn(const QByteArray &userId, const QByteArray& hashPassword) {
|
||||
bool HanoiClient::p_signIn(const QString &userId, const QByteArray& hashPassword) {
|
||||
QH::PKG::AuthRequest request;
|
||||
request.setId(userId);
|
||||
request.setAuthenticationData(hashPassword);
|
||||
@ -119,7 +120,7 @@ bool HanoiClient::userDatarequest(const QByteArray &userId) {
|
||||
return sendData(&request, _serverAddress);
|
||||
}
|
||||
|
||||
QSharedPointer<LocalUser> HanoiClient::getLocalUser(const QByteArray &userId) const {
|
||||
QSharedPointer<LocalUser> HanoiClient::getLocalUser(const QString &userId) const {
|
||||
LocalUser request;
|
||||
request.setId(userId);
|
||||
|
||||
@ -177,7 +178,7 @@ QImage HanoiClient::userAvatar(const QByteArray &userId) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray HanoiClient::currentUserId() const {
|
||||
QString HanoiClient::currentUserId() const {
|
||||
return _currentUserId;
|
||||
}
|
||||
|
||||
@ -191,7 +192,7 @@ const ProfileData* HanoiClient::currentProfile() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QSharedPointer<LocalUser> HanoiClient::profileToLocalUser(const QByteArray &login) {
|
||||
QSharedPointer<LocalUser> HanoiClient::profileToLocalUser(const QString &login) {
|
||||
auto user = QSharedPointer<LocalUser>::create();
|
||||
user->setId(login);
|
||||
user->setUpdateTime(time(nullptr));
|
||||
@ -247,7 +248,7 @@ bool HanoiClient::updateProfile(const ProfileData &profile) {
|
||||
}
|
||||
|
||||
|
||||
bool HanoiClient::login(const QByteArray &userId, const QString &rawPassword) {
|
||||
bool HanoiClient::login(const QString &userId, const QString &rawPassword) {
|
||||
|
||||
auto user = getLocalUser(userId);
|
||||
|
||||
@ -266,7 +267,7 @@ bool HanoiClient::login(const QByteArray &userId, const QString &rawPassword) {
|
||||
|
||||
}
|
||||
|
||||
bool HanoiClient::registerUser(const QByteArray &userId, const QString &rawPassword) {
|
||||
bool HanoiClient::registerUser(const QString &userId, const QString &rawPassword) {
|
||||
auto user = getLocalUser(userId);
|
||||
|
||||
if (user) {
|
||||
@ -277,12 +278,12 @@ bool HanoiClient::registerUser(const QByteArray &userId, const QString &rawPassw
|
||||
return p_signIn(userId, hashgenerator(rawPassword.toLatin1()));
|
||||
}
|
||||
|
||||
bool HanoiClient::registerOflineUser(const QByteArray &login) {
|
||||
bool HanoiClient::registerOflineUser(const QString &login) {
|
||||
auto user = profileToLocalUser(login);
|
||||
return db()->updateObject(user);
|
||||
return db()->insertObject(user);
|
||||
}
|
||||
|
||||
bool HanoiClient::removeUser(const QByteArray &userId) {
|
||||
bool HanoiClient::removeUser(const QString &userId) {
|
||||
auto user = getLocalUser(userId);
|
||||
QH::PKG::AuthRequest request;
|
||||
request.setId(user->getId());
|
||||
|
@ -45,17 +45,17 @@ public:
|
||||
const QH::AbstractNodeInfo *sender) override;
|
||||
|
||||
|
||||
QByteArray currentUserId() const;
|
||||
QString currentUserId() const;
|
||||
|
||||
const ProfileData *currentProfile() const;
|
||||
bool updateProfile(const ProfileData& profile);
|
||||
bool addProfile(const ProfileData& profile);
|
||||
|
||||
bool login(const QByteArray &userId, const QString& rawPassword = "");
|
||||
bool registerUser(const QByteArray &userId, const QString& rawPassword);
|
||||
bool login(const QString &userId, const QString& rawPassword = "");
|
||||
bool registerUser(const QString &userId, const QString& rawPassword);
|
||||
|
||||
bool registerOflineUser(const QByteArray &login);
|
||||
bool removeUser(const QByteArray &userId);
|
||||
bool registerOflineUser(const QString &login);
|
||||
bool removeUser(const QString &userId);
|
||||
|
||||
void connectToServer(const QH::HostAddress& host);
|
||||
|
||||
@ -85,17 +85,17 @@ private slots:
|
||||
|
||||
private:
|
||||
|
||||
bool p_login(const QByteArray &userId, const QByteArray &hashPassword = {});
|
||||
bool p_signIn(const QByteArray &userId, const QByteArray &hashPassword);
|
||||
bool p_login(const QString &userId, const QByteArray &hashPassword = {});
|
||||
bool p_signIn(const QString &userId, const QByteArray &hashPassword);
|
||||
|
||||
bool userDatarequest(const QByteArray &userId);
|
||||
QSharedPointer<LocalUser> getLocalUser(const QByteArray &userId) const;
|
||||
QSharedPointer<LocalUser> getLocalUser(const QString &userId) const;
|
||||
QSharedPointer<LocalUser> profileToLocalUser(const ProfileData &profile);
|
||||
QSharedPointer<LocalUser> profileToLocalUser(const QByteArray &login);
|
||||
QSharedPointer<LocalUser> profileToLocalUser(const QString &login);
|
||||
|
||||
|
||||
Status _status;
|
||||
QByteArray _currentUserId;
|
||||
QString _currentUserId;
|
||||
QH::HostAddress _serverAddress;
|
||||
QList<LocalUser*> _usersList;
|
||||
|
||||
|
@ -48,7 +48,8 @@ bool LocalUser::isValid() const {
|
||||
}
|
||||
|
||||
QH::PKG::DBVariantMap LocalUser::variantMap() const {
|
||||
return {{"passwordHash", {_hashPassword, MT::InsertUpdate}},
|
||||
return {{primaryKey(), {getId(), MT::PrimaryKey}},
|
||||
{"passwordHash", {_hashPassword, MT::InsertUpdate}},
|
||||
{"token", {_token.toBytes(), MT::InsertUpdate}},
|
||||
{"userdata", {_userData.toBytes(), MT::InsertUpdate}},
|
||||
{"updateTime", {static_cast<int>(time(nullptr)), MT::InsertUpdate}}};
|
||||
|
@ -3,13 +3,13 @@ CREATE TABLE IF NOT EXISTS Users (
|
||||
passwordHash BLOB default NULL,
|
||||
token BLOB default NULL,
|
||||
userdata BLOB default NULL,
|
||||
updateTime INTEGER default 0
|
||||
userAvatar INTEGER default 0,
|
||||
updateTime INTEGER default 0,
|
||||
userAvatar INTEGER default 0
|
||||
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Avatars (
|
||||
id INTEGER PRIMARY KEY NOT NULL
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
user_id VARCHAR(64) NOT NULL,
|
||||
data BLOB default NULL,
|
||||
|
||||
|
2
Heart
2
Heart
@ -1 +1 @@
|
||||
Subproject commit bcfbf3ad76b56bc58469eabd000fb6e8b40a6cac
|
||||
Subproject commit 313fd29c05c2de89c77f76f33d8dd70178969dc4
|
Loading…
x
Reference in New Issue
Block a user