Browse Source

Verify Login Info

chengxr 1 year ago
parent
commit
1415bbe181
4 changed files with 37 additions and 3 deletions
  1. 22 3
      QFD/view/LoginView.cpp
  2. 2 0
      QFD/view/LoginView.h
  3. 10 0
      QFD/widgets/LoginWidget.cpp
  4. 3 0
      QFD/widgets/LoginWidget.h

+ 22 - 3
QFD/view/LoginView.cpp

@@ -58,11 +58,30 @@ void LoginView::connectSignalsAndSlots()
     connect(m_stackedWidget, &QStackedWidget::currentChanged, this, &LoginView::slotStackIndexChanged);
 }
 
+bool LoginView::verifyLoginInfo() const
+{
+    bool valid = true;
+    QString msg;
+
+    if (m_loginWidget->account().isEmpty()) {
+        valid = false;
+        msg   = "账号不能为空";
+    }
+
+    if (m_loginWidget->password().isEmpty()) {
+        valid = false;
+        msg   = "密码不能为空";
+    }
+
+    return valid;
+}
+
 void LoginView::slotLogin()
 {
-    qDebug() << __FUNCTION__ << __LINE__;
-    setStackIndex(m_stackedWidget->currentIndex() + 1);
-    emit signalLogin();
+    if (verifyLoginInfo()) {
+        setStackIndex(m_stackedWidget->currentIndex() + 1);
+        emit signalLogin();
+    }
 }
 
 void LoginView::slotCancelLogin()

+ 2 - 0
QFD/view/LoginView.h

@@ -31,6 +31,8 @@ private:
     void initLayout();
     void connectSignalsAndSlots();
 
+    bool verifyLoginInfo() const;
+
 private slots:
     void slotLogin();
     void slotCancelLogin();

+ 10 - 0
QFD/widgets/LoginWidget.cpp

@@ -19,6 +19,16 @@ void LoginWidget::setTitle(const QString title)
     m_titleLabel->setText(title);
 }
 
+const QString LoginWidget::account() const
+{
+    return m_accLineEdit->text();
+}
+
+const QString LoginWidget::password() const
+{
+    return m_pwLineEdit->text();
+}
+
 void LoginWidget::initialize()
 {
     m_vBoxLayout = new QVBoxLayout(this);

+ 3 - 0
QFD/widgets/LoginWidget.h

@@ -20,6 +20,9 @@ public:
 
     void setTitle(const QString title);
 
+    const QString account() const;
+    const QString password() const;
+
 private:
     void initialize();
     void initLayout();