summaryrefslogtreecommitdiff
path: root/libopie2/opiesecurity/multiauthmainwindow.cpp
blob: 17e87058feef286fabbbcf87e251bde30ed91eab (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "multiauthmainwindow.h"

#include "multiauthcommon.h"
#include <qpe/config.h>

namespace Opie {
namespace Security {

/// Initializes widgets according to allowBypass argument (false by default) and explanScreens config
/**
 * \note if allowBypass is true, we will show explanatory screens anyway
 */
MultiauthMainWindow::MultiauthMainWindow(bool allowBypass)
    : QDialog(0, "main Opie multiauth modal dialog", TRUE,
              Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop)

{
    alreadyDone = false;
    // initializes widget pointers which not always point to an object
    quit = 0;
    message2 = 0;

    if (allowBypass == true)
        explanScreens = true;
    else
    {
        Config *pcfg = new Config("Security");
        pcfg->setGroup("Misc");
        explanScreens = pcfg->readBoolEntry("explanScreens", true);
        delete pcfg;
    }

    layout = new QVBoxLayout(this);
    layout->setSpacing(11);
    layout->setMargin(11);
    layout->setAlignment( Qt::AlignTop );

    // if explanScreens is false, we don't show any text in the QDialog,
    // and we proceed directly
    if ( explanScreens == true )
    {
        title = new QLabel("<center><h1>" + tr("Welcome to Opie Multi-authentication Framework") + "</h1></center>", this);
        message = new QLabel("<center><h3>" + tr("Launching authentication plugins...") + "</h3></center>", this);
    } else {
        title = new QLabel("", this);
        message = new QLabel("", this);
    }

    layout->addWidget(title);
    layout->addWidget(message);
    proceedButton = new QPushButton(tr("Proceed..."), this);
    layout->addWidget(proceedButton, 0, Qt::AlignHCenter);

    QObject::connect(proceedButton, SIGNAL(clicked()), this, SLOT(proceed()));

    if ( explanScreens == true )
    {
        quit = new QPushButton("Exit", this);
        layout->addWidget(quit, 0, Qt::AlignHCenter);
        if ( allowBypass == true )
        {
            // very important: we can close the widget through the quit button, and bypass authentication, only if allowBypass is set!
            message2 = new QLabel("<center><i>" + tr("Note: this 'exit' button only appears during <b>simulations</b>, like the one we are in. If you don't succeed an authentication step at some point, it will keep on asking you to authenticate, but remember you can <b>skip</b> it too (and have access to this button again).") + "</i></center>", this);
            layout->addWidget(message2);
            QObject::connect(quit, SIGNAL(clicked()), this, SLOT(close()));
        }
        else
        {
            quit->hide();
        }

    }
    else
    {
        // we will need this button only if runPlugins() fails in proceed()
        proceedButton->hide();
        // let's proceed now
        proceed();
    }
}

/// nothing to do
MultiauthMainWindow::~MultiauthMainWindow() {
}

/// launch the authentication
void MultiauthMainWindow::proceed() {
    int result = Internal::runPlugins();


    if ( (result == 0) && !explanScreens )
    {
        // the authentication has succeeded, we can exit directly
        // this will work if we haven't been called by the constructor of MultiauthMainWindow
        close();
        // and if we've been called by this constructor, we use this variable to tell our
        // caller we're already done
        alreadyDone = true;
        return;
    }
    else
    {

        proceedButton->setText("Another try?");
        QString resultMessage;

        if (result == 0)
        {
            // authentication has succeeded, adapt interface then
            message->setText( "<center><h3>" + tr("Congratulations! Your authentication has been successful.") + "</h3></center>" );
            quit->setText("Enter Opie");
            if ( quit->isHidden() )
            {
                // that means we don't allow to bypass, but now we can show and connect this button
                QObject::connect(quit, SIGNAL(clicked()), this, SLOT(close()));
                quit->show();
            } else {
                if ( message2 != 0 ) message2->hide();
            }
        }
        else
        {
            // authentication has failed, explain that according to allowBypass
            message->setText( "<center><h3>" + tr("You have <b>not</b> succeeded enough authentication steps!") + "</h3></center>" );
            proceedButton->show();
            if ( allowBypass == true )
            {
                message2->setText( "<center><p>" + tr("Be careful: if this was not a <b>simulation</b>, you would have to go back through all the steps now.") + "</p></center>" );
                message2->show();
            }
        }
    }
}

/** When we don't show explanatory screens and we succeed authentication,
 * as early as during the proceed() call of the constructor, the caller must know
 * (through this function) authentication has already been succeeded..
 * \todo try to avoid this hack?
 */
bool MultiauthMainWindow::isAlreadyDone() {
    return alreadyDone;
}

}
}