diff --git a/mainwindow.cpp b/mainwindow.cpp
index 0ad640c..7587a57 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -4,6 +4,33 @@
#include
#include
+void MainWindow::handleOutput() {
+ QString content = m_box->text();
+ m_box->setText("");
+ switch(state) {
+ case Unauthed:
+ if(!content.startsWith("/login ")) {
+ addMessage("You are currently unauthenticated, you can't send messages or use commands!", Error);
+ return;
+ }
+ m_box->setEchoMode(QLineEdit::NoEcho);
+ m_box->setPlaceholderText("Enter your password");
+ state = PendingPassword;
+ addMessage(QString("Logging in as %1. Enter your password then press Enter. (you won't be able to see any characters)").arg(content.replace("/login ", "")), System);
+ break;
+ case Unauthed:
+ if(!content.startsWith("/login ")) {
+ addMessage("You are currently unauthenticated, you can't send messages or use commands!", Error);
+ return;
+ }
+ m_box->setEchoMode(QLineEdit::NoEcho);
+ m_box->setPlaceholderText("Enter your password");
+ state = PendingPassword;
+ addMessage(QString("Logging in as %1. Enter your password then press Enter. (you won't be able to see any characters)").arg(content.replace("/login ", "")), System);
+ break;
+}
+}
+
void MainWindow::addMessage(QString content, MainWindow::MessageType type) {
if(type == Normal) {
m_chatlog->append(content);
@@ -12,7 +39,7 @@ void MainWindow::addMessage(QString content, MainWindow::MessageType type) {
m_chatlog->append(QString("[Sys] %1
").arg(content));
}
if(type == Error) {
- m_chatlog->append(QString("Error: %1").arg(content));
+ m_chatlog->append(QString("Error: %1").arg(content));
}
}
@@ -39,6 +66,7 @@ MainWindow::MainWindow(QWidget *parent)
chatboxLayout->addWidget(m_send);
chatboxWidget->setLayout(chatboxLayout);
m_layout->addWidget(chatboxWidget);
+ connect(m_box, SIGNAL(returnPressed()), this, SLOT(handleOutput()));
}
MainWindow::~MainWindow() {
diff --git a/mainwindow.h b/mainwindow.h
index d0dac4b..a8c2e5a 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -15,9 +15,13 @@ class MainWindow : public QMainWindow
public:
enum MessageType {Normal, System, Error};
+ enum AppState {Unauthed, Sane, PendingPassword, PendingOTP};
MainWindow(QWidget *parent = nullptr);
~MainWindow();
+private slots:
+ void handleOutput();
private:
+ AppState state = Unauthed;
void addMessage(QString content, MainWindow::MessageType type = Normal);
QVBoxLayout *m_layout;
QTextEdit *m_chatlog;