Skip to content

Commit

Permalink
数据库结合signinwin(虽然好像还有点问题
Browse files Browse the repository at this point in the history
  • Loading branch information
RaidenShogunShadow committed Jul 9, 2024
1 parent 6c7fc3e commit b441aec
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
1 change: 0 additions & 1 deletion loginwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include<QPalette>
#include<QColor>
#include<QMessageBox>
#include "databasemanager.h"
#include"ElaPushButton.h"
#include"ElaLineEdit.h"
#include"ElaText.h"
Expand Down
2 changes: 0 additions & 2 deletions loginwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include"resetwin.h"
#include"signinwin.h"
#include "mycore.h"
#include"databasemanager.h"

class ElaPushButton;
class loginwin:public ElaWidget
Expand All @@ -20,7 +19,6 @@ class loginwin:public ElaWidget
ElaLineEdit*accountLine;
ElaLineEdit*passwordLine;
ElaPushButton*loginBtn;
DatabaseManager *db;

signals:
void on_login_complete(User user);
Expand Down
22 changes: 22 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ MainWindow::MainWindow(QWidget *parent)
// 拦截默认关闭事件
this->setIsDefaultClosed(false);
connect(this, &MainWindow::closeButtonClicked, this, &MainWindow::onCloseButtonClicked);
connect(CurrentUser,&User::loginResponse,this,&MainWindow::onLoginResponse);
}

MainWindow::~MainWindow() {}
Expand All @@ -168,6 +169,27 @@ void MainWindow::onNeedPassword(const QString &account)
emit dbPassword(password);
}

void MainWindow::insertUserToDatabase(User user)
{
db->insertUser(user.getEmail(),user.gethashedPassword());
}

void MainWindow::onLoginResponse(const int &code, const QJsonObject &data, const QString &message)
{
QString url=data.value("avatar_url").toString();
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkRequest request;
request.setUrl(QUrl(url));
QNetworkReply *reply = manager->get(request);
QEventLoop loop;
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
QByteArray picdata = reply->readAll();
QPixmap pixmap;
pixmap.loadFromData(picdata);
setUserInfoCardPixmap(pixmap);
}

void MainWindow::onCloseButtonClicked()
{
ElaContentDialog *dialag = new ElaContentDialog(this);
Expand Down
4 changes: 3 additions & 1 deletion mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include"loginwin.h"
#include"ElaCheckBox.h"
#include"userinfopage.h"

#include"databasemanager.h"
#include "user.h"
class HomePage;
class SyncingPage;
Expand All @@ -34,6 +34,8 @@ class MainWindow : public ElaWindow
public slots:
void onUserLoggedIn(User user);
void onNeedPassword(const QString& account);
void insertUserToDatabase(User user);
void onLoginResponse(const int &code,const QJsonObject &data,const QString &message);

signals:
void dbPassword(const QString &);
Expand Down
3 changes: 3 additions & 0 deletions signinwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ void signinwin::on_signinBtn_clicked()
else
result=enrolluser.enroll();
if(result)
{
emit on_signin_complete(enrolluser);
QMessageBox::information(this, "成功","注册成功");
}
else
QMessageBox::critical(this, "失败","注册失败");
emit goback();
Expand Down
2 changes: 2 additions & 0 deletions signinwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class signinwin:public ElaWidget

signals:
void goback();
void on_signin_complete(User user);

public:
ElaInteractiveCard*avatar;
QHBoxLayout*avatarArea;
Expand Down

0 comments on commit b441aec

Please sign in to comment.