From ef667f5951ab11ecfb56e03d1c3f1a3a02271933 Mon Sep 17 00:00:00 2001 From: Firefly-29710 <2235501805@qq.com> Date: Mon, 8 Jul 2024 15:44:55 +0800 Subject: [PATCH 01/10] insertUser --- loginwin.cpp | 6 +++--- mainwindow.cpp | 5 +++++ mainwindow.h | 1 + user.cpp | 5 +++++ user.h | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/loginwin.cpp b/loginwin.cpp index 47b22ef..de928a7 100644 --- a/loginwin.cpp +++ b/loginwin.cpp @@ -85,8 +85,8 @@ loginwin::loginwin(QWidget* parent):ElaWidget(parent) loginWinArea->addLayout(srBtnArea,Qt::AlignCenter); area->setLayout(loginWinArea); - db = new DatabaseManager(this); // 创建数据库管理器实例 - db->initializeDatabase(); // 初始化数据库 + //db = new DatabaseManager(this); // 创建数据库管理器实例 + //db->initializeDatabase(); // 初始化数据库 connect(resetBtn,&ElaPushButton::clicked,this, &loginwin::on_resetBtn_clicked); connect(signinBtn,&ElaPushButton::clicked,this, &loginwin::on_signinBtn_clicked); @@ -129,7 +129,7 @@ void loginwin::on_loginBtn_clicked() if(loginuser.login()){ QMessageBox::information(this, "成功","登录成功"); emit on_login_complete(loginuser); - db->insertUser(accountLine->text(),passwordLine->text()); + //db->insertUser(accountLine->text(),passwordLine->text()); this->close(); } else diff --git a/mainwindow.cpp b/mainwindow.cpp index 3f5df79..d037924 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -21,6 +21,10 @@ MainWindow::MainWindow(QWidget *parent) : ElaWindow(parent) { + + db = new DatabaseManager(this); // 创建数据库管理器实例 + db->initializeDatabase(); // 初始化数据库 + // ElaApplication::getInstance()->setThemeMode(ElaApplicationType::Dark); // setIsNavigationBarEnable(false); // setNavigationBarDisplayMode(ElaNavigationType::Minimal); @@ -148,6 +152,7 @@ void MainWindow::onUserLoggedIn(User user) setUserInfoCardTitle(user.getUsername()); setUserInfoCardSubTitle(user.getEmail()); CurrentUser=new User(user); + db->insertUser(user.getEmail(),user.gethashedPassword()); } void MainWindow::onCloseButtonClicked() diff --git a/mainwindow.h b/mainwindow.h index d3b85ce..2172c56 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,6 +27,7 @@ class MainWindow : public ElaWindow loginwin* login=new loginwin(); Q_SLOT void onCloseButtonClicked(); User*CurrentUser=nullptr; + DatabaseManager*db; public slots: void onUserLoggedIn(User user); diff --git a/user.cpp b/user.cpp index f6dc856..0df96eb 100644 --- a/user.cpp +++ b/user.cpp @@ -98,6 +98,11 @@ QString User::getEmail() return account; } +QString User::gethashedPassword() +{ + return hashedPassword; +} + QString User::getUserHash() const { QByteArray hash = QCryptographicHash::hash(account.toUtf8(), QCryptographicHash::Sha1); diff --git a/user.h b/user.h index 701a6b0..381eb79 100644 --- a/user.h +++ b/user.h @@ -37,7 +37,7 @@ class User : public QObject QString getUsername();//获取用户名 QString getEmail();//获取用户邮箱 QString getUserHash() const; //返回用户账户的哈希 - + QString gethashedPassword(); bool getisLogin(); //返回用户登陆状态 signals: From b61035f0d8f9439b1714cfa0a31b40037b857af8 Mon Sep 17 00:00:00 2001 From: Firefly-29710 <2235501805@qq.com> Date: Mon, 8 Jul 2024 16:19:54 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=AD=A3=E5=9C=A8=E5=90=8C=E6=AD=A5=E7=95=8C=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?filecard=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + filecard.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ filecard.h | 26 ++++++++++++++++++++++ syncing_view.cpp | 41 +++++++++++++++++++++++++++++++++- syncing_view.h | 5 ++++- 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 filecard.cpp create mode 100644 filecard.h diff --git a/CMakeLists.txt b/CMakeLists.txt index edea7c4..7610e69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) avatarImage.qrc filequeue.h filequeue.cpp storage.h storage.cpp + filecard.h filecard.cpp ) diff --git a/filecard.cpp b/filecard.cpp new file mode 100644 index 0000000..930ee62 --- /dev/null +++ b/filecard.cpp @@ -0,0 +1,58 @@ +#include "filecard.h" + +#include +#include"ElaCheckBox.h" +#include"ElaIconButton.h" +#include"ElaProgressBar.h" +FileCard::FileCard(QString f, QString d,QString s,QString p) +{ + filename=new ElaText(f); + datasize=new ElaText(d); + speed=new ElaText(s); + progress=new ElaText(p); + + _checkBox = new ElaCheckBox(filename->text(), this); + QVBoxLayout*checkBoxArea=new QVBoxLayout(); + checkBoxArea->addWidget(_checkBox,0,Qt::AlignCenter); + + datasize->setTextSize(16); + QVBoxLayout*dataSizeArea=new QVBoxLayout(); + dataSizeArea->addWidget(datasize,0,Qt::AlignCenter); + + speed->setTextSize(16); + QVBoxLayout*speedArea=new QVBoxLayout(); + speedArea->addWidget(speed,0,Qt::AlignCenter); + + proBar = new ElaProgressBar(this); + proBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + proBar->setFixedSize(100,15); + proBar->setMinimum(0); + proBar->setMaximum(0); + progress->setTextSize(16); + QVBoxLayout*proBarArea=new QVBoxLayout(); + proBarArea->addWidget(progress,0,Qt::AlignCenter); + proBarArea->addWidget(proBar,0,Qt::AlignCenter); + proBarArea->setAlignment(Qt::AlignCenter); + + modifyBtn=new ElaIconButton(ElaIconType::CalendarLinesPen); + pauseBtn=new ElaIconButton(ElaIconType::Pause); + relieveBtn=new ElaIconButton(ElaIconType::Xmark); + modifyBtn->setFixedSize(30,30); + pauseBtn->setFixedSize(30,30); + relieveBtn->setFixedSize(30,30); + + QHBoxLayout*actionArea=new QHBoxLayout(); + actionArea->addWidget(modifyBtn); + actionArea->addWidget(pauseBtn); + actionArea->addWidget(relieveBtn); + actionArea->setAlignment(Qt::AlignCenter); + + QHBoxLayout*FileCardArea=new QHBoxLayout(this); + FileCardArea->addLayout(checkBoxArea,Qt::AlignCenter); + FileCardArea->addLayout(dataSizeArea,Qt::AlignCenter); + FileCardArea->addLayout(speedArea,Qt::AlignCenter); + FileCardArea->addLayout(proBarArea,Qt::AlignCenter); + FileCardArea->addLayout(actionArea,Qt::AlignCenter); + FileCardArea->addStretch(); + +} diff --git a/filecard.h b/filecard.h new file mode 100644 index 0000000..c73106a --- /dev/null +++ b/filecard.h @@ -0,0 +1,26 @@ +#ifndef FILECARD_H +#define FILECARD_H + +#include"ElaScrollPageArea.h" +#include"ElaText.h" + +class ElaCheckBox; +class ElaIconButton; +class ElaProgressBar; +class FileCard : public ElaScrollPageArea +{ +public: + explicit FileCard(QString f, QString d,QString s,QString p); + + ElaCheckBox* _checkBox{nullptr}; + ElaText *filename; + ElaText *datasize; + ElaText *speed; + ElaText*progress; + ElaIconButton*modifyBtn; + ElaIconButton*pauseBtn; + ElaIconButton*relieveBtn; + ElaProgressBar*proBar; +}; + +#endif // FILECARD_H diff --git a/syncing_view.cpp b/syncing_view.cpp index b00a05a..dd6c43f 100644 --- a/syncing_view.cpp +++ b/syncing_view.cpp @@ -3,6 +3,8 @@ #include "ElaPushButton.h" #include "ElaToggleButton.h" #include +#include"filecard.h" +#include"ElaScrollArea.h" SyncingPage::SyncingPage(QWidget* parent) : ElaScrollPage(parent) @@ -83,10 +85,41 @@ SyncingPage::SyncingPage(QWidget* parent) catalogueLayout->addWidget(catalogueText4); catalogueLayout->addWidget(catalogueText5); + ElaScrollArea* scrollArea = new ElaScrollArea(); + scrollArea->viewport()->setStyleSheet("background:transparent;");//设置背景透明 + FileCard*FileCardArea1=new FileCard("文件1","3.5GB","1MB/s","0%"); + FileCard*FileCardArea2=new FileCard("文件2","3.5GB","2MB/s","0%"); + FileCard*FileCardArea3=new FileCard("文件3","3.5GB","3MB/s","0%"); + FileCard*FileCardArea4=new FileCard("文件4","3.5GB","4MB/s","0%"); + FileCard*FileCardArea5=new FileCard("文件5","3.5GB","5MB/s","0%"); + FileCard*FileCardArea6=new FileCard("文件6","3.5GB","6MB/s","0%"); + FileCard*FileCardArea7=new FileCard("文件7","3.5GB","7MB/s","0%"); + FileCard*FileCardArea8=new FileCard("文件8","3.5GB","8MB/s","0%"); + FileCard*FileCardArea9=new FileCard("文件9","3.5GB","9MB/s","0%"); + FileCard*FileCardArea10=new FileCard("文件10","3.5GB","10MB/s","0%"); + + + QWidget* filesWidget=new QWidget(); + filesLayout=new QVBoxLayout(filesWidget); + filesLayout->addWidget(FileCardArea1); + filesLayout->addWidget(FileCardArea2); + filesLayout->addWidget(FileCardArea3); + filesLayout->addWidget(FileCardArea4); + filesLayout->addWidget(FileCardArea5); + filesLayout->addWidget(FileCardArea6); + filesLayout->addWidget(FileCardArea7); + filesLayout->addWidget(FileCardArea8); + filesLayout->addWidget(FileCardArea9); + filesLayout->addWidget(FileCardArea10); + filesLayout->setAlignment(Qt::AlignTop); + + scrollArea->setWidget(filesWidget); // 设置scrollArea的内容部件 + scrollArea->setWidgetResizable(true); // 允许scrollArea根据内容自动调整大小 + centerVLayout->addWidget(progressBarArea); // 将上方固定区域添加到布局中 centerVLayout->addWidget(pushButtonArea); // 将切换按钮容器添加到布局中 centerVLayout->addWidget(catalogueArea); // 将目录文本添加到布局中 - centerVLayout->addStretch(); // 在布局的末尾添加一个弹性空间 + centerVLayout->addWidget(scrollArea); this->addCentralWidget(centralWidget); // 将中心部件添加到窗口中 } @@ -95,3 +128,9 @@ SyncingPage::~SyncingPage() { } + +void SyncingPage::addFile(QString filename, QString datasize,QString speed,QString progress) +{ + FileCard*firecard=new FileCard(filename,datasize,speed,progress); + filesLayout->addWidget(firecard); +} diff --git a/syncing_view.h b/syncing_view.h index 453c701..14ec979 100644 --- a/syncing_view.h +++ b/syncing_view.h @@ -3,15 +3,18 @@ #include "ElaProgressBar.h" #include "ElaScrollPage.h" -#include "ElaScrollPageArea.h" +#include "ElaScrollPage.h" class ElaToggleButton; class ElaPushButton; +class QVBoxLayout; class SyncingPage : public ElaScrollPage { public: SyncingPage(QWidget* parent = nullptr); ~SyncingPage(); + void addFile(QString filename, QString datasize,QString speed,QString progress); + QVBoxLayout*filesLayout; private: ElaProgressBar* _progressBar{nullptr}; ElaPushButton* _pushButton{nullptr}; From 8f289b7636d30a91b96c5a8539aba0ceef0b238f Mon Sep 17 00:00:00 2001 From: Cppthx <2728347417@qq.com> Date: Mon, 8 Jul 2024 16:24:27 +0800 Subject: [PATCH 03/10] =?UTF-8?q?db=E7=A7=BB=E5=8A=A8=EF=BC=8C=E8=AE=B0?= =?UTF-8?q?=E4=BD=8F=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- databasemanager.cpp | 6 +++--- loginwin.cpp | 4 ++-- loginwin.h | 2 +- mainwindow.cpp | 7 ++++++- mainwindow.h | 2 ++ user.cpp | 4 ++++ user.h | 1 + userinfopage.cpp | 36 +++++++++++++++++++----------------- userinfopage.h | 19 ++++++++++++------- 9 files changed, 50 insertions(+), 31 deletions(-) diff --git a/databasemanager.cpp b/databasemanager.cpp index a07de6a..76dc9dc 100644 --- a/databasemanager.cpp +++ b/databasemanager.cpp @@ -59,9 +59,7 @@ bool DatabaseManager::insertUser(const QString &account, const QString &hashedPa return true; } - bool DatabaseManager::updateUserInfo(const QString &account, - const QString &newId, - const QString &newHashedPassword) +bool DatabaseManager::updateUserInfo(const QString &account,const QString &newId,const QString &newHashedPassword) { QSqlQuery query; query.prepare("UPDATE Users SET account = :newId, hashedPassword = :newHashedPassword WHERE account = :account"); @@ -111,3 +109,5 @@ QPair DatabaseManager::getUserPassword(const QString &account) // 如果没有找到匹配的账号,返回空值 return userPassword; } + + diff --git a/loginwin.cpp b/loginwin.cpp index de928a7..423a22a 100644 --- a/loginwin.cpp +++ b/loginwin.cpp @@ -91,7 +91,7 @@ loginwin::loginwin(QWidget* parent):ElaWidget(parent) connect(resetBtn,&ElaPushButton::clicked,this, &loginwin::on_resetBtn_clicked); connect(signinBtn,&ElaPushButton::clicked,this, &loginwin::on_signinBtn_clicked); connect(loginBtn,&ElaPushButton::clicked,this, &loginwin::on_loginBtn_clicked); - connect(accountLine, &ElaLineEdit::returnPressed, this, &loginwin::on_accountLine_returnPressed); + connect(accountLine, &ElaLineEdit::editingFinished, this, &loginwin::on_accountLine_editingFinished); } loginwin::~loginwin() @@ -138,7 +138,7 @@ void loginwin::on_loginBtn_clicked() loginBtn->setEnabled(true); } -void loginwin::on_accountLine_returnPressed() +void loginwin::on_accountLine_editingFinished() { // 当账号输入框编辑完成时,检查是否需要记住密码 if (accountLine->text().isEmpty()) { diff --git a/loginwin.h b/loginwin.h index 7ec1a0e..304dfcd 100644 --- a/loginwin.h +++ b/loginwin.h @@ -29,7 +29,7 @@ private slots: void on_resetBtn_clicked(); void on_signinBtn_clicked(); void on_loginBtn_clicked(); - void on_accountLine_returnPressed(); + void on_accountLine_editingFinished(); private: Core *core; diff --git a/mainwindow.cpp b/mainwindow.cpp index d037924..c7bfbd6 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -39,11 +39,14 @@ MainWindow::MainWindow(QWidget *parent) _syncingPage = new SyncingPage(this); _filemanagePage=new FileManagePage(this); _historysyncPage = new HistorysyncPage(this); + _userinfopage = new UserInfoPage(this); connect(this, &ElaWindow::userInfoCardClicked, this, [=]() { if(CurrentUser==nullptr) login->show(); }); + connect(this,&MainWindow::dbPassword,login,&loginwin::on_db_response); + connect(login,&loginwin::needPassword,this,&MainWindow::onNeedPassword); // GraphicsView ElaGraphicsScene *scene = new ElaGraphicsScene(this); @@ -77,7 +80,7 @@ MainWindow::MainWindow(QWidget *parent) addExpanderNode("版本控制",testKey_3,ElaIconType::EnvelopeOpenText); addPageNode("查看历史",new QWidget(this),testKey_3,ElaIconType::CalendarClock); addExpanderNode("个人功能",testKey_4,ElaIconType::User); - addPageNode("修改信息",new QWidget(this),testKey_4,ElaIconType::Text); + addPageNode("修改信息",_userinfopage,testKey_4,ElaIconType::Text); addPageNode("注销账号",new QWidget(this),testKey_4,ElaIconType::UserSlash); addPageNode("退出登录",new QWidget(this),testKey_4,ElaIconType::ArrowRightFromBracket); @@ -141,6 +144,7 @@ MainWindow::MainWindow(QWidget *parent) */ qDebug() << ElaEventBus::getInstance()->getRegisteredEventsName(); QObject::connect(login, &loginwin::on_login_complete, this, &MainWindow::onUserLoggedIn); + QObject::connect(_userinfopage, &UserInfoPage::changexinxi, this, &MainWindow::onUserLoggedIn); // 拦截默认关闭事件 this->setIsDefaultClosed(false); connect(this, &MainWindow::closeButtonClicked, this, &MainWindow::onCloseButtonClicked); @@ -152,6 +156,7 @@ void MainWindow::onUserLoggedIn(User user) setUserInfoCardTitle(user.getUsername()); setUserInfoCardSubTitle(user.getEmail()); CurrentUser=new User(user); + _userinfopage->currentUser=CurrentUser; db->insertUser(user.getEmail(),user.gethashedPassword()); } diff --git a/mainwindow.h b/mainwindow.h index 2172c56..566e88c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -7,6 +7,7 @@ #include "ElaWindow.h" #include"loginwin.h" #include"ElaCheckBox.h" +#include"userinfopage.h" #include "user.h" class HomePage; @@ -47,6 +48,7 @@ public slots: QString _settingKey{""}; ElaCheckBox* _checkBox{nullptr}; + UserInfoPage* _userinfopage{nullptr}; }; #endif // MAINWINDOW_H diff --git a/user.cpp b/user.cpp index 0df96eb..ecf7e11 100644 --- a/user.cpp +++ b/user.cpp @@ -115,3 +115,7 @@ bool User::getisLogin() // return session; }*/ +bool User::updateUser(User &user) +{ + return true; +} diff --git a/user.h b/user.h index 381eb79..305d7d5 100644 --- a/user.h +++ b/user.h @@ -33,6 +33,7 @@ class User : public QObject bool login(); //执行post请求,实现登录功能 bool forgetPassword(); //执行post请求,实现找回密码功能 bool loadTask();//获取云端task + bool updateUser(User &user); QString getS3Location();//获取云端容器地址 QString getUsername();//获取用户名 QString getEmail();//获取用户邮箱 diff --git a/userinfopage.cpp b/userinfopage.cpp index 06bb8f7..6724b94 100644 --- a/userinfopage.cpp +++ b/userinfopage.cpp @@ -2,17 +2,18 @@ #include #include -UserInfoPage::UserInfoPage(DatabaseManager *dbManager, QWidget *parent) : QWidget(parent), dbManager_(dbManager) + +UserInfoPage::UserInfoPage(QWidget *parent) : QWidget(parent) { // 创建控件 - newIdEdit_ = new QLineEdit(this); - newPasswordEdit_ = new QLineEdit(this); - confirmNewPasswordEdit_ = new QLineEdit(this); - confirmButton_ = new QPushButton("确认修改", this); + newIdEdit_ = new ElaLineEdit(this); + newPasswordEdit_ = new ElaLineEdit(this); + confirmNewPasswordEdit_ = new ElaLineEdit(this); + confirmButton_ = new ElaPushButton("确认修改", this); // 设置密码输入为密码模式 - newPasswordEdit_->setEchoMode(QLineEdit::Password); - confirmNewPasswordEdit_->setEchoMode(QLineEdit::Password); + newPasswordEdit_->setEchoMode(ElaLineEdit::Password); + confirmNewPasswordEdit_->setEchoMode(ElaLineEdit::Password); // 布局 QVBoxLayout *layout = new QVBoxLayout(this); @@ -21,8 +22,15 @@ UserInfoPage::UserInfoPage(DatabaseManager *dbManager, QWidget *parent) : QWidge layout->addWidget(confirmNewPasswordEdit_); layout->addWidget(confirmButton_); + // 获取当前登录的用户信息 + //QString userEmail = currentUser->getEmail(); + newIdEdit_->setPlaceholderText("修改ID"); + newPasswordEdit_->setPlaceholderText("新密码"); + confirmNewPasswordEdit_->setPlaceholderText("确认密码"); + + // 连接信号与槽 - connect(confirmButton_, &QPushButton::clicked, this, &UserInfoPage::onConfirmButtonClicked); + connect(confirmButton_, &ElaPushButton::clicked, this, &UserInfoPage::onConfirmButtonClicked); } void UserInfoPage::onConfirmButtonClicked() @@ -43,13 +51,7 @@ void UserInfoPage::onConfirmButtonClicked() } // 更新数据库 - QString currentAccount = "currentUserAccount"; // 应替换为实际的当前用户账号 - if (dbManager_->updateUserInfo(currentAccount, newId, newPassword)) { - QMessageBox::information(this, "成功", "用户信息更新成功。"); - // 更新主界面显示的用户ID - // 假设主界面有一个label来显示用户ID,我们将更新它的文本 - //emit updateUserIdSignal(newId); - } else { - QMessageBox::warning(this, "错误", "用户信息更新失败。"); - } + emit changexinxi(User(*currentUser)); + + QMessageBox::information(this, "成功","修改成功"); } diff --git a/userinfopage.h b/userinfopage.h index 2922b0e..d30eb5e 100644 --- a/userinfopage.h +++ b/userinfopage.h @@ -6,20 +6,25 @@ #include #include #include -#include "databasemanager.h" +#include"user.h" +#include"ElaLineEdit.h" +#include"ElaPushButton.h" class UserInfoPage : public QWidget { Q_OBJECT public: - explicit UserInfoPage(DatabaseManager *dbManager, QWidget *parent = nullptr); + explicit UserInfoPage(QWidget *parent = nullptr); + User* currentUser; private: - DatabaseManager *dbManager_; - QLineEdit *newIdEdit_; - QLineEdit *newPasswordEdit_; - QLineEdit *confirmNewPasswordEdit_; - QPushButton *confirmButton_; + ElaLineEdit *newIdEdit_; + ElaLineEdit *newPasswordEdit_; + ElaLineEdit *confirmNewPasswordEdit_; + ElaPushButton *confirmButton_; + +signals: + void changexinxi(User user); private slots: void onConfirmButtonClicked(); From a44db59d600a6861db32ee5f0614066e624e4eae Mon Sep 17 00:00:00 2001 From: Cppthx <2728347417@qq.com> Date: Mon, 8 Jul 2024 16:51:24 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E8=AE=B0=E4=BD=8F=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- databasemanager.cpp | 7 +++---- databasemanager.h | 2 +- loginwin.cpp | 12 +++++++----- loginwin.h | 4 ++++ mainwindow.cpp | 6 ++++++ mainwindow.h | 4 ++++ 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/databasemanager.cpp b/databasemanager.cpp index 76dc9dc..7889a3b 100644 --- a/databasemanager.cpp +++ b/databasemanager.cpp @@ -59,11 +59,10 @@ bool DatabaseManager::insertUser(const QString &account, const QString &hashedPa return true; } -bool DatabaseManager::updateUserInfo(const QString &account,const QString &newId,const QString &newHashedPassword) +bool DatabaseManager::updateUserInfo(const QString &account,const QString &newHashedPassword) { QSqlQuery query; - query.prepare("UPDATE Users SET account = :newId, hashedPassword = :newHashedPassword WHERE account = :account"); - query.bindValue(":newId", newId); + query.prepare("UPDATE Users SET hashedPassword = :newHashedPassword WHERE account = :account"); query.bindValue(":newHashedPassword", newHashedPassword); query.bindValue(":account", account); @@ -73,7 +72,7 @@ bool DatabaseManager::updateUserInfo(const QString &account,const QString &newId } // 更新账号密码映射 - accountPasswordMap_[newId] = newHashedPassword; + accountPasswordMap_[account] = newHashedPassword; return true; } diff --git a/databasemanager.h b/databasemanager.h index c2efe83..3fd9bb1 100644 --- a/databasemanager.h +++ b/databasemanager.h @@ -13,7 +13,7 @@ class DatabaseManager : public QObject QMapaccountPasswordMap_; public: explicit DatabaseManager(QObject *parent = nullptr); - bool updateUserInfo(const QString &account, const QString &newId, const QString &newHashedPassword); + bool updateUserInfo(const QString &account, const QString &newHashedPassword); bool initializeDatabase(); bool insertUser(const QString &account, const QString &hashedPassword); QListgetAllAccounts(); diff --git a/loginwin.cpp b/loginwin.cpp index 423a22a..2f6caed 100644 --- a/loginwin.cpp +++ b/loginwin.cpp @@ -99,6 +99,11 @@ loginwin::~loginwin() } +void loginwin::on_db_response(const QString &password) +{ + passwordLine->setText(password); +} + void loginwin::on_resetBtn_clicked() { resetWin->show(); @@ -150,11 +155,8 @@ void loginwin::on_accountLine_editingFinished() QString inputAccount = accountLine->text(); // 从数据库中获取账号对应的密码 - QPair accountPassword = db->getUserPassword(inputAccount); - + emit needPassword(inputAccount); // 如果数据库中存在该账号,则设置密码到密码输入框 - if (!accountPassword.second.isEmpty()) { - passwordLine->setText(accountPassword.second); - } + } diff --git a/loginwin.h b/loginwin.h index 304dfcd..0403d44 100644 --- a/loginwin.h +++ b/loginwin.h @@ -24,12 +24,16 @@ class loginwin:public ElaWidget signals: void on_login_complete(User user); + void needPassword(const QString & account); +public slots: + void on_db_response(const QString & password); private slots: void on_resetBtn_clicked(); void on_signinBtn_clicked(); void on_loginBtn_clicked(); void on_accountLine_editingFinished(); + private: Core *core; diff --git a/mainwindow.cpp b/mainwindow.cpp index c7bfbd6..275275f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -160,6 +160,12 @@ void MainWindow::onUserLoggedIn(User user) db->insertUser(user.getEmail(),user.gethashedPassword()); } +void MainWindow::onNeedPassword(const QString &account) +{ + QString password = db->getUserPassword(account).second; + emit dbPassword(password); +} + void MainWindow::onCloseButtonClicked() { ElaContentDialog *dialag = new ElaContentDialog(this); diff --git a/mainwindow.h b/mainwindow.h index 566e88c..6c70a79 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -32,6 +32,10 @@ class MainWindow : public ElaWindow public slots: void onUserLoggedIn(User user); + void onNeedPassword(const QString& account); + +signals: + void dbPassword(const QString &); private: From ec274c6ccee828affd4c0a92600b4ab8713ea539 Mon Sep 17 00:00:00 2001 From: Dipper209 <3611691282@qq.com> Date: Mon, 8 Jul 2024 16:58:18 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=8E=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E9=80=9A=E4=BF=A1=EF=BC=8Ctask=E5=BB=BA?= =?UTF-8?q?=E7=AB=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + synctask.h | 2 + tasktoken.cpp | 11 ++++++ tasktoken.h | 17 +++++++++ user.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++--- user.h | 21 +++++++++-- 6 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 tasktoken.cpp create mode 100644 tasktoken.h diff --git a/CMakeLists.txt b/CMakeLists.txt index edea7c4..9430ed7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) avatarImage.qrc filequeue.h filequeue.cpp storage.h storage.cpp + tasktoken.h tasktoken.cpp ) diff --git a/synctask.h b/synctask.h index 7debcc9..a30232f 100644 --- a/synctask.h +++ b/synctask.h @@ -9,6 +9,7 @@ #include #include #include "qcontainerfwd.h" +#include "awsutils.h" //声明友元类 class SyncCore; @@ -24,6 +25,7 @@ class SyncTask int syncStatus; //1 for upload/download,2 for only upload,3 for only download. -1 for paused //lastSyncTime, use Qt::currentDateTime() to get the current time QDateTime lastSyncTime; + AWSUtils* awsutils; public: SyncTask(QString localPath, QString remotePath, int syncStatus, int id=-1); diff --git a/tasktoken.cpp b/tasktoken.cpp new file mode 100644 index 0000000..e4b8158 --- /dev/null +++ b/tasktoken.cpp @@ -0,0 +1,11 @@ +#include "tasktoken.h" + +TaskToken::TaskToken(const QJsonObject &data) +{ + QJsonObject credentials=data.value("credentials").toObject(); + sessionToken = credentials.value("sessionToken").toString(); + tmpSecretId = credentials.value("tmpSecretId").toString(); + tmpSecretKey = credentials.value("tmpSecretKey").toString(); + qint64 qtUnixTimestamp = static_cast(data.value("expiredTime").toInt()); + expiredTime = QDateTime::fromSecsSinceEpoch(qtUnixTimestamp); +} diff --git a/tasktoken.h b/tasktoken.h new file mode 100644 index 0000000..86ce3ea --- /dev/null +++ b/tasktoken.h @@ -0,0 +1,17 @@ +#ifndef TASKTOKEN_H +#define TASKTOKEN_H +#include +#include +#include + +class TaskToken +{ +public: + TaskToken(const QJsonObject &data); + QString sessionToken; + QString tmpSecretId; + QString tmpSecretKey; + QDateTime expiredTime;//过期时间的unix +}; + +#endif // TASKTOKEN_H diff --git a/user.cpp b/user.cpp index f6dc856..8d0c182 100644 --- a/user.cpp +++ b/user.cpp @@ -35,6 +35,7 @@ bool User::enroll() QString postData = QString("username=%1&email=%2&password=%3").arg(username).arg(account).arg(hashedPassword); ApiResponse response=apiRequest->post("/register",postData.toUtf8()); + emit enrollResponse(response.getCode(),response.getData(),response.getMessage()); return response.isSuccess(); } @@ -48,8 +49,8 @@ bool User::login() } else if(response.getCode()==403){ isLogin=false; - } + emit loginResponse(response.getCode(),response.getData(),response.getMessage()); return response.isSuccess(); } @@ -59,20 +60,109 @@ bool User::forgetPassword() return true; } -bool User::loadTask() +bool User::updateAvatar(const QString &filePath) +{ + QImageReader reader(filePath); + if (!reader.canRead()) { + qDebug()<<"read picture failed!"; + QString jsonString = R"({"code": 666, "message": "select picture error!", "data": "Nooo!"})"; + QByteArray jsonData = jsonString.toUtf8(); + QJsonDocument document = QJsonDocument::fromJson(jsonData); + QJsonObject jsonObject = document.object(); + emit updateAvatarResponse(666,jsonObject,"select picture error!"); + return false; // 图片读取失败 + } + QImage image = reader.read(); + if (image.isNull()) { + qDebug()<<"read picture failed!"; + QString jsonString = R"({"code": 666, "message": "select picture error!", "data": "Nooo!"})"; + QByteArray jsonData = jsonString.toUtf8(); + QJsonDocument document = QJsonDocument::fromJson(jsonData); + QJsonObject jsonObject = document.object(); + emit updateAvatarResponse(666,jsonObject,"select picture error!"); + return false; // 图片读取失败 + } + QByteArray byteArray; + QBuffer buffer(&byteArray); + image.save(&buffer, reader.format()); // 使用图片的原始格式保存 + // 将字节数据编码为Base64字符串 + QString postData = byteArray.toBase64(); + ApiResponse response=apiRequest->post("/updateAvatar",postData.toUtf8()); + emit updateAvatarResponse(response.getCode(),response.getData(),response.getMessage()); + return response.isSuccess(); +} + +bool User::addTask(const QString& localDir, const QString& s3Dir, int syncType, int usedSize, int totalSize) +{ + //添加云端task + QString postData = QString("localDir=%1&s3Dir=%2&syncType=%3&usedSize=%4&totalSize=%5") + .arg(localDir) + .arg(s3Dir) + .arg(syncType) + .arg(usedSize) + .arg(totalSize); + ApiResponse response=apiRequest->post("/addTask",postData.toUtf8()); + emit addTaskResponse(response.getCode(),response.getData(),response.getMessage()); + return response.isSuccess(); +} + +QVector User::getTask() { //获取云端task ApiResponse response=apiRequest->get("/tasks"); QJsonArray tasksArray = response.getDatav().toArray(); + QVector tasks; for (int i = 0; i < tasksArray.size(); ++i) { QJsonObject taskObj = tasksArray[i].toObject(); SyncTask task(taskObj["localDir"].toString(), - taskObj["s3Dir"].toString(),taskObj["syncType"].toInt()); - //task.usedSize = taskObj["usedSize"].toDouble(); - //task.totalSize = taskObj["totalSize"].toDouble(); + taskObj["s3Dir"].toString(), + taskObj["syncType"].toInt()); + //taskObj["usedSize"].toDouble(), + //taskObj["totalSize"].toDouble() tasks.push_back(task); } + return tasks; +} + +TaskToken User::getTaskToken(int id) +{ + ApiResponse response=apiRequest->get(QString("/getTaskToken?task_id=%1").arg(id)); + if(response.isSuccess()){ + TaskToken tasktoken(response.getData()); + return tasktoken; + } + else{ + QString jsonString = R"({"code": 666, "message": "get token error!", "data": "Nooo!"})"; + QByteArray jsonData = jsonString.toUtf8(); + QJsonDocument document = QJsonDocument::fromJson(jsonData); + QJsonObject jsonObject = document.object(); + TaskToken errortasktoken(jsonObject); + return errortasktoken; + } +} + +TaskToken User::getTaskTokenByRemote(QString s3Dir) +{ + ApiResponse response=apiRequest->get(QString("/getTaskTokenByS3Dir?s3Dir=%1").arg(s3Dir)); + if(response.isSuccess()){ + TaskToken tasktoken(response.getData()); + return tasktoken; + } + else{ + QString jsonString = R"({"code": 666, "message": "get tokenRemote error!", "data": "Nooo!"})"; + QByteArray jsonData = jsonString.toUtf8(); + QJsonDocument document = QJsonDocument::fromJson(jsonData); + QJsonObject jsonObject = document.object(); + TaskToken errortasktoken(jsonObject); + return errortasktoken; + } +} + +bool User::logout() +{ + ApiResponse response=apiRequest->get("/logout"); + emit logoutResponse(response.getCode(),response.getData(),response.getMessage()); return response.isSuccess(); } diff --git a/user.h b/user.h index 701a6b0..51b2641 100644 --- a/user.h +++ b/user.h @@ -6,8 +6,13 @@ #include #include #include +#include +#include +#include +#include #include "apirequest.h" #include "synctask.h" +#include "tasktoken.h" class User : public QObject { Q_OBJECT @@ -19,7 +24,7 @@ class User : public QObject QString hashedPassword; //password bool isLogin=false; ApiRequest *apiRequest; - QVector tasks; + public: User(const QString &username, const QString &account, @@ -32,7 +37,12 @@ class User : public QObject bool enroll(); //执行post请求,实现注册功能 bool login(); //执行post请求,实现登录功能 bool forgetPassword(); //执行post请求,实现找回密码功能 - bool loadTask();//获取云端task + bool updateAvatar(const QString &filePath);//更新头像 + bool addTask(const QString& localDir, const QString& s3Dir, int syncType, int usedSize, int totalSize);//添加云端task + QVector getTask();//获取云端task + TaskToken getTaskToken(int id);//获取tasktoken + TaskToken getTaskTokenByRemote(QString s3Dir); + bool logout();//登出 QString getS3Location();//获取云端容器地址 QString getUsername();//获取用户名 QString getEmail();//获取用户邮箱 @@ -41,8 +51,11 @@ class User : public QObject bool getisLogin(); //返回用户登陆状态 signals: - void enrollCompleted(const QString &session); //注册成功的信号,发送获取到的cookie中session - void loginCompleted(const QString &session); //登陆成功的信号,发送获取到的cookie中session + void enrollResponse(const int &code,const QJsonObject &data,const QString &message); //注册的信号 + void loginResponse(const int &code,const QJsonObject &data,const QString &message); //登陆的信号 + void addTaskResponse(const int &code,const QJsonObject &data,const QString &message); //新建任务的信号 + void updateAvatarResponse(const int &code,const QJsonObject &data,const QString &message);//改头像的信号 + void logoutResponse(const int &code,const QJsonObject &data,const QString &message); }; From 2ee105055b466e21e1c4f033d2393ff9a960c662 Mon Sep 17 00:00:00 2001 From: Firefly-29710 <2235501805@qq.com> Date: Mon, 8 Jul 2024 17:09:03 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + filemange_view.cpp | 1 - historycard.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ historycard.h | 22 ++++++++++++++++++++++ historysync_view.cpp | 35 +++++++++++++++++++++++++++++++++-- historysync_view.h | 3 +++ 6 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 historycard.cpp create mode 100644 historycard.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7610e69..a5cab0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) filequeue.h filequeue.cpp storage.h storage.cpp filecard.h filecard.cpp + historycard.h historycard.cpp ) diff --git a/filemange_view.cpp b/filemange_view.cpp index 244a32c..bfbb3c7 100644 --- a/filemange_view.cpp +++ b/filemange_view.cpp @@ -127,7 +127,6 @@ FileManagePage::FileManagePage(QWidget* parent):ElaScrollPage(parent) centerVLayout->addWidget(pushButtonArea); // 将切换按钮容器添加到布局中 centerVLayout->addWidget(catalogueArea); // 将目录文本添加到布局中 centerVLayout->addWidget(scrollArea); // 将scrollArea添加到布局中 - //centerVLayout->addStretch(); // 在布局的末尾添加一个弹性空间 this->addCentralWidget(centralWidget); // 将中心部件添加到窗口 } diff --git a/historycard.cpp b/historycard.cpp new file mode 100644 index 0000000..fa3b5d4 --- /dev/null +++ b/historycard.cpp @@ -0,0 +1,44 @@ +#include "historycard.h" + +#include +#include"ElaCheckBox.h" + +HistoryCard::HistoryCard(QString f, QString d,QString t,bool u) +{ + setMaximumHeight(25); + + filename=new ElaText(f); + datasize=new ElaText(d); + time=new ElaText(t); + + _checkBox = new ElaCheckBox(filename->text(), this); + QVBoxLayout*checkBoxArea=new QVBoxLayout(); + checkBoxArea->addWidget(_checkBox,0,Qt::AlignCenter); + + datasize->setTextSize(16); + QVBoxLayout*dataSizeArea=new QVBoxLayout(); + dataSizeArea->addWidget(datasize,0,Qt::AlignCenter); + + time->setTextSize(16); + QVBoxLayout*timeArea=new QVBoxLayout(); + ElaText*text; + if(u) + text=new ElaText("上传于"); + else + text=new ElaText("下载于"); + text->setTextSize(16); + timeArea->addWidget(text,0,Qt::AlignCenter); + timeArea->addWidget(time,0,Qt::AlignCenter); + + ElaText*bingoText=new ElaText("√"); + bingoText->setTextSize(16); + QVBoxLayout*bingoArea=new QVBoxLayout(); + bingoArea->addWidget(bingoText,0,Qt::AlignCenter); + + QHBoxLayout*HistoryCardArea=new QHBoxLayout(this); + HistoryCardArea->addLayout(checkBoxArea,Qt::AlignCenter); + HistoryCardArea->addLayout(dataSizeArea,Qt::AlignCenter); + HistoryCardArea->addLayout(timeArea,Qt::AlignCenter); + HistoryCardArea->addLayout(bingoArea,Qt::AlignCenter); + HistoryCardArea->addStretch(); +} diff --git a/historycard.h b/historycard.h new file mode 100644 index 0000000..dac6cbf --- /dev/null +++ b/historycard.h @@ -0,0 +1,22 @@ +#ifndef HISTORYCARD_H +#define HISTORYCARD_H + +#include"ElaScrollPageArea.h" +#include"ElaText.h" + +class ElaCheckBox; +class ElaIconButton; +class ElaProgressBar; +class HistoryCard : public ElaScrollPageArea +{ +public: + explicit HistoryCard(QString f, QString d,QString t,bool u); + + ElaCheckBox* _checkBox{nullptr}; + ElaText *filename; + ElaText *datasize; + ElaText *time; + bool upif; +}; + +#endif // HISTORYCARD_H diff --git a/historysync_view.cpp b/historysync_view.cpp index 4a48b93..e524319 100644 --- a/historysync_view.cpp +++ b/historysync_view.cpp @@ -3,6 +3,8 @@ #include "ElaPushButton.h" #include "ElaToggleButton.h" #include +#include"historycard.h" +#include"ElaScrollArea.h" HistorysyncPage::HistorysyncPage(QWidget* parent) : ElaScrollPage(parent) @@ -57,13 +59,42 @@ HistorysyncPage::HistorysyncPage(QWidget* parent) catalogueText5->setAlignment(Qt::AlignCenter); // 设置文本居中对齐 catalogueLayout->addWidget(catalogueText1); catalogueLayout->addWidget(catalogueText2); - //catalogueLayout->addStretch(); catalogueLayout->addWidget(catalogueText4); catalogueLayout->addWidget(catalogueText5); + ElaScrollArea* scrollArea = new ElaScrollArea(); + scrollArea->viewport()->setStyleSheet("background:transparent;");//设置背景透明 + HistoryCard*HistoryCardArea1=new HistoryCard("文件1","3.5GB","2024.7.1",0); + HistoryCard*HistoryCardArea2=new HistoryCard("文件2","3.5GB","2024.7.2",0); + HistoryCard*HistoryCardArea3=new HistoryCard("文件3","3.5GB","2024.7.3",1); + HistoryCard*HistoryCardArea4=new HistoryCard("文件4","3.5GB","2024.7.4",0); + HistoryCard*HistoryCardArea5=new HistoryCard("文件5","3.5GB","2024.7.5",1); + HistoryCard*HistoryCardArea6=new HistoryCard("文件6","3.5GB","2024.7.6",1); + HistoryCard*HistoryCardArea7=new HistoryCard("文件7","3.5GB","2024.7.7",1); + HistoryCard*HistoryCardArea8=new HistoryCard("文件8","3.5GB","2024.7.8",0); + HistoryCard*HistoryCardArea9=new HistoryCard("文件9","3.5GB","2024.7.9",0); + HistoryCard*HistoryCardArea10=new HistoryCard("文件10","3.5GB","2024.7.10",1); + + QWidget* filesWidget=new QWidget(); + filesLayout=new QVBoxLayout(filesWidget); + filesLayout->addWidget(HistoryCardArea1); + filesLayout->addWidget(HistoryCardArea2); + filesLayout->addWidget(HistoryCardArea3); + filesLayout->addWidget(HistoryCardArea4); + filesLayout->addWidget(HistoryCardArea5); + filesLayout->addWidget(HistoryCardArea6); + filesLayout->addWidget(HistoryCardArea7); + filesLayout->addWidget(HistoryCardArea8); + filesLayout->addWidget(HistoryCardArea9); + filesLayout->addWidget(HistoryCardArea10); + filesLayout->setAlignment(Qt::AlignTop); + + scrollArea->setWidget(filesWidget); // 设置scrollArea的内容部件 + scrollArea->setWidgetResizable(true); // 允许scrollArea根据内容自动调整大小 + centerVLayout->addWidget(progressBarArea); // 将上方固定区域添加到布局中 centerVLayout->addWidget(catalogueArea); // 将目录文本添加到布局中 - centerVLayout->addStretch(); // 在布局的末尾添加一个弹性空间 + centerVLayout->addWidget(scrollArea); this->addCentralWidget(centralWidget); // 将中心部件添加到窗口中 } diff --git a/historysync_view.h b/historysync_view.h index 229a64f..a9da64b 100644 --- a/historysync_view.h +++ b/historysync_view.h @@ -5,11 +5,14 @@ #include "ElaScrollPage.h" #include "ElaScrollPageArea.h" +class QVBoxLayout; class HistorysyncPage : public ElaScrollPage { public: HistorysyncPage(QWidget* parent = nullptr); ~HistorysyncPage(); + QVBoxLayout*filesLayout; + //void addHistory(QString filename, QString datasize,QString time,bool upif); private: ElaProgressBar* _progressBar{nullptr}; }; From ce5f1496fb0043e6aa8eddc77f71226e7efe6852 Mon Sep 17 00:00:00 2001 From: Firefly-29710 <2235501805@qq.com> Date: Mon, 8 Jul 2024 17:17:41 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- historycard.cpp | 2 -- historysync_view.cpp | 6 ++++++ historysync_view.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/historycard.cpp b/historycard.cpp index fa3b5d4..e10fa70 100644 --- a/historycard.cpp +++ b/historycard.cpp @@ -5,8 +5,6 @@ HistoryCard::HistoryCard(QString f, QString d,QString t,bool u) { - setMaximumHeight(25); - filename=new ElaText(f); datasize=new ElaText(d); time=new ElaText(t); diff --git a/historysync_view.cpp b/historysync_view.cpp index e524319..d8ca329 100644 --- a/historysync_view.cpp +++ b/historysync_view.cpp @@ -102,3 +102,9 @@ HistorysyncPage::HistorysyncPage(QWidget* parent) HistorysyncPage::~HistorysyncPage() { } + +void HistorysyncPage::addHistory(QString filename, QString datasize,QString time,bool upif) +{ + HistoryCard*historyCard=new HistoryCard(filename,datasize,time,upif); + filesLayout->addWidget(historyCard); +} diff --git a/historysync_view.h b/historysync_view.h index a9da64b..d016b92 100644 --- a/historysync_view.h +++ b/historysync_view.h @@ -12,7 +12,7 @@ class HistorysyncPage : public ElaScrollPage HistorysyncPage(QWidget* parent = nullptr); ~HistorysyncPage(); QVBoxLayout*filesLayout; - //void addHistory(QString filename, QString datasize,QString time,bool upif); + void addHistory(QString filename, QString datasize,QString time,bool upif); private: ElaProgressBar* _progressBar{nullptr}; }; From 1c3fc0426e08289e8a0371c3b32ec1043eff5bab Mon Sep 17 00:00:00 2001 From: Dipper209 <3611691282@qq.com> Date: Mon, 8 Jul 2024 17:18:38 +0800 Subject: [PATCH 08/10] user avatar --- user.cpp | 15 ++++++++++++++- user.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/user.cpp b/user.cpp index 1fdf42a..1b1b089 100644 --- a/user.cpp +++ b/user.cpp @@ -32,8 +32,21 @@ User::User(const User &user) bool User::enroll() { + QImageReader reader(avatarpath); + if (!reader.canRead()) { + qDebug()<<"read picture failed!"; + } + QImage image = reader.read(); + if (image.isNull()) { + qDebug()<<"read picture failed!"; + } + QByteArray byteArray; + QBuffer buffer(&byteArray); + image.save(&buffer, reader.format()); // 使用图片的原始格式保存 + // 将字节数据编码为Base64字符串 + QString avatar = byteArray.toBase64(); QString postData - = QString("username=%1&email=%2&password=%3").arg(username).arg(account).arg(hashedPassword); + = QString("username=%1&email=%2&password=%3&avatar=%4").arg(username).arg(account).arg(hashedPassword).arg(avatar); ApiResponse response=apiRequest->post("/register",postData.toUtf8()); emit enrollResponse(response.getCode(),response.getData(),response.getMessage()); return response.isSuccess(); diff --git a/user.h b/user.h index cb0419e..6a9f7b5 100644 --- a/user.h +++ b/user.h @@ -24,6 +24,7 @@ class User : public QObject QString hashedPassword; //password bool isLogin=false; ApiRequest *apiRequest; + QString avatarpath; public: User(const QString &username, From b5c0b14683966fadf2a6aaeebb20bc0e9222d01a Mon Sep 17 00:00:00 2001 From: Dipper209 <3611691282@qq.com> Date: Mon, 8 Jul 2024 17:22:21 +0800 Subject: [PATCH 09/10] avatar pubilc --- user.h | 1 + 1 file changed, 1 insertion(+) diff --git a/user.h b/user.h index 6a9f7b5..24af5f3 100644 --- a/user.h +++ b/user.h @@ -24,6 +24,7 @@ class User : public QObject QString hashedPassword; //password bool isLogin=false; ApiRequest *apiRequest; +public: QString avatarpath; public: From 7c1f2da25b34f958582a0688e4650c67add143bb Mon Sep 17 00:00:00 2001 From: Dipper209 <3611691282@qq.com> Date: Mon, 8 Jul 2024 17:34:56 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=BC=A0=E5=A4=B4=E5=83=8F=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user.cpp | 9 +++++++++ user.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/user.cpp b/user.cpp index 1b1b089..02dcdc0 100644 --- a/user.cpp +++ b/user.cpp @@ -31,6 +31,15 @@ User::User(const User &user) bool User::enroll() +{ + QString postData + = QString("username=%1&email=%2&password=%3").arg(username).arg(account).arg(hashedPassword); + ApiResponse response=apiRequest->post("/register",postData.toUtf8()); + emit enrollResponse(response.getCode(),response.getData(),response.getMessage()); + return response.isSuccess(); +} + +bool User::enroll(const QString &avatarpath) { QImageReader reader(avatarpath); if (!reader.canRead()) { diff --git a/user.h b/user.h index 24af5f3..1fc06d7 100644 --- a/user.h +++ b/user.h @@ -24,7 +24,6 @@ class User : public QObject QString hashedPassword; //password bool isLogin=false; ApiRequest *apiRequest; -public: QString avatarpath; public: @@ -37,6 +36,7 @@ class User : public QObject QObject *parent = nullptr); User(const User &user); bool enroll(); //执行post请求,实现注册功能 + bool enroll(const QString &avatarpath);//注册带头像 bool login(); //执行post请求,实现登录功能 bool forgetPassword(); //执行post请求,实现找回密码功能 bool updateAvatar(const QString &filePath);//更新头像