-
Notifications
You must be signed in to change notification settings - Fork 0
/
Login.cpp
83 lines (71 loc) · 1.91 KB
/
Login.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include"Login.h"
#include <QDebug>
#include <QFile>
QString Login::userName="";
QString Login::password="";
Login::Login()
{
setupUi(this);
setWindowTitle("Aeolus Login");
connections();
checkBoxImplementation();
}
void Login::connections()
{
connect(loginPushButton,SIGNAL(clicked()),this,SLOT(authenticate()));
connect(showPasswordCheckBox,SIGNAL(stateChanged(int)),this,SLOT(checkBoxImplementation()));
connect(backPushButton,SIGNAL(clicked()),this,SLOT(back()));
}
QString Login::returnUserName()
{
return Login::userName;
}
QString Login::returnPassword()
{
return Login::password;
}
void Login::checkBoxImplementation()
{
if(showPasswordCheckBox->isChecked())
passwordLineEdit->setEchoMode(QLineEdit::Normal);
else
passwordLineEdit->setEchoMode(QLineEdit::Password);
}
void Login::authenticate()
{
Login::userName=userNameLineEdit->text();
Login::password=passwordLineEdit->text();
QString command="curl -k --user "+ userName+":"+password + " https://localhost/conductor/providers";
qDebug()<<command;
QByteArray commandBA = command.toLocal8Bit();
const char *commandC = commandBA.data();
system(commandC);
QFile file("/var/log/aeolus-conductor/rails.log");
file.open(QIODevice::Text | QIODevice::ReadOnly);
QTextStream out(&file);
QString lastLineRead;
while(!out.atEnd())
{
QString log=out.readLine();
lastLineRead=log;
}
QByteArray lastLineReadBA = lastLineRead.toLocal8Bit();
const char *lastLineReadC = lastLineReadBA.data();
if(strstr(lastLineReadC,"401 Unauthorized"))
{
message.setText("Login Error , Please Check your credentials");
message.show();
}
else
{
LoggedInDialog *object=new LoggedInDialog;
this->close();
object->show();
}
}
void Login::back()
{
StartDialog *object=new StartDialog;
this->close();
object->show();
}