Skip to content

Commit 81a44bc

Browse files
committed
user-optional authentication added
1 parent 751d02f commit 81a44bc

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

src/authenticationwidget.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ AuthenticationWidget::~AuthenticationWidget()
4141
{
4242
}
4343

44-
void AuthenticationWidget::loadKeyFromFile(QString filePath) {
44+
bool AuthenticationWidget::isKeyAvailable(){
45+
return this->keyAvailable;
46+
}
47+
48+
void AuthenticationWidget::loadKeyFromFile(QString filePath){
4549
QFile inputFile(filePath);
4650
if (inputFile.open(QIODevice::ReadOnly)){
4751
QTextStream in(&inputFile);
@@ -54,7 +58,7 @@ void AuthenticationWidget::loadKeyFromFile(QString filePath) {
5458
void AuthenticationWidget::authenticate() {
5559
if(keyAvailable){
5660
emit query(this, "auth.challenge?");
57-
}
61+
}
5862
}
5963

6064
void AuthenticationWidget::handleResponse(QString initialQuery, QString response){
@@ -93,7 +97,7 @@ void AuthenticationWidget::handleResponse(QString initialQuery, QString response
9397
}
9498
}
9599
}
96-
else if (status == "401") {
100+
else if (status == "401"){
97101
emit error(tr("Invalid command! Initial query: ") + initialQuery + tr(" Response: ") + recoveredResponse);
98102
}
99103
else {

src/authenticationwidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
** at **
2525
** iqo.uni-hannover.de **
2626
** **
27-
** Date: 12 June 2019 **
28-
** Version: 1.0.0 **
2927
****************************************************************************/
3028

3129

@@ -43,6 +41,8 @@ class AuthenticationWidget : public QueryWidget
4341
AuthenticationWidget(QString keyFilePath, QWidget* parent = 0, QString name = "");
4442
~AuthenticationWidget();
4543

44+
bool isKeyAvailable();
45+
4646
private:
4747
QString key;
4848
bool keyAvailable;

src/fdmlcontrol.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ FDMLControl::FDMLControl(QWidget *parent) : QMainWindow(parent){
5454
this->queryManager->moveToThread(&comThread);
5555
connect(this, &FDMLControl::openSerialPort, this->queryManager, &QueryManager::openSerialPort);
5656
connect(this, &FDMLControl::closeSerialPort, this->queryManager, &QueryManager::closeSerialPort);
57+
connect(this, &FDMLControl::info, this->logConsole, &MessageConsole::slot_displayInfo);
58+
connect(this, &FDMLControl::error, this->logConsole, &MessageConsole::slot_displayError);
5759
connect(this->queryManager, &QueryManager::serialOpen, this, &FDMLControl::enableGui);
5860
connect(this->queryManager, &QueryManager::info, this->logConsole, &MessageConsole::slot_displayInfo);
5961
connect(this->queryManager, &QueryManager::error, this->logConsole, &MessageConsole::slot_displayError);
@@ -205,6 +207,9 @@ void FDMLControl::initMenu(){
205207
QMenu* deviceMenu = this->menuBar()->addMenu(tr("&Device"));
206208
this->readOutAction = deviceMenu->addAction(tr("&Read From Device"), this, &FDMLControl::readOutDevice);
207209
this->readOutAction->setStatusTip(tr("Read out current FDML Laser parameters and update graphical user interface."));
210+
this->authenticateAction = deviceMenu->addAction(tr("&Authenticate As Admin"), this, &FDMLControl::authenticateAsAdmin);
211+
this->authenticateAction->setStatusTip(tr("Log in as administrator to edit expert parameters."));
212+
208213

209214
QMenu* helpMenu = this->menuBar()->addMenu(tr("&Help"));
210215
QAction* aboutAction = helpMenu->addAction(tr("&About"), this, &FDMLControl::showAbout);
@@ -259,6 +264,7 @@ void FDMLControl::enableGui(bool enable){
259264
this->enableGroupBoxes(enable);
260265
this->plot->setAutoUpdate(enable);
261266
this->readOutAction->setEnabled(enable);
267+
this->authenticateAction->setEnabled(enable);
262268

263269
if (enable) {
264270
this->authenticator->authenticate();
@@ -284,8 +290,8 @@ void FDMLControl::showAbout() {
284290
"Contact: zabic"
285291
"@"
286292
"iqo.uni-hannover.de<br>"
287-
"Date: 21 June 2019<br>"
288-
"Version: 1.0.2"));
293+
"Date: 17 July 2019<br>"
294+
"Version: 1.0.3"));
289295
}
290296

291297
void FDMLControl::toggleExpertView() {
@@ -302,5 +308,13 @@ void FDMLControl::toggleLogView() {
302308
}
303309

304310
void FDMLControl::readOutDevice(){
305-
this->widgetManager->queryCurrentValues();
311+
this->widgetManager->queryCurrentValues();
312+
}
313+
314+
void FDMLControl::authenticateAsAdmin(){
315+
if(this->authenticator->isKeyAvailable()){
316+
this->authenticator->authenticate();
317+
}else{
318+
emit error(tr("Administrator authentication not possible, key file is missing."));
319+
}
306320
}

src/fdmlcontrol.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class FDMLControl : public QMainWindow
6868
QAction* expertViewAction;
6969
QAction* logViewAction;
7070
QAction* readOutAction;
71+
QAction* authenticateAction;
7172

7273
QWidget* acqFrame;
7374
QWidget* galvoFrame;
@@ -93,9 +94,12 @@ public slots:
9394
void toggleExpertView();
9495
void toggleLogView();
9596
void readOutDevice();
97+
void authenticateAsAdmin();
9698

9799
signals:
98100
void serialResponse(QString);
99101
void openSerialPort(ComSettings);
100102
void closeSerialPort();
103+
void error(QString);
104+
void info(QString);
101105
};

0 commit comments

Comments
 (0)