Skip to content

Commit

Permalink
insertUser
Browse files Browse the repository at this point in the history
  • Loading branch information
Firefly-26710 committed Jul 8, 2024
1 parent 7b591d9 commit ef667f5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions loginwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion user.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class User : public QObject
QString getUsername();//获取用户名
QString getEmail();//获取用户邮箱
QString getUserHash() const; //返回用户账户的哈希

QString gethashedPassword();
bool getisLogin(); //返回用户登陆状态

signals:
Expand Down

0 comments on commit ef667f5

Please sign in to comment.