#include "MdbLogin.h" #include #include #include #include MdbLogin::MdbLogin(QWidget *parent) :QDialog(parent) { create(); } MdbLogin::MdbLogin(QString username, QString password, QWidget *parent) :QDialog (parent), m_username(username), m_password(password) { create(); } MdbLogin::~MdbLogin() { // destructor } void MdbLogin::create() { setWindowTitle("Login Portal"); setMinimumWidth(400); // dialog ok and cancel button p_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(p_buttonBox, &QDialogButtonBox::accepted, this, &MdbLogin::onDialogOk); connect(p_buttonBox, &QDialogButtonBox::rejected, this, &MdbLogin::onDialogCancel); QVBoxLayout *mainLayout = new QVBoxLayout(this); // create line edit { p_usernameEditor = new QLineEdit(); p_usernameEditor->setPlaceholderText("E-mail address"); // connect the text changed signal to capture the user name } { p_passwordEditor = new QLineEdit(); p_passwordEditor->setPlaceholderText("*********"); p_passwordEditor->setEchoMode(QLineEdit::Password); // connect the text changed signal to capture the user name } p_groupBox = new QGroupBox(); QFormLayout *layout = new QFormLayout(); layout->addRow(new QLabel("Username:"), p_usernameEditor); layout->addRow(new QLabel("Password:"), p_passwordEditor); p_groupBox->setLayout(layout); mainLayout->addWidget(p_groupBox); mainLayout->addWidget(p_buttonBox); connect(&session, &MdbSession::onAuthorizationComplete, this, &MdbLogin::showLoginConfirmation); } void MdbLogin::clearForm() { p_usernameEditor->clear(); p_passwordEditor->clear(); } // implementation of slots void MdbLogin::onDialogOk() { m_username = p_usernameEditor->text(); m_password = p_passwordEditor->text(); session.Login(m_username, m_password); } void MdbLogin::onDialogCancel() { this->clearForm(); hide(); } void MdbLogin::showLoginConfirmation() { hide(); QString title("Login Updated"); QString msg = "User "+ m_username + " successfully logged in!."; // prepare message box int r = QMessageBox::information(this, title, msg, QMessageBox::Close); emit userAuthorized(); }