132 lines
3.9 KiB
C++
132 lines
3.9 KiB
C++
#include "dialoglogin.h"
|
|
#include "ui_dialoglogin.h"
|
|
#include "mainwindow.h"
|
|
|
|
#include <QMessageBox>
|
|
|
|
DialogLogin::DialogLogin(QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::DialogLogin)
|
|
{
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
|
setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog | Qt::Popup);
|
|
ui->setupUi(this);
|
|
|
|
setGeometry(0, 0, 1280, 1024);
|
|
|
|
ui->lineEdit_Password->setEchoMode(QLineEdit::Password);
|
|
ui->lineEdit_ID->setFocus();
|
|
|
|
connect(ui->lineEdit_ID, SIGNAL(returnPressed()), this, SLOT(OnReturnPressed()));
|
|
connect(ui->lineEdit_Password, SIGNAL(returnPressed()), this, SLOT(OnReturnPressed()));
|
|
|
|
|
|
}
|
|
|
|
DialogLogin::~DialogLogin()
|
|
{
|
|
disconnect(ui->lineEdit_ID, SIGNAL(returnPressed()), this, SLOT(OnReturnPressed()));
|
|
disconnect(ui->lineEdit_Password, SIGNAL(returnPressed()), this, SLOT(OnReturnPressed()));
|
|
|
|
delete ui;
|
|
}
|
|
|
|
void DialogLogin::OnReturnPressed()
|
|
{
|
|
ui->pushButton_OK->click();
|
|
}
|
|
|
|
void DialogLogin::resizeEvent(QResizeEvent *event)
|
|
{
|
|
int nDisplayType = MainWindow::GetCommonData()->GetDisplayType();
|
|
if(nDisplayType==SDISPLAY_1280X1024)
|
|
{
|
|
ui->frame->setGeometry((1280-600)/2, (1080-340)/2, 600, 340);
|
|
//ui->label->setGeometry(0, 30, 1080, 80);
|
|
//ui->pushButton->setGeometry(1080/2-250/2, 124, 250, 60);
|
|
}
|
|
else if(nDisplayType==SDISPLAY_1920X1080)
|
|
{
|
|
//ui->frame_info->setGeometry(100, 400, 1720, 200);
|
|
//ui->label->setGeometry(0, 30, 1720, 80);
|
|
//ui->pushButton->setGeometry(728, 124, 271, 61);
|
|
}
|
|
}
|
|
|
|
void DialogLogin::on_pushButton_OK_clicked()
|
|
{
|
|
|
|
QString strID = ui->lineEdit_ID->text();
|
|
QString strPassword = ui->lineEdit_Password->text();
|
|
|
|
bool bLoginSuccess = false;
|
|
|
|
// 1. 이 로그인 확인 작업을 위한 지역 DB 인스턴스를 생성합니다.
|
|
SUTIL::SDatabase db(QString("LoginCheck_%1").arg(reinterpret_cast<quintptr>(this)));
|
|
if (db.OpenDatabase("/home/birdhead/test.db") == 0) // 0이 성공
|
|
{
|
|
// 2. 보안과 효율을 위해 COUNT(*) 쿼리와 '?' 플레이스홀더를 사용합니다.
|
|
QString query = "SELECT COUNT(*) FROM LoginUser WHERE LoginID = ? AND LoginPassword = ?;";
|
|
|
|
// 3. 사용자 입력을 안전하게 파라미터로 전달합니다.
|
|
QVariantList params;
|
|
params << strID << strPassword;
|
|
|
|
// 4. executeScalar 헬퍼를 사용해 일치하는 사용자의 '수'를 가져옵니다.
|
|
// 이 수가 0보다 크면, 로그인 정보가 일치하는 것입니다.
|
|
if (db.executeScalar(query, params).toInt() > 0)
|
|
{
|
|
bLoginSuccess = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
qWarning() << "DB open failed for login check.";
|
|
// 필요에 따라 사용자에게 DB 오류 메시지 표시
|
|
}
|
|
|
|
// 5. 최종 결과에 따라 다이얼로그를 닫습니다.
|
|
if (bLoginSuccess)
|
|
{
|
|
done(QDialog::Accepted);
|
|
}
|
|
else
|
|
{
|
|
// 로그인 실패 시 사용자에게 알림 (예: QMessageBox)
|
|
QMessageBox::warning(this, "Login Failed", "Invalid ID or password.");
|
|
// 기존 코드처럼 실패 시 아무것도 안 하려면 이 else 블록을 비워두거나 제거합니다.
|
|
}
|
|
|
|
/*
|
|
QString strID;
|
|
QString strPassword;
|
|
|
|
strID = ui->lineEdit_ID->text();
|
|
strPassword = ui->lineEdit_Password->text();
|
|
|
|
QString strQuery;
|
|
strQuery = QString("select * from LoginUser where LoginID='%1' and LoginPassword='%2';").arg(strID).arg(strPassword);
|
|
|
|
|
|
CommonData* pCommonData = MainWindow::GetCommonData();
|
|
SDatabase* pDatabase = pCommonData->GetDatabase();
|
|
pDatabase->ExecuteQuery(strQuery);
|
|
QList<QStringList*>* pResult = pDatabase->GetResult();
|
|
|
|
if(pResult->size()>0)
|
|
{
|
|
pCommonData->ReleaseDatabase();
|
|
done(QDialog::Accepted);
|
|
}
|
|
else
|
|
{
|
|
pCommonData->ReleaseDatabase();
|
|
}
|
|
*/
|
|
}
|
|
|
|
void DialogLogin::reject()
|
|
{
|
|
|
|
}
|