30f469e141fdf65db00ad545f2070fe4c7919b12
[quassel.git] / src / core / authenticator.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2015 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #ifndef AUTHENTICATOR_H
22 #define AUTHENTICATOR_H
23
24 #include <QtCore>
25
26 #include "types.h"
27
28 class Authenticator : public QObject {
29
30     Q_OBJECT
31
32 public:
33     Authenticator(QObject *parent = 0);
34     virtual ~Authenticator() {};
35
36     enum State {
37         IsReady,        // ready to go
38         NeedsSetup,        // need basic setup (ask the user for input)
39         NotAvailable     // remove the authenticator backend from the list of avaliable authenticators.
40     };
41
42
43 public slots:
44     // General
45
46     //! Check if the authenticator type is available.
47     /** An authenticator subclass should return true if it can be successfully used, i.e. if all
48      *  prerequisites are in place.
49      * \return True if and only if the authenticator class can be successfully used.
50      */
51     virtual bool isAvailable() const = 0;
52
53     //! Returns the display name of the authenticator backend
54     /** \return A string that can be used by the client to name the authenticator backend */
55     virtual QString displayName() const = 0;
56
57     //! Returns a description of this authenticator backend
58     /** \return A string that can be displayed by the client to describe the authenticator */
59     virtual QString description() const = 0;
60
61     //! Returns a list of properties required to use the authenticator backend
62     virtual QStringList setupKeys() const = 0;
63
64     //! Checks if the authenticator allows manual password changes from inside quassel.
65     virtual bool canChangePassword() const = 0;
66
67     //! Returns a map where the keys are are properties to use the authenticator backend
68     /*  the values are QVariants with default values */
69     virtual QVariantMap setupDefaults() const = 0;
70
71     //! Setup the authenticator provider.
72     /** This prepares the authenticator provider (e.g. create tables, etc.) for use within Quassel.
73      *  \param settings   Hostname, port, username, password, ...
74      *  \return True if and only if the authenticator provider was initialized successfully.
75      */
76     virtual bool setup(const QVariantMap &settings = QVariantMap()) = 0;
77
78     //! Initialize the authenticator provider
79     /** \param settings   Hostname, port, username, password, ...
80      *  \return the State the authenticator backend is now in (see authenticator::State)
81      */
82     virtual State init(const QVariantMap &settings = QVariantMap()) = 0;
83
84     //! Validate a username with a given password.
85     /** \param user     The username to validate
86      *  \param password The user's alleged password
87      *  \return A valid UserId if the password matches the username; 0 else
88      */
89     virtual UserId validateUser(const QString &user, const QString &password) = 0;
90
91 private:
92
93 };
94
95 #endif