Skip to content

Instantly share code, notes, and snippets.

@ianmac45
Created October 6, 2014 23:10
Show Gist options
  • Save ianmac45/5b22426f36f6dfebb39b to your computer and use it in GitHub Desktop.
Save ianmac45/5b22426f36f6dfebb39b to your computer and use it in GitHub Desktop.
example for object-oriented programming
#pragma once
#include "stable.h"
namespace gui { class UserDialog; class AdminDialog; }
namespace data
{
class User : public QObject
{
Q_OBJECT
friend class gui::UserDialog;
public:
User(QObject *parent = 0) : QObject(parent) { load(QSqlRecord()); }
virtual ~User() { save(); }
PROP(bool, prefersSi, setSiPreference)
PROP(QDateTime, lastLogon, setLastLogon)
PROP(QString, name, setName) // PROP_W(QString, name, setName, protected)
PROP(bool, isActive, setActive)
PROP_W(QDateTime, lastUpdated, setLastUpdated, private)
PROP_W(QDateTime, created, setCreated, private)
PROP_W(quint64, id, setId, private)
bool changePassword(const QString &currentClearTextPass, const QString &newClearTextPass);
//! Retrieves the corresponding name for the user id.
static QString nameFromId(quint64);
// protected:
void load(const QSqlRecord &);
bool save();
};
class Administrator : public User
{
Q_OBJECT
friend class gui::UserDialog;
public:
Administrator(QObject *parent = 0) : User(parent) { }
bool addUser(const QString &name, bool isAdmin);
//! Deactivates a user -- does *not* delete;
bool removeUser(quint64 id);
//! Resets a user's password to the default.
bool resetUserPassword(quint64 id);
QList<quint64> getAllUsers() const;
private:
static User* tryLogin(const QString &name, const QString &clearTextPass);
static User* forceLogin(const QString &name);
static User* _processLogin(QSqlQuery &q);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment