diff --git a/helpers/accounthelper.cpp b/helpers/accounthelper.cpp index 77058af..8e3f1c3 100644 --- a/helpers/accounthelper.cpp +++ b/helpers/accounthelper.cpp @@ -16,6 +16,12 @@ bool AccountHelper::signedIn() return ConfigurationHelper().getAccountTokens().isValid(); } +void AccountHelper::logout() +{ + //Destroy login tokens + ConfigurationHelper().setAccountTokens(AccountLoginTokens()); +} + void AccountHelper::login(const AccountLoginRequest &info) { //Create API request diff --git a/helpers/accounthelper.h b/helpers/accounthelper.h index 5ff943b..7c3fbe9 100644 --- a/helpers/accounthelper.h +++ b/helpers/accounthelper.h @@ -27,6 +27,11 @@ public: */ bool signedIn(); + /** + * Logout user + */ + void logout(); + /** * Perform login * diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index 4832695..8df3fe5 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -1,6 +1,11 @@ +#include + #include "mainwindow.h" #include "ui_mainwindow.h" #include "aboutthisappdialog.h" +#include "loginwidget.h" + +#include "../helpers/accounthelper.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -23,3 +28,17 @@ void MainWindow::on_actionAbout_this_App_triggered() { AboutThisAppDialog(this).exec(); } + +void MainWindow::on_actionLogout_triggered() +{ + if(QMessageBox::question(this, tr("Sign out"), tr("Do you really want to sign out from your account?")) != QMessageBox::Yes) + return; + + AccountHelper().logout(); + + //Display login widget + (new LoginWidget())->show(); + + //Close this widget + close(); +} diff --git a/widgets/mainwindow.h b/widgets/mainwindow.h index 87dd69d..0b8b711 100644 --- a/widgets/mainwindow.h +++ b/widgets/mainwindow.h @@ -26,6 +26,8 @@ private slots: void on_actionAbout_this_App_triggered(); + void on_actionLogout_triggered(); + private: Ui::MainWindow *ui; }; diff --git a/widgets/mainwindow.ui b/widgets/mainwindow.ui index e0899ea..76cdc25 100644 --- a/widgets/mainwindow.ui +++ b/widgets/mainwindow.ui @@ -27,6 +27,7 @@ Account + @@ -49,6 +50,11 @@ About this App + + + Logout + +